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"); }
private void UpdateBoard(object sender, ElapsedEventArgs elapsedEventArgs) { var stopwatch = new Stopwatch(); stopwatch.Start(); var processAllRules = _rules.ProcessAllRules(_gameMatrix); stopwatch.Stop(); Console.Out.WriteLine("Time " + stopwatch.ElapsedMilliseconds); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action <IEnumerable <Cell> >(OnAction), processAllRules); }
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"); }
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"); }