from board import customBoard
from color import customColor
from random import randint
from ai import customAI

def userInput(p):
    space = True
    while(space):
        row = int(input("Input a row 1 2 or 3: "))-1
        column = int(input("Input a column  1 2 or 3: "))-1
        if board.check_space_before_input(row,column):
            board.make_move(row,column,p)
            space = False
        else:
            print(c.magenta("try again"))

def aiInput(p):
    space = True
    while(space):
        row = randint(0, 2)
        column = randint(0, 2)
        if board.check_space_before_input(row,column):
            board.make_move(row,column,p)
            space = False
        else:
            print(c.magenta("try again"))


# Store some data
# aiPlayer = int([1,2,3][1,2,3])
# huPlayer = int([])

# def recursion(p, board):
#     if p == 'O':
#         board.move(p)   
#         board.check()
#         if winner:
#             return board.score()
#         return recursion(!p, board)
    

# Initialize
board = customBoard()
c = customColor()
r = customAI()

# Show board
#board.show_board()

moves = True
p = "X"

while moves == True:
    if p == "X":
        board.show_board()
        print(board.add_color(p) + " your move")
        userInput(p)
        
    
        if board.check_score():
            print(board.add_winner_color_message(p,p + " is the winner"))
            moves = False
        
        if not board.check_moves_available() and moves!=False:
            print (c.magenta("It's a tie!"))
            moves = False
            
        p = "O"

    else:
        move = r.pickMove(board,p)
        board.make_move(move[0],move[1],p)
        if board.check_score():
            print(board.add_winner_color_message(p,p + " [AI] is the winner"))
            moves = False
        
        if not board.check_moves_available() and moves!=False:
            print (c.magenta("It's a tie!"))
            moves = False
        p = "X"

board.show_board()
print("Thank you for playing my game!!!")