示例#1
0
        internal static ulong UpdateZobristHash(ulong hash, MoveContent move, ChessPieceColor whosMove, bool pawnPromote)
        {
            hash = Zobrist.GetHashResult((int)move.MovingPiecePrimary.SrcPosition, move.MovingPiecePrimary.PieceType, move.MovingPiecePrimary.PieceColor, hash);
            if (move.MovingPieceSecondary.PieceType != ChessPieceType.None)
            {
                hash = Zobrist.GetHashResult((int)move.MovingPieceSecondary.SrcPosition, move.MovingPieceSecondary.PieceType, move.MovingPieceSecondary.PieceColor, hash);
                hash = Zobrist.GetHashResult((int)move.MovingPieceSecondary.DstPosition, move.MovingPieceSecondary.PieceType, move.MovingPieceSecondary.PieceColor, hash);
                if (move.MovingPieceSecondary.PieceColor == ChessPieceColor.White)
                {
                    hash ^= Zobrist.ZobristTable[770];
                }
                else
                {
                    hash ^= Zobrist.ZobristTable[771];
                }
            }
            if (move.TakenPiece.PieceType != ChessPieceType.None)
            {
                hash = Zobrist.GetHashResult((int)move.TakenPiece.Position, move.TakenPiece.PieceType, move.TakenPiece.PieceColor, hash);
            }
            hash = !pawnPromote?Zobrist.GetHashResult((int)move.MovingPiecePrimary.DstPosition, move.MovingPiecePrimary.PieceType, move.MovingPiecePrimary.PieceColor, hash) : Zobrist.GetHashResult((int)move.MovingPiecePrimary.DstPosition, ChessPieceType.Queen, move.MovingPiecePrimary.PieceColor, hash);

            if (whosMove == ChessPieceColor.White)
            {
                hash ^= Zobrist.ZobristTable[769];
                hash ^= Zobrist.ZobristTable[768];
            }
            else
            {
                hash ^= Zobrist.ZobristTable[768];
                hash ^= Zobrist.ZobristTable[769];
            }
            return(hash);
        }
示例#2
0
        internal static ulong CalculateZobristHash(Board board)
        {
            ulong hash = 0;

            for (int position = 0; position < 64; ++position)
            {
                Square square = board.Squares[position];
                if (square.Piece != null)
                {
                    hash = Zobrist.GetHashResult(position, square.Piece.PieceType, square.Piece.PieceColor, hash);
                }
            }
            ulong num = board.WhoseMove != ChessPieceColor.White ? hash ^ Zobrist.ZobristTable[769] : hash ^ Zobrist.ZobristTable[768];

            if (board.WhiteCastled)
            {
                num ^= Zobrist.ZobristTable[770];
            }
            if (board.BlackCastled)
            {
                num ^= Zobrist.ZobristTable[771];
            }
            return(num);
        }