Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1771d37

Browse files
committed
Merge pull request aimacode#70 from Chipe1/alphabeta
Fixed pruning for first max node in aphabeta_search
2 parents c6867d3 + b83ca93 commit 1771d37

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

games.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def alphabeta_full_search(state, game):
4141

4242
player = game.to_move(state)
4343

44+
#Functions used by alphabeta
4445
def max_value(state, alpha, beta):
4546
if game.terminal_test(state):
4647
return game.utility(state, player)
@@ -64,16 +65,15 @@ def min_value(state, alpha, beta):
6465
return v
6566

6667
# Body of alphabeta_search:
67-
return argmax(game.actions(state),
68-
lambda a: min_value(game.result(state, a),
69-
-infinity, infinity))
68+
return max_value(state, -infinity, infinity)
7069

7170
def alphabeta_search(state, game, d=4, cutoff_test=None, eval_fn=None):
7271
"""Search game to determine best action; use alpha-beta pruning.
7372
This version cuts off search and uses an evaluation function."""
7473

7574
player = game.to_move(state)
7675

76+
#Functions used by alphabeta
7777
def max_value(state, alpha, beta, depth):
7878
if cutoff_test(state, depth):
7979
return eval_fn(state)
@@ -103,9 +103,7 @@ def min_value(state, alpha, beta, depth):
103103
cutoff_test = (cutoff_test or
104104
(lambda state,depth: depth>d or game.terminal_test(state)))
105105
eval_fn = eval_fn or (lambda state: game.utility(state, player))
106-
return argmax(game.actions(state),
107-
lambda a: min_value(game.result(state, a),
108-
-infinity, infinity, 0))
106+
return max_value(state, -infinity, infinity, 0)
109107

110108
#______________________________________________________________________________
111109
# Players for Games

0 commit comments

Comments
 (0)