hash method

int hash()
override

A full 64-bit position key (native ints), folding all piece bitboards plus side-to-move, castling rights and the en-passant square. Cheap — no FEN rebuild — and collisions are negligible for a per-search table.

Implementation

int hash() {
  var h = turn == white ? 0x9e3779b97f4a7c15 : 0x1c69b3f74ac4ae35;
  for (var c = 0; c < 2; c++) {
    for (var t = 0; t < 6; t++) {
      h = _mix(h ^ pieces[c][t]) + (c * 6 + t + 1);
    }
  }
  h ^= castling * 0x100000001b3;
  h ^= epSquare + 1;
  return _mix(h);
}