void ReadComputerDataAndUpdateScreen() { curComputer.AddInputData(0); for (int intI = 0; intI < requiredOutputPerCycle; intI++) { curComputer.ResumeProgram(); // 1 } if (curComputer.HasOutputData()) { int xLoc = (int)curComputer.ReadOutputData(); int yLoc = (int)curComputer.ReadOutputData(); if (xLoc < 0) { // score, not the other thing curScore = curComputer.ReadOutputData(); Console.WriteLine(curScore); startDrawing = true; curComputer.AddInputData(0); } else { BlockTypeEnum bt = (BlockTypeEnum)curComputer.ReadOutputData(); screen = Helpers.ExpandListOfLists(screen, xLoc, yLoc); screen[yLoc][xLoc] = bt; if (startDrawing) { //DrawScreen(); } } } }
public void RunRobot() { /* * The Intcode program will serve as the brain of the robot. * The program uses input instructions to access the robot's camera: * provide 0 if the robot is over a black panel or 1 if the robot is over * a white panel. Then, the program will output two values: * First, it will output a value indicating the color to paint the * panel the robot is over: 0 means to paint the panel black, * and 1 means to paint the panel white. * Second, it will output a value indicating the * direction the robot should turn: 0 means it should turn * left 90 degrees, and 1 means it should turn right 90 degrees. * After the robot turns, it should always move forward exactly one panel. The robot starts facing up. */ bm = new Bitmap(xSize, ySize); for (int intX = 0; intX < xSize; intX++) { for (int intY = 0; intY < ySize; intY++) { bm.SetPixel(intX, intY, Color.Black); } } bm.SetPixel(curPos.x, curPos.y, Color.White); sw = new StreamWriter(outFile); PaintColorEnum colorToPaint; int directionToTurn; while (!robotComputer.IsProgramCompleted()) { robotComputer.AddInputData((long)GetPanelColorAtPosition()); sw.WriteLine("Adding input " + (long)GetPanelColorAtPosition()); robotComputer.ResumeProgram(); robotComputer.ResumeProgram(); if (!robotComputer.IsProgramCompleted()) { long outputOne = robotComputer.ReadOutputData();; long outputTwo = robotComputer.ReadOutputData(); sw.WriteLine("Program returned 2 values first=" + outputOne + " second=" + outputTwo); colorToPaint = (PaintColorEnum)outputOne; sw.Write("Painting current panel color " + colorToPaint); PaintPanelAtPosition(colorToPaint); directionToTurn = (int)outputTwo; sw.Write(" Turning robot " + directionToTurn); TurnRobot(directionToTurn); sw.WriteLine("Facing " + curDirection + " startPos is " + curPos.x + "," + curPos.y); curPos = Helpers.MovePos(curPos, curDirection); sw.WriteLine(" New pos is " + curPos.x + "," + curPos.y); } } sw.WriteLine("PAINTED " + panelsPainted); OutputDebugInfo(); sw.Close(); bm.Save(outFile + ".png", System.Drawing.Imaging.ImageFormat.Png); }
public RobotResultCode RunRobotCycle(MovementCommandEnum moveCommand) { // run until there's output. curComputer.AddInputData((int)moveCommand); curComputer.ResumeProgram(); return((RobotResultCode)curComputer.ReadOutputData()); }
public void TestDayNineSampleData(int sampleIndex) { IntComputer curComp = new IntComputer(); curComp.InitializeMemory(GetSampleData(sampleIndex)); curComp.StartComputer(false); long outVal = curComp.ReadOutputData(); long expectedRetVal = GetExpectedResults(sampleIndex); Assert.Equal(outVal, expectedRetVal); }