Beispiel #1
0
        public Piece ExecuteAMovement(Position origin, Position destiny)
        {
            Piece piece = Board.RemovePiece(origin);

            piece.IncrementeNumberOfMovements();
            Piece capturedPiece = Board.RemovePiece(destiny);

            Board.InsertPiece(piece, destiny);
            if (capturedPiece != null)
            {
                Captured.Add(capturedPiece);
            }
            //#SpecialPlay Castling short

            if (piece 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    rook        = Board.RemovePiece(rookOrigin);
                rook.IncrementeNumberOfMovements();
                Board.InsertPiece(rook, rookDestiny);
            }

            //#SpecialPlay Castling long

            if (piece 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    rook        = Board.RemovePiece(rookOrigin);
                rook.IncrementeNumberOfMovements();
                Board.InsertPiece(rook, rookDestiny);
            }

            //#SpecialPlay EnPassant
            if (piece is Pawn)
            {
                if (origin.Column != destiny.Column && capturedPiece == null)
                {
                    Position pawnPosition;
                    if (piece.Color == Color.White)
                    {
                        pawnPosition = new Position(destiny.Line + 1, destiny.Column);
                    }
                    else
                    {
                        pawnPosition = new Position(destiny.Line - 1, destiny.Column);
                    }

                    capturedPiece = Board.RemovePiece(pawnPosition);
                    Captured.Add(capturedPiece);
                }
            }

            return(capturedPiece);
        }