20-add-negamax-eval-function (#31)
All checks were successful
Python tests (make) / test (push) Successful in 12s

Reviewed-on: #31
Co-authored-by: Josh <josh@joshuaschuett.com>
Co-committed-by: Josh <josh@joshuaschuett.com>
This commit is contained in:
2025-08-26 00:28:03 +00:00
committed by Josh
parent 6005741b10
commit 27d0f1b6e6
12 changed files with 622 additions and 24 deletions

71
scripts/evaluation.py Normal file
View File

@@ -0,0 +1,71 @@
import random
from binding.python_c_ffi import ChessFFI
from binding.python_c_ffi import Move
class BaseEvaluation:
NAME = ""
def __init__(self, chess_ffi=None):
if chess_ffi is None:
chess_ffi = ChessFFI()
self.chess_ffi = chess_ffi
def get_best_move(self, board, legal_moves):
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
play our other AI evaluation methods against this one to
confirm if our other strategies are at least better than
a simplistic approach.
"""
class RandomEval(BaseEvaluation):
NAME = "random"
def __init__(self, chess_ffi=None):
super().__init__(chess_ffi)
def get_best_move(self, board, legal_moves):
return random.choice(legal_moves)
class NegaMaxEval(BaseEvaluation):
NAME = "negamax"
def __init__(self, depth=6, cp_window=20, chess_ffi=None):
super().__init__(chess_ffi)
self.depth = depth
self.window = cp_window
def get_best_move(self, board, legal_moves):
best = Move()
ok = self.chess_ffi._c_ai_find_best_move_with_window(
board,
self.depth,
self.window,
best
)
if ok:
return best
return legal_moves[0]
def get_params(self):
return {
"depth": self.depth,
"window": self.window,
}