Madison made this work.
from os import system
from cs50 import get_int
from termcolor import colored
class colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW= '\033[93m'
RED = '\033[91m'
END = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
board = [1,2,3,4,5,6,7,8,9]
def print_board():
for i in range(9):
if board[i] == "X":
print(colors.RED + str(board[i]) + " " + colors.END, end="")
elif board[i] == "O":
print(colors.BLUE + str(board[i]) + " " + colors.END, end="")
else:
print(str(board[i]) + " ", end="")
if i == 2 or i == 5:
print("")
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():
system("clear")
print_board()
#horizontal
for team in ["X","O"]:
for i in range(3):
i = i*3
if board[i] == team and board[i+1] == team and board[i+2] == team:
print(team + " wins")
return True
#vertical
for team in ["X","O"]:
for i in range(3):
if board[i] == team and board[i+3] == team and board[i+6] == team:
print(team + " wins")
return True
#diagonal
for team in ["X","O"]:
if board[0] == team and board[4] == team and board[8] == team:
print(team + " wins")
return True
#diagonal
for team in ["X","O"]:
if board[2] == team and board[4] == team and board[6] == team:
print(team + " wins")
return True
return False
system("clear")
print(colors.YELLOW + "Welcome to Tic Tac Toe" + colors.END)
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")