public static long[] GetKey(Board board) { long[] key = new long[] { 0, 0 }; long square = BitboardUtils.H1; byte index = 0; int color = 0; while (square != 0) { color = (square & board.whites) != 0 ? 0 : 1; key[color] ^= GetKeyPieceIndex(index, board.GetPieceAt(square)); square <<= 1; index++; } if (board.GetWhiteKingsideCastling()) { key[0] ^= whiteKingSideCastling; } if (board.GetWhiteQueensideCastling()) { key[0] ^= whiteQueenSideCastling; } if (board.GetBlackKingsideCastling()) { key[1] ^= blackKingSideCastling; } if (board.GetBlackQueensideCastling()) { key[1] ^= blackQueenSideCastling; } // passant flags only when pawn can capture long passant = board.GetPassantSquare(); if ((passant != 0) && (((!board.GetTurn() && (((passant << 9) | (passant << 7)) & board.blacks & board.pawns) != 0)) || ((board.GetTurn() && ((((long)(((ulong)passant ) >> 9)) | ((long)(((ulong)passant) >> 7))) & board.whites & board.pawns) != 0)) )) { color = board.GetTurn() ? 0 : 1; // TODO test key[1 - color] ^= passantColumn[BitboardUtils.GetColumn(passant)]; } if (board.GetTurn()) { key[0] ^= whiteMove; } return key; }