Example #1
0
        public void UndoMoviment(Position origin, Position destiny, Piece capturedPiece = null)
        {
            Piece p = Board.ToRemovePiece(destiny);

            p.UpdateDecrementAmtMoviments();

            if (capturedPiece != null)
            {
                Board.ToSetPiece(capturedPiece, destiny);
                Captureds.Remove(capturedPiece);
            }
            Board.ToSetPiece(p, origin);


            //#Special Moviment Small Rock
            if (p is King && destiny.Column == origin.Column + 2)
            {
                Position originTower  = new Position(origin.Row, origin.Column + 3);
                Position destinyTower = new Position(origin.Row, origin.Column + 1);
                Piece    T            = Board.ToRemovePiece(destinyTower);
                T.UpdateDecrementAmtMoviments();
                Board.ToSetPiece(T, originTower);
            }

            //#Special Moviment Small Rock
            if (p is King && destiny.Column == origin.Column - 2)
            {
                Position originTower  = new Position(origin.Row, origin.Column - 4);
                Position destinyTower = new Position(origin.Row, origin.Column - 1);
                Piece    T            = Board.ToRemovePiece(destinyTower);
                T.UpdateAmtMoviments();
                Board.ToSetPiece(T, originTower);
            }

            //#Special Moviment En Passant
            if (p is Pawn)
            {
                if (origin.Column != destiny.Column && capturedPiece == CanPassant)
                {
                    Piece    pawn = Board.ToRemovePiece(destiny);
                    Position posP;
                    if (p.Color == Color.White)
                    {
                        posP = new Position(3, destiny.Column);
                    }
                    else
                    {
                        posP = new Position(4, destiny.Column);
                    }

                    Board.ToSetPiece(pawn, posP);
                }
            }
        }