Пример #1
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()}");
        }