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

Skip to content

Commit 78f73cc

Browse files
Add 'avoid_pruning' parameter, and comment reg. custom Games dual-goal logic.
1 parent 5aa7d13 commit 78f73cc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

games.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def chance_node(state, action):
8686
return max(game.actions(state), key=lambda a: chance_node(state, a), default=None)
8787

8888

89-
def alpha_beta_search(state, game):
89+
def alpha_beta_search(state, game, avoid_pruning=False):
9090
"""Search game to determine best action; use alpha-beta pruning.
9191
As in [Figure 5.7], this version searches all the way to the leaves."""
9292

@@ -99,7 +99,7 @@ def max_value(state, alpha, beta):
9999
v = -np.inf
100100
for a in game.actions(state):
101101
v = max(v, min_value(game.result(state, a), alpha, beta))
102-
if v >= beta:
102+
if v >= beta and not avoid_pruning:
103103
print("pruning: {}".format(v))
104104
print("state: {}".format(state))
105105
return v
@@ -115,9 +115,10 @@ def min_value(state, alpha, beta):
115115
v = np.inf
116116
for a in game.actions(state):
117117
v = min(v, max_value(game.result(state, a), alpha, beta))
118-
if v <= alpha:
118+
if v <= alpha and not avoid_pruning:
119119
print("pruning: {}".format(v))
120120
print("state: {}".format(state))
121+
# How can we ensure that a sub-node in which terminal_test is true is not being pruned? - Ryan Jackson
121122
return v
122123
prev_beta = copy.deepcopy(beta)
123124
beta = min(beta, v)
@@ -137,6 +138,7 @@ def min_value(state, alpha, beta):
137138
if v > best_score:
138139
best_score = v
139140
best_action = a
141+
140142
return best_action
141143

142144

0 commit comments

Comments
 (0)