/// Calculate zobrist key from current board position. This should only be used after setting board from fen; during search the key should be updated incrementally. public static ulong CalculateZobristKey(Board board) { ulong zobristKey = 0; for (int squareIndex = 0; squareIndex < 64; squareIndex++) { if (board.Square[squareIndex] != 0) { int pieceType = Piece.PieceType(board.Square[squareIndex]); int pieceColour = Piece.Colour(board.Square[squareIndex]); zobristKey ^= piecesArray[pieceType, (pieceColour == Piece.White) ? Board.WhiteIndex : Board.BlackIndex, squareIndex]; } } int epIndex = (int)(board.currentGameState >> 4) & 15; if (epIndex != -1) { zobristKey ^= enPassantFile[epIndex]; } if (board.ColourToMove == Piece.Black) { zobristKey ^= sideToMove; } zobristKey ^= castlingRights[board.currentGameState & 0b1111];