예제 #1
0
        static void Main(string[] args)
        {
            var lines = System.IO.File.ReadAllLines("input.txt");
            var tiles = new Dictionary <HexCo, bool>();

            foreach (var line in lines)
            {
                var hex = HexCo.GoPath(line);
                if (!tiles.ContainsKey(hex))
                {
                    tiles[hex] = true;
                }
                else
                {
                    tiles[hex] = !tiles[hex];
                }
            }

            var game = new GameOfTiles(tiles);

            Console.WriteLine($"Initial state: {game.CountBlack()}");
            for (int i = 0; i < 100; i++)
            {
                game.NextGen();
                Console.WriteLine($"{i} - {game.CountBlack()}");
            }
        }
예제 #2
0
        public void NextGen()
        {
            var nextgen = new Dictionary <HexCo, bool>();

            var minx = tiles.Where(_ => _.Value).Min(c => c.Key.X) - 1;
            var miny = tiles.Where(_ => _.Value).Min(c => c.Key.Y) - 1;
            var maxx = tiles.Where(_ => _.Value).Max(c => c.Key.X) + 1;
            var maxy = tiles.Where(_ => _.Value).Max(c => c.Key.Y) + 1;

            for (var x = minx; x <= maxx; x++)
            {
                for (var y = miny; y <= maxy; y++)
                {
                    var tile    = new HexCo(x, y);
                    var isBlack = tiles.ContainsKey(tile) && tiles[tile];

                    var count = tile.Neighbors().Count(next => tiles.ContainsKey(next) && tiles[next]);

                    if (isBlack)
                    {
                        if (count == 0 || count > 2)
                        {
                            nextgen[tile] = false;
                        }
                        else
                        {
                            nextgen[tile] = true;
                        }
                    }
                    else    // white
                    {
                        if (count == 2)
                        {
                            nextgen[tile] = true;
                        }
                        else
                        {
                            nextgen[tile] = false;
                        }
                    }
                }
            }
            this.tiles = nextgen;
        }
예제 #3
0
 protected bool Equals(HexCo other)
 {
     return(X == other.X && Y == other.Y);
 }