public PositionLongHash CalculateHash(Position.Position position) { var result = new PositionLongHash(); result = result.CalculateXor( CalculatePiecesHash( position.Board.GetPieces(Player.Black), Player.Black)); result = result.CalculateXor( CalculatePiecesHash( position.Board.GetPieces(Player.White), Player.White)); result = result.CalculateXor(playerToMoveHashesTable[(int)position.PlayerToMove]); result = result.CalculateXor( GetEnPassantCaptureColumnHash(position.EnPassantCaptureColumn)); result = result.CalculateXor( GetCastlingAvailabilityHash( position.GetCastlingAvailability(Player.Black), Player.Black)); result = result.CalculateXor( GetCastlingAvailabilityHash( position.GetCastlingAvailability(Player.White), Player.White)); return(result); }
private static PositionLongHash[] GenerateHashesTable(Random random, int tableSize) { var hashesTable = new PositionLongHash[tableSize]; for (int i = 0; i < hashesTable.Length; ++i) { hashesTable[i] = GenerateLongHash(random); } return(hashesTable); }
private PositionLongHash CalculatePiecesHash( IEnumerable <PieceOnBoard> pieces, Player player) { var result = new PositionLongHash(); foreach (var pieceOnBoard in pieces) { var pieceHash = GetPieceHash(player, pieceOnBoard.piece, pieceOnBoard.square); result = result.CalculateXor(pieceHash); } return(result); }
private PositionLongHash GetCastlingAvailabilityHash( CastlingAvailability castlingAvailability, Player player) { var result = new PositionLongHash(); if (castlingAvailability.CanCastleShort) { result = result.CalculateXor(shortCastlingHashesTable[(int)player]); } if (castlingAvailability.CanCastleLong) { result = result.CalculateXor(longCastlingHashesTable[(int)player]); } return(result); }