TTT #3

All right, next step...more BoardNode properties, as mentioned in class  (and you can drop the .parents, since we don't need it).

Here's the new BoardNode's __init__():

class BoardNode:
    def __init__(self,layout):
        self.layout = layout
        self.endState = None # if this is a terminal board, endState == 'x' or 'o' for wins, of 'd' for draw, else None if this board is not final
        self.children = [] # all layouts that can be reached with a single move

        self.best_move  # cell position (0-8) of the best move from this layout, or -1 if this is a final layout
        self.moves_to_end  # how many moves until the end of the game, if played perfectly.  0 if this is a final layout
        self.final_state   # expected final state ('x' if 'x' wins, 'o' if 'o' wins, else 'd' for a draw)


 

move=6
best move is lower-left
x wins in 1 move

The first output line is formatted for computer input and the other two are for human eyes.

Best move choice:

Timing:  You are allowed to cheat if given an empty board and you have to make the first move (any first move will lead to a draw in 9 moves, if played perfectly by both sides).  After that, however, your program should deliver an answer in under 2 seconds.

Testing: Now you can really play with tictactoe against your creation.  It should never lose.  Make it so.