Tic Tac Toe Starter
from os import system
from cs50 import get_int
board = [1,2,3,4,5,6,7,8,9]
def print_board():
print(f"{board[0]} | {board[1]} | {board[2]}")
print(f"{board[3]} | {board[4]} | {board[5]}")
print(f"{board[6]} | {board[7]} | {board[8]}")
print()
def x_move():
global board
space = get_int("X move: ")
if board[space - 1] != "X" and board[space - 1] != "O":
board[space - 1] = "X"
return True
else:
return False
def o_move():
global board
space = get_int("O move: ")
if board[space - 1] != "X" and board[space - 1] != "O":
board[space - 1] = "O"
return True
else:
return False
def game_over():
global board
if board[0] == 'X' and board[1] == 'X' and board[2] == 'X':
print("X wins!")
return True
#game over figures out if someone wins, or if the game is a draw
#if the game is over, it prints out the result and returns True.
#If not, it returns False.
return False
system("clear")
print("Welcome to Tic Tac Toe")
while True:
print_board()
while True:
if x_move():
break
if game_over():
break
system("clear")
print_board()
while True:
if o_move():
break
if game_over():
break
system("clear")