Exemplo n.º 1
0
        public void undoTheMove(Position origin, Position destiny, Piece capturedPiece)
        {
            Piece p = br.throwPiece(destiny);

            p.decreaseNoMoviments();
            if (capturedPiece != null)
            {
                br.putPiece(capturedPiece, destiny);
                captured.Remove(capturedPiece);
            }
            br.putPiece(p, origin);

            if (p is King && destiny.column == origin.column + 2)
            {
                Position originR  = new Position(origin.line, origin.column + 3);
                Position destinyR = new Position(origin.line, origin.column + 1);
                Piece    R        = br.throwPiece(destinyR);
                R.decreaseNoMoviments();
                br.putPiece(R, originR);
            }

            //Big Castling
            if (p is King && destiny.column == origin.column - 2)
            {
                Position originR  = new Position(origin.line, origin.column - 4);
                Position destinyR = new Position(origin.line, origin.column - 1);
                Piece    R        = br.throwPiece(destinyR);
                R.decreaseNoMoviments();
                br.putPiece(R, originR);
            }

            //Special moviment en passant
            if (p is Pawn)
            {
                if (origin.column != destiny.column && capturedPiece == vulnerableEnPassant)
                {
                    Piece    pawn = br.throwPiece(destiny);
                    Position posP;
                    if (p.color == Color.White)
                    {
                        posP = new Position(3, destiny.column);
                    }
                    else
                    {
                        posP = new Position(4, destiny.column);
                    }
                    br.putPiece(pawn, posP);
                }
            }
        }