Esempio n. 1
0
        public override void Start2()
        {
            var filename  = GetFileName1();
            var amplifier = new Amplifier()
            {
                IntCode = GetLongList_BySeparator(filename, ","),
            };

            var Grid = new Grid(10_000);

            Grid.Panels[Grid.CurrentY, Grid.CurrentX] = 1;

            while (!amplifier.IsHalt())
            {
                amplifier.IO.AddLast(Grid.GetCurrentPanelColor());
                amplifier.WorkUntilHaltOrTwoOutput();
                if (amplifier.IsHalt())
                {
                    break;
                }
                Grid.Move((int)amplifier.Output[0], (int)amplifier.Output[1]);
                amplifier.Output.Clear();
            }

            Grid.PrintAroundCenterWithRadius(50);

            Console.WriteLine(Grid.GetPaintedCount());
        }
Esempio n. 2
0
        public override void Start1()
        {
            var filename  = GetFileName1();
            var amplifier = new Amplifier()
            {
                IntCode = GetLongList_BySeparator(filename, ","),
            };

            var Grid = new Grid(10_000);

            int prevMove = 1;

            while (true)
            {
                //Grid.Print(30);

                //ConsoleKeyInfo _Key = Console.ReadKey();
                //switch (_Key.Key)
                //{
                //    case ConsoleKey.UpArrow:
                //        amplifier.IO.AddLast(1);
                //        move = 1;
                //        break;
                //    case ConsoleKey.DownArrow:
                //        amplifier.IO.AddLast(2);
                //        move = 2;
                //        break;
                //    case ConsoleKey.LeftArrow:
                //        amplifier.IO.AddLast(3);
                //        move = 3;
                //        break;
                //    case ConsoleKey.RightArrow:
                //        amplifier.IO.AddLast(4);
                //        move = 4;
                //        break;
                //    default:
                //        amplifier.IO.AddLast(0);
                //        break;
                //}

                int move = Grid.GetNextMoveByPrev_RightRule(prevMove);
                amplifier.IO.AddLast(move);

                amplifier.WorkUntilHaltOrWaitForInput();
                if (amplifier.IsHalt())
                {
                    break;
                }

                if ((int)amplifier.Output.FindLast(x => true) != 0)
                {
                    prevMove = move;
                }


                Grid.SetLocationAndMove((int)amplifier.Output.FindLast(x => true), move);
            }
        }
Esempio n. 3
0
        public override void Start1()
        {
            var filename  = GetFileName1();
            var amplifier = new Amplifier()
            {
                IntCode = GetLongList_BySeparator(filename, ","),
            };

            while (!amplifier.IsHalt())
            {
                amplifier.WorkUntilHaltOrWaitForInput();
                if (amplifier.IsHalt())
                {
                    break;
                }
            }
            var output = amplifier.Output;
            var screen = new Screen(50);

            for (int i = 0; i < output.Count; i += 3)
            {
                screen.Grid[output[i], output[i + 1]] = output[i + 2];
            }

            long blockTiles = 0;

            foreach (var tile in screen.Grid)
            {
                if (tile == 2)
                {
                    blockTiles++;
                }
            }

            Console.WriteLine(blockTiles);
        }
Esempio n. 4
0
        public override void Start2()
        {
            var filename  = GetFileName1();
            var amplifier = new Amplifier()
            {
                IntCode = GetLongList_BySeparator(filename, ","),
            };

            var Grid = new Grid(10_000);

            int prevMove = 1;

            while (true)
            {
                //Grid.Print(30);


                int move = Grid.GetNextMoveByPrev_RightRule(prevMove);
                amplifier.IO.AddLast(move);

                amplifier.WorkUntilHaltOrWaitForInput();
                if (amplifier.IsHalt())
                {
                    break;
                }

                if ((int)amplifier.Output.FindLast(x => true) != 0)
                {
                    prevMove = move;
                }

                if ((int)amplifier.Output.FindLast(x => true) == 2)
                {
                    Grid.Locations[Grid.CurrentY, Grid.CurrentX] = 2;
                }

                Grid.SetLocationAndMove((int)amplifier.Output.FindLast(x => true), move);
                if (Grid.IsAtStart())
                {
                    break;
                }
            }

            Grid.Print(30);


            Grid.FillOxygen();
        }
Esempio n. 5
0
        public override void Start2()
        {
            var filename  = GetFileName1();
            var amplifier = new Amplifier()
            {
                IntCode = GetLongList_BySeparator(filename, ","),
            };

            amplifier.IntCode[0] = 2;

            var  screen           = new Screen(40);
            int  nextDrawPosition = 0;
            long step             = 0;

            while (true)
            {
                step++;

                if (amplifier.Output.Count > nextDrawPosition)
                {
                    screen.AddMoves(amplifier.Output.GetRange(nextDrawPosition, amplifier.Output.Count - nextDrawPosition));
                    nextDrawPosition = amplifier.Output.Count;
                }
                //ConsoleKeyInfo _Key = Console.ReadKey();
                //switch (_Key.Key)
                //{
                //    case ConsoleKey.RightArrow:
                //        amplifier.IO.AddLast(1);
                //        break;
                //    case ConsoleKey.LeftArrow:
                //        amplifier.IO.AddLast(-1);
                //        break;
                //    default:
                //        amplifier.IO.AddLast(0);
                //        break;
                //}

                long current3X = screen.Get3X();
                long current4X = screen.Get4X();
                if (current4X > current3X)
                {
                    amplifier.IO.AddLast(1);
                }
                else if (current4X < current3X)
                {
                    amplifier.IO.AddLast(-1);
                }
                else
                {
                    amplifier.IO.AddLast(0);
                }

                //if (step % 1 == 0)
                //{
                //    screen.PrintScreen();
                //    Console.ReadKey();
                //}

                amplifier.WorkUntilHaltOrWaitForInput();
                if (amplifier.IsHalt())
                {
                    break;
                }
            }

            Console.Clear();
            Console.WriteLine("Game over");
            Console.WriteLine($"Score = {amplifier.Output.Last()}");
        }