import java.util.*;

public class RepairDroid
{
    public static final String INITIAL_INPUT = Integer.toString(DroidMovement.NORTH);

    public RepairDroid (Vector<String> instructions, boolean debug)
    {
        _debug = debug;
        _theComputer = new Intcode(instructions, INITIAL_INPUT, _debug);
        _currentLocation = new Coordinate(0, 0);  // starting location
        _theMap = new Maze();

        _theMap.addContent(_currentLocation, TileId.TRAVERSE);

        _visited = null;
    }

    public final int moveToOxygenStation ()
    {
        int numberOfSteps = 0;

        _visited = new ArrayList<Coordinate>();

        // create a map first!

        recursiveSearch(_currentLocation);

        return numberOfSteps;
    }

    public void printGrid ()
    {
        System.out.println(_theMap);
    }

    private boolean recursiveSearch (Coordinate from)
    {
        while (!_theComputer.hasHalted())
        {
            Coordinate to = new Coordinate(from.getX(), from.getY()+1);

            System.out.println("\n"+_theMap);

            if (!tryToMove(String.valueOf(DroidMovement.NORTH), from, to))
            {
                to = new Coordinate(from.getX(), from.getY()-1);

                System.out.println("\n"+_theMap);

                if (!tryToMove(String.valueOf(DroidMovement.SOUTH), from, to))
                {
                    to = new Coordinate(from.getX()+1, from.getY());

                    System.out.println("\n"+_theMap);

                    if (!tryToMove(String.valueOf(DroidMovement.EAST), from, to))
                    {
                        to = new Coordinate(from.getX()-1, from.getY());

                        System.out.println("\n"+_theMap);

                        return tryToMove(String.valueOf(DroidMovement.WEST), from, to);
                    }
                }
            }
        }

        return false;
    }

    private boolean tryToMove (String direction, Coordinate from, Coordinate to)
    {
        System.out.println("**Trying to move from: "+from+" to "+to+" with direction "+DroidMovement.toString(direction));

        _theComputer.setInput(direction);

        do
        {
            System.out.println("**Single step execution!");

            _theComputer.singleStepExecution();
        }
        while (!_theComputer.waitingForInput());

        System.out.println("**Waiting for input and output is: "+_theComputer.hasOutput());

        if (_theComputer.hasOutput())
        {
            int response = Integer.parseInt(_theComputer.getOutput());

            System.out.println("**Response is "+DroidStatus.toString(response));

            switch (response)
            {
                case DroidStatus.ARRIVED:
                {
                    _theMap.addContent(to, TileId.OXYGEN_STATION);
                    _currentLocation = to;

                    return true;
                }
                case DroidStatus.COLLISION:
                {
                    _theMap.addContent(to, TileId.WALL);  // didn't move as we hit a wall

                    return false;
                }
                case DroidStatus.MOVED:
                {
                    _theMap.addContent(to, TileId.TRAVERSE);
                    _currentLocation = to;
                    
                    return recursiveSearch(to);
                }
                default:
                    System.out.println("Unknown response: "+response);
            }
        }
        else
            System.out.println("Error - no output after move instruction!");

        return false;
    }

    private final Coordinate getNextPosition (Coordinate coord, int x, int y)
    {
        return new Coordinate(coord.getX() + x, coord.getY() + y);
    }

    private boolean _debug;
    private Intcode _theComputer;
    private Coordinate _currentLocation;
    private Maze _theMap;
    private List<Coordinate> _visited;
}
@@ -880,32 +880,388 @@
 )%0A    %7B%0A        
+/*%0A                if (_theMap.isWall(from) %7C%7C !_theMap.isUnexplored(from))%0A            return false;%0A        %0A        _currentLocation = from;%0A        _visited.add(_currentLocation);%0A%0A        _theMap.addContent(_currentLocation, TileId.TRAVERSE);%0A%0A        if (_theMap.isOxygenStation(from))%0A            return true;%0A%0A            */%0A            %0A        //
 while (!_theComp
@@ -3627,36 +3627,16 @@
 n = to;%0A
-                    
 %0A       
@@ -3962,16 +3962,18 @@
 ordinate
+%5B%5D
  getNext
@@ -3980,16 +3980,17 @@
 Position
+s
  (Coordi
@@ -4003,95 +4003,356 @@
 oord
-, int x, int y)
+)%0A    %7B%0A        Coordinate%5B%5D coords = new Coordinate%5B4%5D;%0A
 %0A    
-%7B%0A
     
-    return new Coordinate(coord.getX() + x, coord.getY() + y)
+coords%5B0%5D = new Coordinate(coord.getX(), coord.getY() -1);%0A        coords%5B1%5D = new Coordinate(coord.getX(), coord.getY() +1);%0A        coords%5B2%5D = new Coordinate(coord.getX() -1, coord.getY());%0A        coords%5B3%5D = new Coordinate(coord.getX() +1, coord.getY());%0A%0A        return coords
 ;%0A  

Update RepairDroid.java