예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }