Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var inputState = new[, ]
            {
                { State.Dead, State.Dead, State.Dead, State.Dead, State.Dead },
                { State.Dead, State.Dead, State.Alive, State.Dead, State.Dead },
                { State.Dead, State.Dead, State.Alive, State.Dead, State.Dead },
                { State.Dead, State.Dead, State.Alive, State.Dead, State.Dead },
                { State.Dead, State.Dead, State.Dead, State.Dead, State.Dead },
            };
            var world        = new WrappingSquareWorld(5, 5);
            var initialState = world.CreateState(inputState);
            var game         = new Game(world, initialState);

            while (true)
            {
                game.Tick();
                System.Console.Clear();
                foreach (var row in Enumerable.Range(0, 5))
                {
                    foreach (var column in Enumerable.Range(0, 5))
                    {
                        Cell cell  = world.GetCell(row, column);
                        var  state = game.GetState(cell);
                        System.Console.Write("{0} ", state == State.Alive? "[#]": "[ ]");
                    }
                    System.Console.WriteLine("");
                }
                Thread.Sleep(500);
            }
        }
        public void GivenAThreeByThreeWorld_WhenWorldCellsAreRetrieved_ThenNineAreReturned()
        {
            var world = new WrappingSquareWorld(3, 3);
            var cells = world.WorldCells;

            Assert.AreEqual(9, cells.Count());
        }
        public void GivenAThreeByThreeWorld_WhenEachCellAsksForSiblings_ThenEachSiblingIsUnique()
        {
            var world = new WrappingSquareWorld(3, 3);

            foreach (var cell in world.WorldCells)
            {
                var neighbours = world.GetNeighbours(cell).ToList();
                Assert.AreEqual(neighbours.Count(), neighbours.Distinct().Count());
            }
        }
        public void GivenAThreeByThreeWorld_WhenEachCellAsksForSiblings_ThenItselfIsNotReturned()
        {
            var world = new WrappingSquareWorld(3, 3);

            foreach (var cell in world.WorldCells)
            {
                var siblings = world.GetNeighbours(cell).ToList();
                CollectionAssert.DoesNotContain(siblings, cell);
            }
        }
        public void GivenAThreeByThreeWorld_WhenEachCellAsksForSiblings_ThenEightSiblingsReturned()
        {
            var world = new WrappingSquareWorld(3, 3);

            foreach (var cell in world.WorldCells)
            {
                var siblings = world.GetNeighbours(cell);
                Assert.AreEqual(8, siblings.Count());
            }
        }
Ejemplo n.º 6
0
        private static void SquareWorldInputOutputTest(State[,] inputStates, State[,] expectedStates)
        {
            var world = new WrappingSquareWorld(5, 5);

            var state = world.CreateState(inputStates);

            var nextState = Game.GetNextState(world, state);

            foreach (var row in Enumerable.Range(0, expectedStates.Rank))
            {
                foreach (var column in Enumerable.Range(0, expectedStates.GetLength(row)))
                {
                    var expectedState = expectedStates[row, column];

                    Assert.AreEqual(expectedState, nextState.GetState(world.GetCell(row, column)));
                }
            }
        }
        public void GivenAThreeByThreeWorldIsRequired_WhenAThreeByThreeWorldIsConstructed_ThenSucceeds()
        {
            var world = new WrappingSquareWorld(3, 3);

            Assert.IsNotNull(world);
        }