Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de1b92f

Browse files
minmax is now working
1 parent 3d5df48 commit de1b92f

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

‎Engine.py‎

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -216,66 +216,59 @@ def minmax(self, is_max=True, depth=0, alpha=-INF, beta=INF):
216216
if depth == self.depth or abs(score) == Engine.INF:
217217
return score
218218

219-
# find the minimum attainable value for the Goat
219+
# find the minimum attainable value for the minimizer
220220
if not is_max:
221-
best_val = Engine.INF
222-
223221
for move in self.generate_move_list():
224222
# first make the move
225223
self._make_move(move)
226224

227225
# go deeper in the search tree recursively
228226
value = self.minmax(True, depth + 1, alpha, beta)
229-
best_val = min(best_val, value)
230-
beta = min(beta, best_val)
227+
228+
if value < beta:
229+
beta = value
230+
if depth == 0:
231+
self.best_move = move
231232

232233
# then revert the move
233234
self._revert_move(move)
234235

235236
# ab pruning
236-
if beta<=alpha:
237-
break
237+
if alpha>=beta:
238+
returnbeta
238239

239-
return best_val
240+
return beta
240241

241242
# find the maximum attainable value for the maximizer
242243
else:
243-
best_val = -Engine.INF
244-
245244
for move in self.generate_move_list():
246245
# first make the move
247246
self._make_move(move)
248247

249248
# go deeper in the search tree recursively
250249
value = self.minmax(False, depth + 1, alpha, beta)
251-
best_val = max(best_val, value)
252-
alpha = max(alpha, best_val)
250+
251+
if value > alpha:
252+
alpha = value
253+
if depth == 0:
254+
self.best_move = move
253255

254256
# then revert the move
255257
self._revert_move(move)
256258

257259
# ab pruning
258-
if beta <= alpha:
259-
break
260-
261-
return best_val
262-
263-
def find_best_move(self):
264-
score = 0
265-
best_move = None
266-
267-
for move in self.generate_move_list():
268-
# make the move
269-
self._make_move(move)
260+
if alpha >= beta:
261+
return alpha
270262

271-
# is it the best move we've found so far?
272-
if self.minmax(is_max=True) > score:
273-
best_move = move
263+
return alpha
274264

275-
# revert the move
276-
self._revert_move(move)
265+
def best_tiger_move(self):
266+
self.minmax()
267+
return self.best_move
277268

278-
return best_move
269+
def best_goat_move(self):
270+
self.minmax(is_max=False)
271+
return self.best_move
279272

280273
def make_random_move(self):
281274
import random

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /