public void GetLifeCellWithInvalidIndexShouldThrowException() { var lifeBoard = new LifeBoard(3, 3); var cell = lifeBoard[3, 3]; Assert.Fail(); }
public void ToggleLifeBoardCellWithInvalidIndexShouldThrowException() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(-1, 0); Assert.Fail(); }
public void AliveCellWithMoreThan3NeighboursShouldBeDead() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 0); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(0, 2); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ToggleCell(2, 0); lifeBoard.ToggleCell(2, 1); lifeBoard.ToggleCell(2, 2); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[0, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 1].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 2].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[2, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }
private static void Main(string[] args) { var totalGen = 50; var rows = 31; var columns = 31; var lifeBoard = new LifeBoard(rows, columns); for (int i = 0; i < rows; i++) { lifeBoard.ToggleCell(i, 15); for (int j = 0; j < columns; j++) { lifeBoard.ToggleCell(15, j); } } var done = false; while (!done) { PrintCells(lifeBoard); lifeBoard.ProcessNext(); var key = System.Console.ReadLine(); if (key == "e" || key == "E") { done = true; } } }
private static async Task CreateNewGame() { LifeBoard lifeBoard = GetLifeBoard(); Rules rules = GetRules(); await CreateGame(rules, lifeBoard).ConfigureAwait(false); }
public void InitializeBoardSuccess() { var lifeBoard = new LifeBoard(9, 9); Assert.That(9, Is.EqualTo(lifeBoard.Rows)); Assert.That(9, Is.EqualTo(lifeBoard.Columns)); Assert.That(81, Is.EqualTo(lifeBoard.CellsCount)); }
public void DeadCellShouldBeAliveWhenToggle() { var lifeBoard = new LifeBoard(10, 10); Assert.That(false, Is.EqualTo(lifeBoard[5, 5].IsAlive)); lifeBoard.ToggleCell(5, 5); Assert.That(true, Is.EqualTo(lifeBoard[5, 5].IsAlive)); }
// Start is called before the first frame update void Start() { moneyBoard = FindObjectOfType <MoneyBoard>(); lifeBoard = FindObjectOfType <LifeBoard>(); Pathfinder pathfinder = FindObjectOfType <Pathfinder>(); List <Waypoint> path = pathfinder.GetPath(); StartCoroutine(FollowPath(path)); }
private static void PrintCells(LifeBoard lifeBoard) { System.Console.WriteLine("Generation : {0} ", lifeBoard.Generation); System.Console.WriteLine(); for (int x = 0; x < lifeBoard.Rows; x++) { for (int y = 0; y < lifeBoard.Columns; y++) { System.Console.Write("{0} ", lifeBoard[x, y].IsAlive ? charAliveCell.ToString(CultureInfo.InvariantCulture) : "-"); } System.Console.WriteLine(); } System.Console.WriteLine(); System.Console.WriteLine(@"Press any key to Continue or Enter ""e|E"" to exit"); }
public void AliveCellWith2Or3NeiboursShouldBeAliveInNextGeneration() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }
public void DeadCellWithExact3AliveNeiboursShouldBecomeAlive() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ToggleCell(2, 1); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }
public void ShouldCountNumberOfAliveNeiboursCorrectly() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 0); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(0, 2); Assert.AreEqual(1, lifeBoard.CountAliveNeighbours(0, 0)); Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(0, 1)); Assert.AreEqual(1, lifeBoard.CountAliveNeighbours(0, 2)); Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(1, 0)); Assert.AreEqual(3, lifeBoard.CountAliveNeighbours(1, 1)); Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(1, 2)); Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 0)); Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 1)); Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 2)); }
private void Start() { LifeBoard lifeBoard = SelectedFactory?.Create(); Rules rules = new Rules(RuleDescription); if (_gameService.CurrentGame != null) { bool continueCreation = _interactivityService.Ask("Start", "A game is currently open. Do you want to proceed?"); if (!continueCreation) { RaiseCanceled(); return; } } _gameService.Start(rules, lifeBoard); RaiseStarted(); }
private static async Task CreateGameFromParameters(Options options) { if (options.GameFilePath != null) { await LoadGame(options.GameFilePath).ConfigureAwait(false); } else { List <Position> alivePositions = new List <Position>(); for (int i = 0; i < (options.AlivePositions.Length - 1); i += 2) { alivePositions.Add(new Position(options.AlivePositions[i], options.AlivePositions[i + 1])); } if (Rules.IsValid(options.Rules)) { Rules rules = new Rules(options.Rules); LifeBoard lifeBoard = null; switch (options.Board) { case Options.BoardType.Toroid: lifeBoard = ToroidLifeBoard.Create(options.Width, options.Height, alivePositions); break; case Options.BoardType.Cuboid: lifeBoard = CuboidLifeBoard.Create(options.Width, options.Height, options.Depth, alivePositions); break; } if (lifeBoard != null) { await CreateGame(rules, lifeBoard); } } } }
public void Given_the_following_Setup(string[][] table) { _board = new LifeBoard(TransformTableToBooleans(table)); }
private static async Task CreateGame(Rules rules, LifeBoard lifeBoard) { Game game = new Game(rules, lifeBoard); await StartGame(game).ConfigureAwait(false); }
void Start() { lifeBoard = FindObjectOfType <LifeBoard>(); }
/// <summary> /// Starts a game with the given rules on the given life board. /// </summary> /// <param name="rules">The rules.</param> /// <param name="lifeBoard">The life board.</param> public void Start(Rules rules, LifeBoard lifeBoard) { CurrentGame = new Game(rules, lifeBoard); }
public void InitiateLifeBoardWithZeroShouldThrowException() { var lifeBoard = new LifeBoard(0, 0); Assert.Fail(); }