コード例 #1
0
 def choose_move(self):
     """Given the current board state, choose a best move."""
     value, move = minimax.alphabeta(
         self.state,
         player=(minimax.MAX
                 if self.player == chess.WHITE else minimax.MIN),
         maxdepth=self.searchdepth)
     return value, move
コード例 #2
0
ファイル: bot.py プロジェクト: gbtami/chess-1
 def choose_move(self):
     """Given the current board state, choose a best move."""
     value, move = minimax.alphabeta(self.state,
             player=(minimax.MAX
                 if self.player == chess.WHITE
                 else minimax.MIN),
             maxdepth=self.searchdepth)
     return value, move
コード例 #3
0
ファイル: players.py プロジェクト: xdom/open-mtg
    def determine_move(self, method, game):
        legal_moves = game.get_legal_moves(self)
        if len(legal_moves) == 1:
            return legal_moves[0]
        if method == "random":
            return random.choice(legal_moves)
        if method == "alphabeta":
            move_values = [-9999] * len(legal_moves)
            for i in range(len(move_values)):
                new_game = copy.deepcopy(game)
                new_game.make_move(legal_moves[i])
                move_values[i] = minimax.alphabeta(self, new_game, 1, -9999, 9999,
                                                   new_game.player_with_priority.index is not self.index)

            winner = np.argwhere(move_values == np.amax(move_values))
            winner.flatten().tolist()
            arg = random.choice(winner)[0]
            return legal_moves[arg]
コード例 #4
0
def run_minimax_experiments_for_defender_budget(actions_mgr, network,
                                                defender_budget, alg,
                                                attacker_budgets):
    results = {0: {}, defender_budget: {}}
    for attacker_budget in attacker_budgets:
        print(' Defender:' + str(defender_budget) + ' Attacker: ' +
              str(attacker_budget))
        results[0][attacker_budget] = single_agent(actions_mgr, network,
                                                   attacker_budget)
        network.limit_trade_step = True
        if alg == 'minimax':
            results[defender_budget][attacker_budget] = minimax2(
                actions_mgr, ATTACKER, network, attacker_budget,
                defender_budget)
        else:
            results[defender_budget][attacker_budget] = alphabeta(
                actions_mgr, ATTACKER, network, attacker_budget,
                defender_budget, (-inf, inf), (inf, inf))
    return results
コード例 #5
0
ファイル: game2.py プロジェクト: sharpau/CS533-Final
   
if __name__ == "__main__":
    import othello
    import minimax

    # Experiment 1:
    # Player 1 and Player 2 are evenly matched with 3-ply deep search
    # player 2 wins with a final score of 28
    # player 1 0.2 s per ply player 2 0.4 s per ply
    play(othello.game(), player(lambda x: minimax.minimax(x, 3)),
         player(lambda x: minimax.minimax(x, 3)), True)
    
    # Experiment 2:
    # now we show the significance of an evaluation function
    # we weaken player1 to 2 ply deep but use the edge eval fun
    # player 1 now beats player 2 with a score of 58!
    # player 1 0.1 s per ply player 2 0.4 s per ply
    play(othello.game(), player(lambda x: minimax.minimax(x, 2, othello.edge_eval)),
         player(lambda x: minimax.minimax(x, 3)), False)

    # Experiment 1 (with alpha-beta):
    # player 1 0.1 s per ply, player 2 0.1 s per ply
    play(othello.game(), player(lambda x: minimax.alphabeta(x, 3)),
         player(lambda x: minimax.alphabeta(x, 3)), False)

    # Experiment 2 (with alpha-beta):
    # player 1 0.0 s per ply player 2 0.1 s per ply
    play(othello.game(), player(lambda x: minimax.alphabeta(x, 2, othello.edge_eval)),
         player(lambda x: minimax.alphabeta(x, 3)), False)
コード例 #6
0
ファイル: game2.py プロジェクト: lijuan0531/othello-py
if __name__ == "__main__":
    import othello
    import minimax

    # Experiment 1:
    # Player 1 and Player 2 are evenly matched with 3-ply deep search
    # player 2 wins with a final score of 28
    # player 1 0.2 s per ply player 2 0.4 s per ply
    play(othello.game(), player(lambda x: minimax.minimax(x, 3)),
         player(lambda x: minimax.minimax(x, 3)), False)

    # Experiment 2:
    # now we show the significance of an evaluation function
    # we weaken player1 to 2 ply deep but use the edge eval fun
    # player 1 now beats player 2 with a score of 58!
    # player 1 0.1 s per ply player 2 0.4 s per ply
    play(othello.game(),
         player(lambda x: minimax.minimax(x, 2, othello.edge_eval)),
         player(lambda x: minimax.minimax(x, 3)), False)

    # Experiment 1 (with alpha-beta):
    # player 1 0.1 s per ply, player 2 0.1 s per ply
    play(othello.game(), player(lambda x: minimax.alphabeta(x, 3)),
         player(lambda x: minimax.alphabeta(x, 3)), False)

    # Experiment 2 (with alpha-beta):
    # player 1 0.0 s per ply player 2 0.1 s per ply
    play(othello.game(),
         player(lambda x: minimax.alphabeta(x, 2, othello.edge_eval)),
         player(lambda x: minimax.alphabeta(x, 3)), False)
コード例 #7
0
ファイル: othello_gui.py プロジェクト: sharpau/CS533-Final
        score = game.score() * game.player
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)        
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over "+win_text)

        # wait for the user to quit the game        
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return

    
if __name__ == "__main__":

    print("""othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.""")
    
    game2.play(othello.game(),
               game2.player(lambda x: minimax.alphabeta(x, 4, othello.edge_eval)),
               player(), True)
コード例 #8
0
ファイル: othello_gui.py プロジェクト: njmanohar/othello-py
        score = game.score() * game.player
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)        
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over "+win_text)

        # wait for the user to quit the game        
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return

    
if __name__ == "__main__":

    print """othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions."""

    game2.play(othello.game(), player(), game2.player(lambda x: minimax.alphabeta(x, 3, othello.positional_eval)), True)

コード例 #9
0
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over " + win_text)

        # wait for the user to quit the game
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return


if __name__ == "__main__":

    print("""othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.""")

    game2.play(
        othello.game(),
        game2.player(lambda x: minimax.alphabeta(x, 4, othello.edge_eval)),
        player(), True)