Esempio n. 1
0
        public RepairBot(string inData, string outFile)
        {
            string curMapFile = "BotMap.txt";
            string rootPath   = Path.GetDirectoryName(outFile);

            curMapFile         = Path.Combine(rootPath, curMapFile);
            sw                 = new StreamWriter(outFile);
            xSize              = 42;
            ySize              = 42;
            startNode          = new ExploreNode();
            startNode.nodeType = RobotResultCode.MOVE_SUCCESFUL;
            curNode            = startNode;
            curMap             = new ExploreNode[xSize * ySize];
            curPos.x           = xSize / 2;
            curPos.y           = ySize / 2;
            int startIndex = Helpers.GetIndexFromCoordinate(curPos, xSize);

            curMap[startIndex] = startNode;
            curComputer        = new IntComputer();
            curComputer.InitializeMemory(inData);
            curComputer.StartComputer(true);
            RunRobot();

            //DrawMap();
            int endIndex = Helpers.GetIndexFromCoordinate(curPos, xSize);
            int length   = SearchTree(startIndex, endIndex);

            sw.Close();
        }
Esempio n. 2
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. 3
0
 public ArcadeMachine(string sourceData, string outFile)
 {
     curComputer = new IntComputer();
     curComputer.InitializeMemory(sourceData);
     curComputer.ReplaceMemoryAtAddress(0, 2); // infinite play
     curComputer.StartComputer(true);
     sw = new StreamWriter(outFile);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public Amplifiers(int ampCount, string sourceProgram)
 {
     numAmplifiers = ampCount;
     for (int intI = 0; intI < ampCount; intI++)
     {
         IntComputer newComp = new IntComputer();
         newComp.curId = numAmplifiers - intI;
         newComp.InitializeMemory(sourceProgram);
         newComp.StartComputer(true);
         generatedAmplifiers.Add(newComp);
     }
 }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public PainterRobot(string sourceInstructions, int width, int height, string debugFile)
        {
            outFile       = debugFile;
            xSize         = width;
            ySize         = height;
            curPos        = new Vector2();
            curPos.x      = xSize / 2;
            curPos.y      = ySize / 2;
            panelsToPaint = new PaintPanelStruct[xSize * ySize];
            int curIndex = Helpers.GetIndexFromCoordinate(curPos, xSize);

            panelsToPaint[curIndex].curColor = PaintColorEnum.WHITE;

            robotComputer = new IntComputer();
            robotComputer.InitializeMemory(sourceInstructions);
            robotComputer.StartComputer(true);
            RunRobot();
        }
Esempio n. 8
0
 public bool FindNounVerb(IntComputer newComp)
 {
     for (int intI = 0; intI < 100; intI++)
     {
         for (int intJ = 0; intJ < 100; intJ++)
         {
             newComp.ResetMemory();
             newComp.ReplaceMemoryAtAddress(1, (long)intI);
             newComp.ReplaceMemoryAtAddress(2, (long)intJ);
             newComp.StartComputer(false);
             long result = newComp.ReadMemoryAtAddress(0);
             if (result == 19690720)
             {
                 // ALL DONE
                 return(true);
             }
         }
     }
     return(false);
 }