예제 #1
0
        public Game[] Build(string inputFilename)
        {
            var games = new List<Game>();

            var input = new InputReader().Read(inputFilename);

            var board = Board.CreateEmpty(input.height, input.width);
            foreach (var busyCell in input.filled)
            {
                board.Fill(busyCell.ToPoint());
            }

            var units = input.units.Select(x => x.ToUnit()).ToArray();
            foreach (var seed in input.sourceSeeds)
            {
                var generator = new RandomGenerator(seed);
                var unitSequence = generator.Generate().Select(x => units[x % units.Length]).Take(input.sourceLength).ToArray();

                var game = new Game(board, null, unitSequence, 0, 0, 0, input.id, seed, string.Empty, 0);
                game = game.TrySpawnNew();

                games.Add(game);
            }

            return games.ToArray();
        }
예제 #2
0
        public void TestRead()
        {
            var input = new InputReader().Read("testReader.txt");
            var expected = new Input
            {
                height = 10,
                width = 10,
                sourceSeeds = new [] { 0 },
                id = 0,
                filled = new InputCell[0],
                sourceLength = 100,
                units = new[]
                {
                    new InputUnit
                    {
                        pivot = new InputCell { x = 3, y = 4 },
                        members = new[] { new InputCell { x = 1, y = 2} }
                    }
                }
            };

            Console.WriteLine("Actual:");
            Console.WriteLine(Serialize(input));
            Console.WriteLine("Expected:");
            Console.WriteLine(Serialize(expected));

            Assert.AreEqual(Serialize(expected), Serialize(input));
        }