Beispiel #1
0
        public Piece ExecuteMoviment(Position origin, Position destiny)
        {
            Piece p = BoardOfMatch.RemovePiece(origin);

            p.IncrementManyMoves();
            Piece takenPiece = BoardOfMatch.RemovePiece(destiny);

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

            // #SpecialPlay

            // 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(originOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, destinyOfRook);
            }

            // 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(originOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, destinyOfRook);
            }

            // EnPassant
            if (p is Pawn)
            {
                if (origin.Column != destiny.Column && takenPiece == null)
                {
                    Position posPawn;
                    if (p.Color == Color.White)
                    {
                        posPawn = new Position(destiny.Line + 1, destiny.Column);
                    }
                    else
                    {
                        posPawn = new Position(destiny.Line - 1, destiny.Column);
                    }
                    takenPiece = BoardOfMatch.RemovePiece(posPawn);
                    CapturedPieces.Add(takenPiece);
                }
            }
            return(takenPiece);
        }
Beispiel #2
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);
                }
            }
        }