コード例 #1
0
        public void Move(int move)
        {
            halfMovesStack.Push(halfMoves);
            IPiece p = board[MovePackHelper.GetStartSquare(move)];

            if (MovePackHelper.HasCapture(move))
            {
                captured.Push(board[MovePackHelper.GetEndSquare(move)]);
                board[MovePackHelper.GetEndSquare(move)].Capture();
                ZKey           ^= ZKeyForCastling[(int)CastlingStatus];
                CastlingStatus ^= MovePackHelper.GetCastleMask(move);
                ZKey           ^= ZKeyForCastling[(int)CastlingStatus];
                halfMoves       = 0;
            }
            else
            {
                if (p.Type != PieceType.Pawn)
                {
                    halfMoves++;
                }
            }
            p.Move(move);
            if (MovePackHelper.HasCastling(move))
            {
                DoCastling(move);
            }
            PromotionTo to = MovePackHelper.GetPromotion(move);

            if (to != PromotionTo.None)
            {
                DoPromotion(p, move, to);
            }
            moveStack.Push(move);
            if (!epTouched)
            {
                PlaceEnpassant(Square.Invalid);
            }
            epTouched = false;
            if (ToMove == Side.Black)
            {
                movesCount++;
            }
            Flip();
            Debug.Assert(ZKey == CalcZKey());
        }
コード例 #2
0
        private void UndoMove(int move)
        {
            IPiece p = board[MovePackHelper.GetEndSquare(move)];

            p.UnMove(move);
            if (MovePackHelper.HasCapture(move))
            {
                IPiece resumed = captured.Pop();
                resumed.UnCapture(MovePackHelper.GetEndSquare(move));
                board[resumed.HomeSquare] = resumed;
                ZKey           ^= ZKeyForCastling[(int)CastlingStatus];
                CastlingStatus ^= MovePackHelper.GetCastleMask(move);
                ZKey           ^= ZKeyForCastling[(int)CastlingStatus];
            }
            if (MovePackHelper.HasCastling(move))
            {
                UndoCastling(move);
            }
            PromotionTo to = MovePackHelper.GetPromotion(move);

            if (to != PromotionTo.None)
            {
                UndoPromotion(p, move, to);
            }
            if (!epTouched)
            {
                UnplaceEnPassant();
            }
            epTouched = false;
            if (ToMove == Side.White)
            {
                movesCount--;
            }
            halfMoves = halfMovesStack.Pop();
            Flip();
            Debug.Assert(ZKey == CalcZKey());
        }