public void outputs_and_input_have_equal_dimensions() { List <List <char> > twoGrid = new List <List <char> >(); twoGrid.Add(new List <char> { '.', '.' }); twoGrid.Add(new List <char> { '.', '.' }); GameOfLife gameTwo = new GameOfLife(twoGrid); Assert.That(gameTwo.Play(), Has.Count.EqualTo(twoGrid.Count)); List <List <char> > fourGrid = new List <List <char> >(); fourGrid.Add(new List <char> { '.', '.', '.', '.' }); fourGrid.Add(new List <char> { '.', '.', '.', '.' }); fourGrid.Add(new List <char> { '.', '.', '.', '.' }); fourGrid.Add(new List <char> { '.', '.', '.', '.' }); GameOfLife gameFour = new GameOfLife(fourGrid); Assert.That(gameFour.Play(), Has.Count.EqualTo(fourGrid.Count)); }
public void IfCellHasMoreThanThreeNeighboursItDies() { game = new GameOfLife(3, 3); CreateBlock(0, 0); CreateBlock(1, 1); Assert.IsFalse(game.ShouldSurvive(1, 1)); }
public void ShouldReturnCorrectThirdGenerationGivenSecond() { //check that returned generation is as expected var thirdGen = GameOfLife.GenerateNextGeneration(SecondGen); Assert.Equal(ThirdGen, thirdGen); }
public void CreateSimplestGameOfLifeEverWith1X1() { game = new GameOfLife(1, 1); Assert.AreEqual(0, game.GenerationCount); game.Update(); Assert.AreEqual(1, game.GenerationCount); }
public void ShouldReturnCorrectSecondGenerationGivenFirstNotEqualToWrongOne() { //check that returned generation is NOT as expected var secondGen = GameOfLife.GenerateNextGeneration(FirstGen); Assert.NotEqual(WrongSecondGen, secondGen); }
public void GameLogicAllZombieTest() { int size = 5; GameOfLife target = new GameOfLife(size); CellUpdate[] cellUpdates = new CellUpdate[size * size]; int c = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { cellUpdates[c] = new CellUpdate(i, j, null); c++; } } target.ChangeCellStates(cellUpdates); int?[,] Grid = target.GetGrid(); c = 0; // Reset count for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Assert.AreEqual(null, Grid[i, j], "Failed at " + i + "," + j); c++; } } }
public static void Main(string[] args) { string filename; if (args.Length == 0) { // filename = "init_highlife_replicator.txt"; filename = "init_LWSS.txt"; } else if (args.Length == 1) { filename = args[0]; } else { Console.WriteLine("Too many args!"); return; } GameOfLife GoL = new GameOfLife(filename); GoL.PrintBoard(); for (int i = 0; i < 50; i++) { Console.ReadKey(); GoL.NextTurn(); GoL.PrintBoard(); } Console.WriteLine("That\'s a Wrap!"); }
public void NumberAliveNeighborTest1() { string fields = "..##.\n" + ".....\n" + "###..\n"; Board board = new Board(fields); GameOfLife gol = new GameOfLife(board); Assert.AreEqual(0, gol.NumberAliveNeighbors(0, 0)); // line 1 Assert.AreEqual(1, gol.NumberAliveNeighbors(1, 0)); Assert.AreEqual(1, gol.NumberAliveNeighbors(2, 0)); Assert.AreEqual(1, gol.NumberAliveNeighbors(3, 0)); Assert.AreEqual(1, gol.NumberAliveNeighbors(4, 0)); Assert.AreEqual(2, gol.NumberAliveNeighbors(0, 1)); // line 2 Assert.AreEqual(4, gol.NumberAliveNeighbors(1, 1)); Assert.AreEqual(4, gol.NumberAliveNeighbors(2, 1)); Assert.AreEqual(3, gol.NumberAliveNeighbors(3, 1)); Assert.AreEqual(1, gol.NumberAliveNeighbors(4, 1)); Assert.AreEqual(1, gol.NumberAliveNeighbors(0, 2)); // line 3 Assert.AreEqual(2, gol.NumberAliveNeighbors(1, 2)); Assert.AreEqual(1, gol.NumberAliveNeighbors(2, 2)); Assert.AreEqual(1, gol.NumberAliveNeighbors(3, 2)); Assert.AreEqual(0, gol.NumberAliveNeighbors(4, 2)); }
public void TestDeadCellWithExactlyThreeNeighborsShouldBecomeAlive() { var gol = new GameOfLife(6, 6, new Coord[] { new Coord(1, 2), new Coord(2, 1), new Coord(2, 2) }); int[][] nGen = gol.NextGen(); Assert.AreEqual(1, nGen[0][0], "Dead cell with exactly three neighbors should become alive"); }
static void Main() { int[,] pentadecathlon = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; var game = new GameOfLife(pentadecathlon); while (true) { Console.Clear(); Console.WriteLine(game.ToString()); game.Transition(); Thread.Sleep(1000); } }
public void LoadGame_command_Works() { //arrange using var mock = AutoMock.GetLoose(); mock.Mock <IRules>(); var game = new GameOfLife(new GridSize(5, 5)); mock.Mock <ISaveManager>() .Setup(sm => sm.Load()) .Returns(game); mock.Mock <IPlayerInterface>() .Setup(p => p.GetCommand()) .Returns(MenuCommand.LoadGame); var sut = mock.Create <Menu>(); //act sut.Run(); //assert mock.Mock <IPlayerInterface>().Verify(p => p.GetCommand(), Times.Once); mock.Mock <ISaveManager>().Verify(sm => sm.Load(), Times.Once); }
public void LiveCellWith_MoreThan3Neighbors_Dies(int liveNeighbors) { var currentState = CellState.Alive; CellState newState = GameOfLife.GetNewState(currentState, liveNeighbors); Assert.Equal(CellState.Dead, newState); }
// Debug void OnDrawGizmos() { var dx = Mathf.FloorToInt(size.x * 0.5f); var dy = Mathf.FloorToInt(size.y * 0.5f); GameOfLife.DrawRect(new Rect(-dx, -dy, size.x, size.y), Color.red); }
public void OneCellShouldDisappearAfterOneIteration() { game = new GameOfLife(3, 3); game[1, 1] = true; game.Update(); Assert.IsFalse(game[1, 1]); }
public void IfCellIsNotAliveButHasTwoNeighborsItStayDead() { game = new GameOfLife(2, 2); game[0, 1] = true; game[1, 0] = true; Assert.IsFalse(game.ShouldSurvive(0, 0)); }
public void TestLiveCellWithTwoNeighborsShouldLive() { var gol = new GameOfLife(4, 8, new Coord[] { new Coord(2, 1), new Coord(3, 1), new Coord(3, 2) }); int[][] nGen = gol.NextGen(); Assert.AreEqual(1, nGen[2][0], "Live cell with two neighbors should stay alive"); }
public void ShouldReturnCorrectSecondGenerationGivenFirst() { //check that returned generation is as expected var secondGen = GameOfLife.GenerateNextGeneration(FirstGen); Assert.Equal(SecondGen, secondGen); }
public void ShouldReturnIncorrectNumberOfLiveNeighbors() { //given FirstGen grid, neighbors for [1,3] = 3 var liveNeighbors = GameOfLife.CheckNeighbors(FirstGen, 1, 3); Assert.False(liveNeighbors == 4); }
public static void ReadFrom <TLoc, TState>(this GameOfLife <TLoc, TState> game, AlignedSpace <TLoc, TState> space) { foreach (var(pos, value) in space) { game[pos] = value; } }
public void dead_cell_lives_with_three_neighbours_only() { List <List <char> > reviveGrid = new List <List <char> >(); reviveGrid.Add(new List <char> { '*', '.', '*' }); reviveGrid.Add(new List <char> { '.', '*', '*' }); reviveGrid.Add(new List <char> { '.', '.', '*' }); reviveGrid.Add(new List <char> { '.', '.', '.' }); GameOfLife reviveGame = new GameOfLife(reviveGrid); //Console.WriteLine(reviveGame.currentGrid[2][1]); //Console.WriteLine(reviveGame.LiveSurroundingCells(2,1)); reviveGame.Play(); Assert.AreEqual('.', reviveGame.nextGrid[2][0]); Assert.AreEqual('*', reviveGame.nextGrid[2][1]); Assert.AreEqual('.', reviveGame.nextGrid[1][0]); }
public void counts_the_live_cells_surrounding_a_cell() { List <List <char> > deadThreeGrid = new List <List <char> >(); deadThreeGrid.Add(new List <char> { '.', '.', '.' }); deadThreeGrid.Add(new List <char> { '.', '.', '.' }); deadThreeGrid.Add(new List <char> { '.', '.', '.' }); GameOfLife deadGame = new GameOfLife(deadThreeGrid); Assert.AreEqual(0, deadGame.LiveSurroundingCells(1, 1)); List <List <char> > liveThreeGrid = new List <List <char> >(); liveThreeGrid.Add(new List <char> { '*', '*', '*' }); liveThreeGrid.Add(new List <char> { '*', '*', '*' }); liveThreeGrid.Add(new List <char> { '*', '*', '*' }); GameOfLife liveGame = new GameOfLife(liveThreeGrid); Assert.AreEqual(8, liveGame.LiveSurroundingCells(1, 1)); }
public void Neighbours_GridCellWithNoNeighbours_EmptyCollectionReturned() { var grid = GameOfLife.GetGrid(new bool[4, 4]); IEnumerable <Cell> neighbours = grid.Neighbours(new Cell(2, 2, false)); Assert.That(neighbours.Count, Is.EqualTo(0)); }
public void AnyDeadCellWithExactlyThreeLiveNeighbbors_BecomeAliveOneTick() { Cell cell1 = new Cell(0, 0); Cell cell2 = new Cell(1, 0); Cell cell3 = new Cell(0, 1); List <Cell> gameBoard = new List <Cell>(); gameBoard.Add(cell1); gameBoard.Add(cell2); gameBoard.Add(cell3); GameOfLife game = new GameOfLife(gameBoard); game.Tick(); List <Cell> expected = new List <Cell>(); expected.Add(new Cell(0, 0)); expected.Add(new Cell(1, 0)); expected.Add(new Cell(0, 1)); expected.Add(new Cell(1, 1)); CollectionAssert.AreEquivalent(expected, game.GetBoard()); }
static void Main() { int prevWidth = 0; int prevHeight = 0; GameOfLife game = null; while (true) { int width = Console.WindowWidth; int height = (Console.WindowHeight - 1); if (width != prevWidth || height != prevHeight || game == null) { Console.Clear(); game = new GameOfLife(width, height); game.ViewField(); prevWidth = width; prevHeight = height; } else { game.Refresh(); } } }
public long part_one(string input) { var simulation = new GameOfLife(input.CharPixels().Grid(ch => ch == '#')); simulation.Generations(100); return(simulation.Count); }
public void Play5() { var gameOfLife = new GameOfLife(); var generatedBoards = new List <Board>(); var mockRules = new MockRules(); gameOfLife.NextGeneration += (sender, args) => { generatedBoards.Add(args.Board); }; gameOfLife.Play(2, 2, 2, mockRules, new Tuple <int, int>[] { new Tuple <int, int>(0, 0), new Tuple <int, int>(1, 1) }, 0); Assert.AreEqual(3, generatedBoards.Count); Assert.AreEqual(2, mockRules.NumberOfGenerations); Assert.IsTrue(generatedBoards[0].IsAlive(0, 0)); Assert.IsFalse(generatedBoards[0].IsAlive(1, 0)); Assert.IsFalse(generatedBoards[0].IsAlive(0, 1)); Assert.IsTrue(generatedBoards[0].IsAlive(1, 1)); Assert.IsTrue(generatedBoards[1].IsAlive(0, 0)); Assert.IsTrue(generatedBoards[1].IsAlive(1, 0)); Assert.IsTrue(generatedBoards[1].IsAlive(0, 1)); Assert.IsTrue(generatedBoards[1].IsAlive(1, 1)); Assert.IsFalse(generatedBoards[2].IsAlive(0, 0)); Assert.IsFalse(generatedBoards[2].IsAlive(1, 0)); Assert.IsFalse(generatedBoards[2].IsAlive(0, 1)); Assert.IsFalse(generatedBoards[2].IsAlive(1, 1)); }
public void Count_LivingCells_GetNumberOfLivingNeighbouringCells() { var gameOfLife = new GameOfLife(4, 2); gameOfLife.Board = BoardA; for (var x = 1; x < gameOfLife.BoardSize - 1; x++) { for (var y = 1; y < gameOfLife.BoardSize - 1; y++) { var numberOfLiveNeighbours = gameOfLife.GetLivingNeighbourCellCount(x, y); if (x == 1 && y == 1) { Assert.AreEqual(2, numberOfLiveNeighbours); } else if (x == 1 && y == 2) { Assert.AreEqual(2, numberOfLiveNeighbours); } else if (x == 2 && y == 1) { Assert.AreEqual(3, numberOfLiveNeighbours); } else if (x == 2 && y == 3) { Assert.AreEqual(2, numberOfLiveNeighbours); } } } }
public void Iteration_PopulatedGrid_NextStateCorrect() { // Arrange var size = new Coordinates(5, 5); var coordinatesList = new[] { new Coordinates(2, 1), new Coordinates(2, 2), new Coordinates(2, 3) }; // Act var sut = new GameOfLife(size, coordinatesList); sut.NextGeneration(); // Assert var expectedAliveCells = new[] { new Coordinates(1, 2), new Coordinates(2, 2), new Coordinates(3, 2) }.ToHashSet(); sut.Grid.Cells.Should().HaveCount(3); foreach (var cell in sut.Grid.Cells) { expectedAliveCells.Should().Contain(cell.Coordinates); } }
public void ShouldReturnCorrectNumberOfLiveNeighbors() { // given FirstGen grid, neighbors for [1,2] = 5 var liveNeighbors = GameOfLife.CheckNeighbors(FirstGen, 1, 2); Assert.True(liveNeighbors == 5); }
public void TestAllDead() { GameOfLife.Board = "000\n000\n000".Split('\n'); GameOfLife.NextGen(); CollectionAssert.AreEqual("000\n000\n000".Split('\n'), GameOfLife.Board); }
public void Constructor_InitializeWithSpecifiedSize_Success() { GameOfLife gol = new GameOfLife(20); Assert.True(gol.Size.Width == 20); Assert.True(gol.Size.Height == 20); }
public void Constructor_InitializeWithDefaultSize_Success() { GameOfLife gol = new GameOfLife(); Assert.True(gol.Size.Width == DEFAULT_GRID_SIZE); Assert.True(gol.Size.Height == DEFAULT_GRID_SIZE); }
public void IfCellIsAliveAndHasTwoNeighborsItShouldSurvive() { game = new GameOfLife(2, 2); game[0, 0] = true; game[0, 1] = true; game[1, 0] = true; Assert.IsTrue(game.ShouldSurvive(0, 0)); }
public void IfCellIsNotAliveButHasThreeNeighborsItShouldResurrect() { game = new GameOfLife(2, 2); game[0, 1] = true; game[1, 0] = true; game[1, 1] = true; Assert.IsTrue(game.ShouldSurvive(0, 0)); }
public void BlockShouldStayAlive() { game = new GameOfLife(4, 4); CreateBlock(1, 1); game.Run(); Assert.IsTrue(game[1, 1]); Assert.IsTrue(game[2, 2]); }
public void Constructor_2x2Template_InitializedCorrectly() { GameOfLife gol = new GameOfLife("{\"r\":[{\"c\":[1,0]},{\"c\":[0,1]}]}"); Assert.True(gol.GetCell(0, 0).State == CellState.Live); Assert.True(gol.GetCell(0, 1).State == CellState.Dead); Assert.True(gol.GetCell(1, 0).State == CellState.Dead); Assert.True(gol.GetCell(1, 1).State == CellState.Live); }
public void ThatAdvancingGliderByTwoGenerationsAdvancesGliderToThirdStage() { var game = new GameOfLife(10, 10, Patterns.Glider[0]); CollectionAssert.AreEquivalent(Patterns.Glider[0].ToList(), game.Cells.ToList()); game.AdvanceGeneration(2); CollectionAssert.AreEquivalent(Patterns.Glider[2].ToList(), game.Cells.ToList()); }
public void Constructor_Initialize_AllCellsAreDead() { GameOfLife gol = new GameOfLife(); for (int x = 0; x < DEFAULT_GRID_SIZE; x++) { for (int y = 0; y < DEFAULT_GRID_SIZE; y++) { Assert.True(gol.GetCell(x, y).State == CellState.Dead); } } }
public MainWindowViewModel(ISettings settings, IFileSystemService fileSystemService) { this.settings = settings; this.fileSystemService = fileSystemService; this.gameOfLife = new GameOfLife(this.settings.GridWidth, this.settings.GridHeight); this.gameOfLife.GameHasStagnated += GameOfLifeOnGameHasStagnated; this.gameOfLife.GameGridUpdated += GameOfLifeOnGameGridUpdated; this.ConfigureCommands(); this.ConfigureTimer(); this.SetStatus("Initialized."); }
public void It_should_kill_an_alone_alive_cell() { var initialState = new GameState(); initialState.PutAliveCell(new Position(0,0)); var size = new GameSize(3,3); var game = new GameOfLife(size, initialState); var currentState = game.Next(); Assert.AreEqual(0, currentState.AliveCells()); Assert.AreEqual(CellState.Dead, currentState.GetState(new Position(0,0))); }
public void It_should_keeps_alive_cell_when_there_is_two_neighbors() { var initialState = new GameState(); initialState.PutAliveCell(new Position(0,0)); initialState.PutAliveCell(new Position(1,0)); initialState.PutAliveCell(new Position(0,1)); var size = new GameSize(3,3); var game = new GameOfLife(size, initialState); var currentState = game.Next(); Assert.AreEqual(CellState.Alive, currentState.GetState(new Position(0,0))); }
public void BottomRightCellWithExactly3NeightborsComesToLife() { var grid = new Int32[,] { { 0, 0, 0 }, { 0, 1, 1 }, { 0, 1, 0 } }; var game = new GameOfLife(grid); var actual = game.CheckGrid(); var expected = new Int32[,] { { 0, 0, 0 }, { 0, 1, 1 }, { 0, 1, 1 } }; Assert.That(actual, Is.EqualTo(expected)); }
public void BiggerGridReturnsTheCorrectResult() { var grid = new Int32[,] { { 0, 0, 0, 1, 0 }, { 1, 1, 0, 1, 1 }, { 0, 0, 1, 0, 0 }, { 1, 1, 0, 0, 0 }, { 0, 0, 1, 0, 0 } }; var game = new GameOfLife(grid); var actual = game.CheckGrid(); var expected = new Int32[,] { { 0, 0, 1, 1, 1 }, { 0, 1, 0, 1, 1 }, { 0, 0, 1, 1, 0 }, { 0, 1, 1, 0, 0 }, { 0, 1, 0, 0, 0 } }; Assert.That(actual, Is.EqualTo(expected)); }
public void GetCell_WithValidPositionArgument_ReturnsNonNullCellObject() { GameOfLife gol = new GameOfLife(); Assert.NotNull(gol.GetCell(0, 0)); }
public void Prepare() { game = new GameOfLife(); }
public void Constructor_XbyYTemplate_SizeIsInitializedCorrectly(string templateString, int expectedWidth, int expectedHeight) { GameOfLife gol = new GameOfLife(templateString); Assert.True(gol.Size.Width == expectedWidth); Assert.True(gol.Size.Height == expectedHeight); }
public void InvokeInstance() { game = new GameOfLife(); }
public Cell(float x, float y, Transform transform, GameObject cellFab, GameOfLife world) { // class properties should be used // with 'this' to be accesbile from outside this.x = x; this.y = y; this.parentTransform = transform; this.cellFab = cellFab; this.world=world; if (Random.Range(0f,2f) > 1) { nextState = true; } else { nextState = false; } state = nextState; neighbors = new List<Cell>(); Spawn(); MoveStuff(); }
public void Constructor_XbyXTemplate_SizeIsInitializedAsX(string templateString, int expectedSize) { GameOfLife gol = new GameOfLife(templateString); Assert.True(gol.Size.Width == expectedSize); Assert.True(gol.Size.Height == expectedSize); }
void Start() { gol = new GameOfLife (50); board = createBoard (); addSquare (0, 0); addSquare (0, boardSize-5); addSquare (boardSize-5, boardSize-5); addSquare (boardSize-5, 0); addSquare (23, 23); addSquare (25, 25); addCell(board, 3,5); addCell(board, 3,6); addCell(board, 4,5); addCell(board, 6,7); addCell(board, 6,8); addCell(board, 5,8); addCell(board, 25,5); addCell(board, 25,6); addCell(board, 25,7); addCell(board, 35,30); addCell(board, 35,31); addCell(board, 35,32); addCell(board, 25,40); addCell(board, 25,41); addCell(board, 25,42); addCell(board, 10,10); addCell(board, 11,10); addCell(board, 12,10); addCell(board, 10,11); addCell(board, 12,11); addCell(board, 10,12); addCell(board, 11,12); addCell(board, 12,12); addCell(board, 10,13); addCell(board, 11,13); addCell(board, 12,13); addCell(board, 10,14); addCell(board, 11,14); addCell(board, 12,14); addCell(board, 10,15); addCell(board, 11,15); addCell(board, 12,15); addCell(board, 10,16); addCell(board, 12,16); addCell(board, 10,17); addCell(board, 11,17); addCell(board, 12,17); // glider addGlider (20, 10); addGlider (30, 4); addGlider (40, 15); }
public void Constructor_VariousInitializations_PopulationIsCalculatedCorrectly(string template, int expectedPopulation) { GameOfLife gol = new GameOfLife(template); Assert.Equal(expectedPopulation, gol.Population); }
public void LineShouldAlternate() { game = new GameOfLife(3, 3); CreateVerticalLine(1, 0); Assert.IsTrue(game[1, 0]); Assert.IsFalse(game[0, 1]); game.Update(); Assert.IsFalse(game[1, 0]); Assert.IsTrue(game[0, 1]); Assert.IsTrue(game[1, 1]); Assert.IsTrue(game[2, 1]); }
public void ShowGameOfLife() { game = new GameOfLife(24, 24); game.Randomize(); if (Time.CheckEvery(0.1f)) game.Update(); for (int x = 0; x < game.width; x++) for (int y = 0; y < game.height; y++) { float posX = 0.1f + 0.8f * x / game.width; float posY = 0.1f + 0.8f * y / game.height; Color color = game[x, y] ? Color.White : Color.DarkGray; new Ellipse(Rectangle.FromCenter(posX, posY, 0.025f, 0.025f), color); } }
public void SingleCellShouldNotSurviveAlone() { game = new GameOfLife(3, 3); game[1, 1] = true; Assert.IsFalse(game.ShouldSurvive(1, 1)); }
public void BlockShouldSurviveAlone() { game = new GameOfLife(2, 2); CreateBlock(0, 0); Assert.IsTrue(game.ShouldSurvive(0, 0)); }
public void IfCellIsAliveAndHasThreeNeighborsItShouldSurvive() { game = new GameOfLife(2, 2); CreateBlock(0, 0); Assert.IsTrue(game.ShouldSurvive(0, 0)); }