// polyglot_key() returns the PolyGlot hash key of the given position public static Key polyglot_key(Position pos) { Key key = 0; Bitboard b = pos.pieces(); while (b != 0) { Square s = BitBoard.pop_lsb(ref b); Piece pc = pos.piece_on(s); // PolyGlot pieces are: BP = 0, WP = 1, BN = 2, ... BK = 10, WK = 11 int pieceOfs = 2 * (Types.type_of_piece(pc) - 1) + ((Types.color_of(pc) == ColorS.WHITE) ? 1 : 0); key ^= PG[psq + (64 * pieceOfs + s)]; } b = (ulong)pos.can_castle_castleright(CastlingRightS.ANY_CASTLING); while (b != 0) { key ^= PG[castle + BitBoard.pop_lsb(ref b)]; } if (pos.ep_square() != SquareS.SQ_NONE) { key ^= PG[enpassant + Types.file_of(pos.ep_square())]; } if (pos.side_to_move() == ColorS.WHITE) { key ^= PG[turn + 0]; } return(key); }