import java.util.function.IntConsumer;

import java.util.*;

public class GameEngine
{
    public GameEngine (Vector<String> instructions, boolean debug)
    {
        _computer = new Intcode(instructions, INITIAL_INPUT, debug);
        _debug = debug;
    }

    public final boolean playGame ()
    {
        int x = 0;
        int y = 0;
        int id = TileId.EMPTY;

        while (!_computer.hasHalted())
        {
            while (!_computer.hasHalted() && !_computer.hasOutput())
            {
                System.out.println("**checking x");
                _computer.singleStepExecution(INITIAL_INPUT);
            }

            if (!_computer.hasHalted())
            {
                x = Integer.parseInt(_computer.getOutput());

                while (!_computer.hasHalted() && !_computer.hasOutput())
                {
                    System.out.println("**checking y");
                    _computer.singleStepExecution(INITIAL_INPUT);
                }

                if (!_computer.hasHalted())
                {
                    y = Integer.parseInt(_computer.getOutput());

                    while (!_computer.hasHalted() && !_computer.hasOutput())
                    {
                        System.out.println("**checking id");
                        _computer.singleStepExecution(INITIAL_INPUT);
                    }

                    id = Integer.parseInt(_computer.getOutput());
                }
                else
                {
                    System.out.println("Error - computer halted after y!");

                    return false;
                }

                System.out.println("**got "+x+" "+y+" "+TileId.idToString(id));
            }
            else
            {
                System.out.println("Error - computer halted after x!");

                return false;
            }
        }

        return true;
    }

    private Intcode _computer;
    private boolean _debug;

    private static final int INITIAL_INPUT = 0; // nothing specified in the overview
}
@@ -502,60 +502,8 @@
   %7B%0A
-                System.out.println(%22**checking x%22);%0A
     
@@ -786,64 +786,8 @@
   %7B%0A
-                    System.out.println(%22**checking y%22);%0A
     
@@ -1098,69 +1098,8 @@
   %7B%0A
-                        System.out.println(%22**checking id%22);%0A
     
@@ -1380,17 +1380,33 @@
 d after 
-y
+outputing x value
 !%22);%0A%0A  
@@ -1573,32 +1573,64 @@
 e%0A            %7B%0A
+                if (_debug)%0A    
                 
@@ -1645,33 +1645,25 @@
 ut.println(%22
-Error - c
+C
 omputer halt
@@ -1668,17 +1668,9 @@
 lted
- after x!
+.
 %22);%0A
@@ -1685,36 +1685,35 @@
          return 
-fals
+tru
 e;%0A            %7D

Update GameEngine.java