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

Skip to content

Fixed pruning for first max node in aphabeta_search #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions games.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def alphabeta_full_search(state, game):

player = game.to_move(state)

#Functions used by alphabeta
def max_value(state, alpha, beta):
if game.terminal_test(state):
return game.utility(state, player)
Expand All @@ -64,16 +65,15 @@ def min_value(state, alpha, beta):
return v

# Body of alphabeta_search:
return argmax(game.actions(state),
lambda a: min_value(game.result(state, a),
-infinity, infinity))
return max_value(state, -infinity, infinity)

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

player = game.to_move(state)

#Functions used by alphabeta
def max_value(state, alpha, beta, depth):
if cutoff_test(state, depth):
return eval_fn(state)
Expand Down Expand Up @@ -103,9 +103,7 @@ def min_value(state, alpha, beta, depth):
cutoff_test = (cutoff_test or
(lambda state,depth: depth>d or game.terminal_test(state)))
eval_fn = eval_fn or (lambda state: game.utility(state, player))
return argmax(game.actions(state),
lambda a: min_value(game.result(state, a),
-infinity, infinity, 0))
return max_value(state, -infinity, infinity, 0)

#______________________________________________________________________________
# Players for Games
Expand Down