public int Part1() { var oxigenGrid = new OxigenGrid(); while (OxigenGrid.IsPosiblePaths()) { try { oxigenGrid = new OxigenGrid(); IntCodeComputer computer = new IntCodeComputer(oxigenGrid, oxigenGrid); computer.Execute(_program); Console.WriteLine("SOLUTION " + OxigenGrid.MovementsToOrigin.Count); Console.Clear(); Console.WriteLine(Day13Utils.PrintBoard(oxigenGrid.GetGrid())); Console.WriteLine("----------------------------------"); } catch (Exception e) { //Console.WriteLine("End of simulation"); } } StringBuilder builder = new StringBuilder(); foreach (var value in oxigenGrid.GetGrid()) { builder.AppendLine($"{value.point.X},{value.point.Y},{value.value}"); } File.WriteAllText("grid.txt", builder.ToString()); Console.WriteLine("SOLUTION " + OxigenGrid.MovementsToOrigin.Count); Console.Clear(); Console.WriteLine(Day13Utils.PrintBoard(oxigenGrid.GetGrid())); Console.WriteLine("----------------------------------"); return(0); }
public int Part2() { OxigenGrid.SetGrid(_grid); Dictionary <Point, TileType> values = OxigenGrid.GetDictionaryGrid(); var oxigenPoints = _grid.Where(v => v.value == (int)TileType.Oxigen).Select(v => v.point).ToList(); int minute = 0; while (oxigenPoints.Any()) { var convertedPoints = new HashSet <Point>(); foreach (var oxigenPoint in oxigenPoints) { var posibleMovements = OxigenGrid.GetPosibleMovements(oxigenPoint); foreach (Point posibleMovement in posibleMovements) { convertedPoints.Add(posibleMovement); } } oxigenPoints = convertedPoints.ToList(); minute++; Console.WriteLine(Day13Utils.PrintBoard(OxigenGrid.GetGrid2())); Console.WriteLine("---------------------------"); Console.ReadKey(); } //_program[0] = 2; //var gameGrid = new GameGrid(); //IntCodeComputer computer = new IntCodeComputer(gameGrid, gameGrid); //computer.Execute(_program); //return gameGrid.GetNumOfBlocks(); Console.WriteLine("SOLUCION " + minute); Console.ReadKey(); return(0); }
public long Read() { var gridString = Day13Utils.PrintBoard(GetGrid()); Console.WriteLine($"SCORE: {Score}"); Console.WriteLine(gridString); int value = int.MinValue; while (!(value >= -1 && value <= 1)) { var readed = Console.ReadKey(); value = readed.Key switch { ConsoleKey.LeftArrow => - 1, ConsoleKey.RightArrow => 1, ConsoleKey.UpArrow => 0, _ => int.MinValue, }; } return(value); }