Open jamesqo opened 4 years ago
One possible method is to calculate the heuristic values for each successor before sorting them (descending or ascending, depending on the active player) then searching them in that order.
It could be challenging to implement this without introducing memory allocations or significant slowdowns due to re-applying moves; we would essentially want to do something like this:
// Before
var pq; // priority queue
using var moves = state.GetPseudoLegalMoves(); // this returns a PooledList now since we're no longer iterating it lazily
foreach (var move in moves) {
if (!state.TryApply(move, out _)) continue;
pq.Add(state.Snapshot(), priority: Evaluation.Heuristic(state));
}
// dispose of moves here
while (!pq.IsEmpty) { state.Restore(in pq.Pop()); ... }
Alternatively (following the move ordering guide):
Move ordering for captures was implemented in https://github.com/jamesqo/chess-bot/pull/26
https://www.chessprogramming.org/Move_Ordering