Esempio n. 1
0
 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();
             }
         }
     }
 }
Esempio n. 2
0
 public RobotResultCode RunRobotCycle(MovementCommandEnum moveCommand)
 {
     // run until there's output.
     curComputer.AddInputData((int)moveCommand);
     curComputer.ResumeProgram();
     return((RobotResultCode)curComputer.ReadOutputData());
 }
Esempio n. 3
0
        public void SolveDayNine()
        {
            string resultsFile = "adventDayNineSolution.txt";
            string dataFile    = "adventDayNine.txt";
            string outFile     = Path.Combine(baseDir, resultsFile);
            string inFile      = Path.Combine(baseDir, dataFile);

            string[]    sourceData = ReadAllLines(inFile);
            IntComputer curComp    = new IntComputer();

            curComp.InitializeMemory(sourceData[0]);
            curComp.AddInputData(2); // test mode
            //curComp.InitializeMemory(SolverTests.GetSampleData(0));
            curComp.StartComputer(false);
            while (!curComp.IsProgramCompleted())
            {
                curComp.ResumeProgram();
            }
            string       debugData = curComp.GetDebugOutputString();
            StreamWriter sw        = new StreamWriter(outFile);

            sw.WriteLine(debugData);
            sw.Close();
            //long outVal = curComp.ReadOutputData();
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public void SolveDayFive()
        {
            string resultsFile = "adventDayFiveSolution.txt";
            string dataFile    = "adventDayFive.txt";
            string outFile     = Path.Combine(baseDir, resultsFile);
            string inFile      = Path.Combine(baseDir, dataFile);

            string[] sourceData = ReadAllLines(inFile);
            // should be one line
            IntComputer newComp = new IntComputer();

            newComp.InitializeMemoryFromFile(inFile);
            newComp.AddInputData(5);
            newComp.StartComputer(false);
            newComp.WriteMemoryToFile(outFile);
        }