Skip to content

Commit 6c5f8af

Browse files
committed
Remove board evaluation cache
The cache adds complexity without significant benefit for typical game sessions (10k-100k unique positions). Removes the dictionary, decorator, and unused imports.
1 parent c0ce6b1 commit 6c5f8af

1 file changed

Lines changed: 0 additions & 21 deletions

File tree

moonfish/psqt.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# flake8: noqa
22

33
import chess
4-
import chess.polyglot
54
import chess.syzygy
65

76
############
@@ -247,25 +246,6 @@ def get_phase(board: chess.Board) -> float:
247246
return phase
248247

249248

250-
BOARD_EVALUATION_CACHE: Dict[int, float] = {}
251-
BOARD_EVALUATION_CACHE_MAX_SIZE = 1_000_000 # Prevent unbounded memory growth
252-
253-
254-
def board_evaluation_cache(fun):
255-
256-
def inner(board: chess.Board):
257-
# Use zobrist hash (fast integer) instead of FEN (slow string)
258-
key = chess.polyglot.zobrist_hash(board)
259-
if key not in BOARD_EVALUATION_CACHE:
260-
# Clear cache if it gets too large (simple eviction policy)
261-
if len(BOARD_EVALUATION_CACHE) >= BOARD_EVALUATION_CACHE_MAX_SIZE:
262-
BOARD_EVALUATION_CACHE.clear()
263-
BOARD_EVALUATION_CACHE[key] = fun(board)
264-
return BOARD_EVALUATION_CACHE[key]
265-
266-
return inner
267-
268-
269249
# All piece types to iterate over
270250
PIECE_TYPES = [
271251
chess.PAWN,
@@ -277,7 +257,6 @@ def inner(board: chess.Board):
277257
]
278258

279259

280-
@board_evaluation_cache
281260
def board_evaluation(board: chess.Board) -> float:
282261
"""
283262
This functions receives a board and assigns a value to it, it acts as

0 commit comments

Comments
 (0)