Beispiel #1
0
            public void Should_return_true_when_simulation_changes_field(
                string[] input, bool expected)
            {
                var sim = new SeatingOfLife {
                    Field = input.Select(s => s.ToArray()).ToArray()
                };

                var changed = sim.Simulate();

                Assert.Equal(expected, changed);
            }
Beispiel #2
0
            public void Should_return_false_when_simulating_a_stable_field(string[] input, bool _)
            {
                var sim = new SeatingOfLife {
                    Field = input.Select(s => s.ToArray()).ToArray()
                };

                var changed = sim.Simulate();

                Assert.False(changed);
                var occupiedCount = sim.Field.SelectMany(x => x).Count(x => x == '#');

                Assert.Equal(37, occupiedCount);
            }
Beispiel #3
0
            public void Should_set_all_free_seats_having_less_than_4_occupied_adjacent_neighbours_to_occupied(
                string[] input,
                string[] expected)
            {
                var sim = new SeatingOfLife {
                    Field = input.Select(s => s.ToArray()).ToArray()
                };

                sim.Simulate();

                var expectedField = expected.Select(s => s.ToArray()).ToArray();

                Assert.Equal(expectedField, sim.Field);
            }
Beispiel #4
0
            public void Puzzle_11A()
            {
                var sim = new SeatingOfLife {
                    Field = PuzzleInputs.Puzzle11.Select(s => s.ToArray()).ToArray()
                };

                while (sim.Simulate())
                {
                }

                var occupiedCount = sim.Field.SelectMany(x => x).Count(x => x == '#');

                Assert.Equal(2338, occupiedCount);
            }
Beispiel #5
0
            public void Example_1(string[] input, bool _)
            {
                var sim = new SeatingOfLife {
                    Field = input.Select(s => s.ToArray()).ToArray()
                };

                while (sim.Simulate())
                {
                }

                var occupiedCount = sim.Field.SelectMany(x => x).Count(x => x == '#');

                Assert.Equal(37, occupiedCount);
            }
Beispiel #6
0
            public void Puzzle_11B()
            {
                var sim = new SeatingOfLife
                {
                    Field = PuzzleInputs.Puzzle11.Select(s => s.ToArray()).ToArray(),
                    Rules = { CrowdedLimit = 5, ExtendedReach = true }
                };

                while (sim.Simulate())
                {
                }

                var occupiedCount = sim.Field.SelectMany(x => x).Count(x => x == '#');

                Assert.Equal(2134, occupiedCount);
            }
Beispiel #7
0
            public void Example_2(params string[] input)
            {
                var sim = new SeatingOfLife
                {
                    Field = input.Select(s => s.ToArray()).ToArray(),
                    Rules =
                    {
                        CrowdedLimit  = 5,
                        ExtendedReach = true
                    }
                };

                while (sim.Simulate())
                {
                }

                var occupiedCount = sim.Field.SelectMany(x => x).Count(x => x == '#');

                Assert.Equal(26, occupiedCount);
            }
Beispiel #8
0
        static void Main(string[] args)
        {
            var sim = new SeatingOfLife
            {
                Field = Data.Select(s => s.ToArray()).ToArray(),
                Rules = new SimulationRules
                {
                    CrowdedLimit  = 4,
                    ExtendedReach = false
                }
            };

            Console.WriteLine("Advent of Code 2020.11.B");

            var handler = GetConsoleHandle();

            var run = true;

            Console.WriteLine("Press enter to start.");
            Console.ReadLine();

            using (var graphics = Graphics.FromHwnd(handler))
            {
                var i = 0;
                while (run)
                {
                    UpdateBitmap(sim.Field);
                    _bitmap.Save($"output/gen{i}.png", ImageFormat.Png);

                    graphics.DrawImage(_bitmap, 210, 0, 98, 93);
                    run = sim.Simulate();
                    i++;
                }

                _bitmap.Dispose();
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }