コード例 #1
0
ファイル: Day09.cs プロジェクト: Narvius/Advent-of-Code
        // Run program with input 1.
        public string PartOne(string[] lines)
        {
            var c = new CPU(lines[0], 10000);

            c.Input.Enqueue(1);
            c.RunWhilePossible();
            return(c.Output.Dequeue().ToString());
        }
コード例 #2
0
ファイル: Day13.cs プロジェクト: Narvius/Advent-of-Code
        // Win the game and report the resulting score.
        public string PartTwo(string[] lines)
        {
            var cpu = new CPU(lines[0], 10000);

            cpu.OverwriteMemoryAt(0, 2);

            return(RunGameLoop(cpu).ToString());
        }
コード例 #3
0
ファイル: Day13.cs プロジェクト: Narvius/Advent-of-Code
        // Wins the game and returns the score.
        private int RunGameLoop(CPU cpu)
        {
            var paddleState = (x : 0, y : 0);
            var ballState   = (x : 0, y : 0);
            var score       = 0;

            while (cpu.State != CPU.ExecutionState.Halted)
            {
                cpu.RunWhilePossible();
                UpdateGameState(cpu, ref score, ref paddleState, ref ballState);
                cpu.Input.Enqueue(Math.Sign(ballState.x - paddleState.x));
            }

            return(score);
        }
コード例 #4
0
ファイル: Day13.cs プロジェクト: Narvius/Advent-of-Code
        // Run the program and count how many breakable blocks (code 2) it printed.
        public string PartOne(string[] lines)
        {
            var cpu = new CPU(lines[0], 10000);

            cpu.RunWhilePossible();

            int result = 0;

            while (cpu.Output.Count > 0)
            {
                cpu.Output.Dequeue();
                cpu.Output.Dequeue();
                if (cpu.Output.Dequeue() == 2)
                {
                    result++;
                }
            }

            return(result.ToString());
        }
コード例 #5
0
ファイル: Day13.cs プロジェクト: Narvius/Advent-of-Code
 // Reads all the output of the CPU and updates the relevant game state as necessary.
 private void UpdateGameState(CPU cpu, ref int score, ref (int x, int y) paddle, ref (int x, int y) ball)