Exemplo n.º 1
0
        public void ProcessAllRules_AnyLiveCellWithFewerThanTwoLiveNeighboursDies_IsDead()
        {
            var processRules = new ProcessRules(new Rule().Live().CellWithFewerThan(2).Neighbours().Dies());
            var gameMatrix   = new GameMatrix(6, 6).Activate(new [] { new Point(2, 3) });

            Assert.That(gameMatrix[2, 3].IsOn, "Initialized Correctly");
            processRules.ProcessAllRules(gameMatrix);
            Assert.That(gameMatrix[2, 3].IsOn, Is.False, "It dies was removed");
        }
Exemplo n.º 2
0
        public void ProcessAllRules_DefaultRules_ShouldBeValid()
        {
            var processRules = ProcessRules.DefaultRules();
            var gameMatrix   = new GameMatrix(6, 6).Activate(new[] { new Point(2, 3) });

            Assert.That(gameMatrix[2, 3].IsOn, "Initialized Correctly");
            processRules.ProcessAllRules(gameMatrix);
            Assert.That(gameMatrix[2, 3].IsOn, Is.False, "It dies was removed");
        }
Exemplo n.º 3
0
        public void ProcessAllRules_AnyDeadCellWithExactlyThreeLiveNeighbours_BecomesLiveCell()
        {
            var processRules = new ProcessRules(new Rule().Dead().CellWithExactly(3).Neighbours().Lives());
            var activate     = new[] { new Point(2, 2), new Point(3, 3), new Point(2, 4) };
            var gameMatrix   = new GameMatrix(6, 6).Activate(activate);

            var processAllRules = processRules.ProcessAllRules(gameMatrix);
            var shouldBeActive  = new[] { new Point(2, 2), new Point(2, 3), new Point(2, 4), new Point(3, 3) };

            Assert.That(processAllRules.Count, Is.EqualTo(1), "Changes");
            Assert.That(gameMatrix.GetCells(shouldBeActive).IsAllAlive(), "All Points are alive");
        }
Exemplo n.º 4
0
        public void ProcessAllRules_AnyLiveCellWithTwoLiveNeighbours_ShouldLiveOn()
        {
            var processRules = new ProcessRules(
                new Rule().Live().CellWithTwoOrThree().Neighbours().Lives());
            var activate   = new[] { new Point(2, 2), new Point(2, 3), new Point(3, 2), new Point(3, 3) };
            var gameMatrix = new GameMatrix(6, 6).Activate(activate);

            var processAllRules = processRules.ProcessAllRules(gameMatrix);
            var shouldBeActive  = new[] { new Point(2, 2), new Point(2, 3), new Point(3, 2), new Point(3, 3) };

            Assert.That(processAllRules.Count, Is.EqualTo(4), "Changes");
            Assert.That(gameMatrix.GetCells(shouldBeActive).IsAllAlive(), "All Points are alive");
        }
        public MainWindow()
        {
            InitializeComponent();
            _gameMatrix = new GameMatrix(40, 40);
            _rules      = ProcessRules.DefaultRules();
            _timer      = new Timer
            {
                Interval = TimeSpan.FromSeconds(.5).TotalMilliseconds,
            };
            _timer.Elapsed += UpdateBoard;
            _gameMatrix.Activate(_gameMatrix.RandomPoints().Take((_gameMatrix.Height * _gameMatrix.Width) / 2).ToArray());

            Loaded += OnLoaded;

            const byte i = 241;

            _colorOff = new SolidColorBrush(new Color {
                A = 255, R = i, B = i, G = i
            });
            _colorOn = new SolidColorBrush(Colors.Gray);
        }