public static long Part2(string inputText) { var intcode = InputParser.ListOfLongs(inputText, ','); var compiler = new IntCodeCompiler(0, true); intcode[0] = 2; var program = new IntCodeProgram(intcode, 0); var level = new TileType[100, 100]; int ballPosition = 0; int paddlePosition = 0; int blockRemaining = 261; int maxBreak = 25000; long score = 0; while (--maxBreak > 0 && !program.IsDone && blockRemaining > 0) { paddlePosition = FindXOfTileTyle(TileType.Paddle, level); ballPosition = FindXOfTileTyle(TileType.Ball, level); if (paddlePosition < ballPosition) { compiler.SetInputs(new long[] { 1 }); } else if (paddlePosition > ballPosition) { compiler.SetInputs(new long[] { -1 }); } else { compiler.SetInputs(new long[] { 0 }); } compiler.Clear(); program = compiler.Compute(program); program = compiler.Compute(program); program = compiler.Compute(program); if (compiler.OutputValues[0] == -1 && compiler.OutputValues[1] == 0) { blockRemaining--; score = compiler.OutputValues[2]; Debug.Log($"{blockRemaining} block remainning. Score : {score}"); } else { var x = compiler.OutputValues[0]; var y = compiler.OutputValues[1]; var tileType = (int)compiler.OutputValues[2]; level[y, x] = IdToTileType(tileType); } } Debug.Log($"maxBreak:{maxBreak}, "); return(score); }
private void Move(Direction direction) { Compiler.Clear(); Compiler.SetInputs((long)direction); Program = Compiler.Compute(Program); var output = Compiler.OutputValue; var forwardTile = GetForward(CurrentPosition, direction); ExploredMap[forwardTile.y, forwardTile.x] = true; if (output == 0) { Map[forwardTile.y, forwardTile.x] = TileType.Wall; } else if (output == 1) { Map[forwardTile.y, forwardTile.x] = TileType.Empty; CurrentPosition = forwardTile; } else { Map[forwardTile.y, forwardTile.x] = TileType.OxygenSystem; CurrentPosition = forwardTile; } var map = (TileType[, ])Map.Clone(); AOCExecutor.ActionForMainOnPerUpdate.Enqueue(() => RepairDroid.MapToTexturee(map, AOCUI.Instance.Part1ComputeOutput)); }
public static long RunSequence(long[] intcode, long[] phases) { var compiler = new IntCodeCompiler(); long input = 0; foreach (var phase in phases) { compiler.Clear(); compiler.SetInputs(new long[] { phase, input }); var program = new IntCodeProgram(intcode.ToArray(), 0); compiler.Compute(program); input = compiler.OutputValue; } return(input); }
public void Step() { var currentColor = 0L; compiler.Clear(); if (Painting.ContainsKey(CurrentPosition)) { currentColor = Painting[CurrentPosition].Last(); } else { Painting.Add(CurrentPosition, new List <long>()); currentColor = 0; } compiler.SetInputs(new long[] { currentColor }); Program = compiler.Compute(Program); Program = compiler.Compute(Program); if (Program.IsDone) { return; } // Debug.Log(compiler.OutputAasListIntStr); Painting[CurrentPosition].Add(compiler.OutputValues[0]); if (compiler.OutputValues[1] == 0) { CurrentDirection = LeftOf(CurrentDirection); } else { CurrentDirection = RightOf(CurrentDirection); } CurrentPosition = MoveForward(CurrentPosition, CurrentDirection); }