jamesqo / chess-bot

UCI-compliant chess engine written in C#
MIT License
1 stars 0 forks source link

Better move ordering to reduce search time #24

Open jamesqo opened 4 years ago

jamesqo commented 4 years ago

https://www.chessprogramming.org/Move_Ordering

jamesqo commented 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()); ... }
jamesqo commented 4 years ago

Alternatively (following the move ordering guide):

jamesqo commented 4 years ago

Move ordering for captures was implemented in https://github.com/jamesqo/chess-bot/pull/26