Ejemplo n.º 1
0
        private void undoMovement(Position origin, Position destiny, Piece deadPiece)
        {
            Piece p = board.removePiece(destiny);

            p.decreaseMovement();
            if (deadPiece != null)
            {
                board.addPiece(deadPiece, destiny);
                deadPieces.Remove(deadPiece);
            }
            board.addPiece(p, origin);

            //#jogadaespecial roque pequeno
            if (p is King && destiny.column == origin.column + 2)
            {
                Position rookOrigin  = new Position(origin.line, origin.column + 3);
                Position rookDestiny = new Position(origin.line, origin.column + 1);
                Piece    king        = board.removePiece(rookDestiny);
                king.decreaseMovement();
                board.addPiece(king, rookOrigin);
            }

            //#jogadaespecial roque grande
            if (p is King && destiny.column == origin.column - 2)
            {
                Position rookOrigin  = new Position(origin.line, origin.column - 4);
                Position rookDestiny = new Position(origin.line, origin.column - 1);
                Piece    king        = board.removePiece(rookDestiny);
                king.decreaseMovement();
                board.addPiece(king, rookOrigin);
            }

            //#jogadaespecial en passant
            if (p is Pawn)
            {
                if (origin.column != destiny.column && deadPiece == canSufferEnPassant)
                {
                    Piece    pawn = board.removePiece(destiny);
                    Position pawnPos;
                    if (p.color == Color.white)
                    {
                        pawnPos = new Position(3, p.position.column);
                    }
                    else
                    {
                        pawnPos = new Position(4, p.position.column);
                    }
                    board.addPiece(pawn, pawnPos);
                }
            }
        }