Exemple #1
0
        public void UndoMoviment(Position origin, Position destiny, Piece takenPiece)
        {
            Piece p = BoardOfMatch.RemovePiece(destiny);

            p.DecrementManyMoves();
            if (takenPiece != null)
            {
                BoardOfMatch.PutPiece(takenPiece, destiny);
                CapturedPieces.Remove(takenPiece);
            }
            BoardOfMatch.PutPiece(p, origin);


            // #SpecialMove
            // Castle Kingside
            if (p is King && destiny.Column == origin.Column + 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column + 3);
                Position destinyOfRook = new Position(origin.Line, origin.Column + 1);

                Piece rook = BoardOfMatch.RemovePiece(destinyOfRook);
                rook.DecrementManyMoves();
                BoardOfMatch.PutPiece(rook, originOfRook);
            }

            // Castle Queenside
            if (p is King && destiny.Column == origin.Column - 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column - 4);
                Position destinyOfRook = new Position(origin.Line, origin.Column - 1);

                Piece rook = BoardOfMatch.RemovePiece(destinyOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, originOfRook);
            }

            // EnPassant
            if (p is Pawn)
            {
                if (origin.Column != destiny.Column && takenPiece == VulnerableEnPassant)
                {
                    Piece    pawn = BoardOfMatch.RemovePiece(destiny);
                    Position posPawn;
                    if (p.Color == Color.White)
                    {
                        posPawn = new Position(3, destiny.Column);
                    }
                    else
                    {
                        posPawn = new Position(4, destiny.Column);
                    }
                    BoardOfMatch.PutPiece(pawn, posPawn);
                }
            }
        }