20-add-negamax-eval-function #31
@@ -15,6 +15,10 @@ class BaseEvaluation:
|
||||
pass
|
||||
|
||||
|
||||
def get_params(self):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
We will use a random move evaluation as our base AI. This
|
||||
is expected to be the worst performing strategy. We can
|
||||
@@ -38,15 +42,7 @@ class NegaMaxEval(BaseEvaluation):
|
||||
self.window = cp_window
|
||||
|
||||
|
||||
def _same(self, a, b):
|
||||
return (int(getattr(a, "from")) == int(getattr(b, "from"))
|
||||
and int(a.to) == int(b.to)
|
||||
and int(getattr(a, "promo", 0) or 0) == int(getattr(b, "promo", 0) or 0))
|
||||
|
||||
def get_best_move(self, board, legal_moves):
|
||||
if not legal_moves:
|
||||
raise RuntimeError("No legal moves")
|
||||
|
||||
best = Move()
|
||||
ok = self.chess_ffi._c_ai_find_best_move_with_window(
|
||||
board,
|
||||
@@ -56,7 +52,9 @@ class NegaMaxEval(BaseEvaluation):
|
||||
)
|
||||
|
||||
if ok:
|
||||
for m in legal_moves:
|
||||
if self._same(m, best):
|
||||
return m
|
||||
return legal_moves[0]
|
||||
return best
|
||||
return legal_moves[0]
|
||||
|
||||
|
||||
def get_params(self):
|
||||
return [self.depth, self.window]
|
||||
Reference in New Issue
Block a user