Example #1
0
 def get_next_board(self, game):
     if self.player_type == PlayerType(1).name:
         choice = game.presenter.get_choice(self, game.board)
         move = game.board.map_to_move(choice)
     else:
         game.presenter.notify_turn(game.active_player.number)
         game.presenter.notify_thinking(game.active_player.player_type)
         move = ai.negamax(game.board, self.symbol, self.symbol).move
     return game.board.apply_move(move, self.symbol)
Example #2
0
winner = None
first_move = True

legend = "123456789"
rules.printBoard(legend)
print "\nComputer goes first\n"

while not winner and not rules.isFull(board):
    # On the first turn, skip the human player to let the computer go first.
    if not first_move:
        # Player's turn
        board[ai.humanPlayer(board)] = player_char
        winner = rules.getWinner(board)

    # Computer's turn
    if not winner and not rules.isFull(board):
        if first_move:
            board[ai.firstMove()] = comp_char
        else:
            # Don't care what the score was, just take the best move.
            _, move = ai.negamax(board, comp_char)
            assert move is not None
            board[move] = comp_char
        winner = rules.getWinner(board)

    # Either the game just ended or we're on to the next round.
    first_move = False
    rules.printBoard(board)

rules.printEndGame(winner)
Example #3
0
first_move = True

while not winner and not rules.isFull(board):
    # Skip the naive player's first turn if the smart player goes first.
    if not first_move or naive_goes_first:
        # Naive player's turn.
        if first_move:
            board[ai.firstMove()] = naive_char
        else:
            board[ai.tryToBeSmart(board, naive_char)] = naive_char
        winner = rules.getWinner(board)
        first_move = False

    if not winner and not rules.isFull(board):
        # Smart player's turn
        if first_move:
            board[ai.firstMove()] = smart_char
        else:
            # Don't care what the score was, just take the best move.
            _, move = ai.negamax(board, smart_char)
            assert move is not None
            board[move] = smart_char
        winner = rules.getWinner(board)
        first_move = False

    # Either the game just ended or we're on to the next round.
    rules.printBoard(board)
    print

rules.printEndGame(winner)