Dec-21-2022, 12:01 AM
I took a shot at using the minimax algorithm with alpha-beta pruning. This works great in a regular tic-tac-toe game, but not very well in this case.
My first attempt to solve for the tic-tac-toe cube was to treat each face like a separate board and choose the highest score from the three boards. The robot player is fairly responsive in this mode but is easy to beat. The robot has a bias towards the first board, and you can make it waste turns filling empty, but unproductive squares while you set up a win on the 2nd or 3rd board.
My second attempt was to simultaneously solve a tic-tac-toe board with 27 squares. Even if with alpha-beta pruning this is painfully slow. After waiting an hour for the computer to make its first move, I gave up waiting.
In response to your questions.
This is the logic I use to control the robot player:
My first attempt to solve for the tic-tac-toe cube was to treat each face like a separate board and choose the highest score from the three boards. The robot player is fairly responsive in this mode but is easy to beat. The robot has a bias towards the first board, and you can make it waste turns filling empty, but unproductive squares while you set up a win on the 2nd or 3rd board.
My second attempt was to simultaneously solve a tic-tac-toe board with 27 squares. Even if with alpha-beta pruning this is painfully slow. After waiting an hour for the computer to make its first move, I gave up waiting.
In response to your questions.
This is the logic I use to control the robot player:
elif event.type == pygame.MOUSEBUTTONDOWN: if cube.done(): # No plays left to make. Reset for new game cube.reset() else: # Check if player clicked on an open square if cube.click(pygame.Vector2(event.pos)): # Player selected a square. If moves available, # have robot make a play. if not cube.done(): cube.draw(surface) cube.play(robot.play(), "O") # Throw away clicks that happened while waiting # for robot player pygame.event.clear() cube.draw(surface)I changed the Cube.draw() method to make it easier to update the window.
def draw(self, surface): """Draw all the tic-tac-toe boards.""" surface.fill("white") for square in self.squares: square.draw(surface) pygame.display.flip()