This commit is contained in:
@@ -15,6 +15,10 @@ class BaseEvaluation:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_params(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
We will use a random move evaluation as our base AI. This
|
We will use a random move evaluation as our base AI. This
|
||||||
is expected to be the worst performing strategy. We can
|
is expected to be the worst performing strategy. We can
|
||||||
@@ -38,15 +42,7 @@ class NegaMaxEval(BaseEvaluation):
|
|||||||
self.window = cp_window
|
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):
|
def get_best_move(self, board, legal_moves):
|
||||||
if not legal_moves:
|
|
||||||
raise RuntimeError("No legal moves")
|
|
||||||
|
|
||||||
best = Move()
|
best = Move()
|
||||||
ok = self.chess_ffi._c_ai_find_best_move_with_window(
|
ok = self.chess_ffi._c_ai_find_best_move_with_window(
|
||||||
board,
|
board,
|
||||||
@@ -56,7 +52,9 @@ class NegaMaxEval(BaseEvaluation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ok:
|
if ok:
|
||||||
for m in legal_moves:
|
return best
|
||||||
if self._same(m, best):
|
return legal_moves[0]
|
||||||
return m
|
|
||||||
return legal_moves[0]
|
|
||||||
|
def get_params(self):
|
||||||
|
return [self.depth, self.window]
|
||||||
Reference in New Issue
Block a user