/// <summary> /// Creates a new <see cref="Cell"/> instance using its location and state from an environment. /// </summary> /// <param name="location">The location of the state to be created.</param> /// <param name="environment">It is used to get the <see cref="Cell"/>`s state.</param> /// <returns>The initialized <see cref="Cell"/> object.</returns> public static Cell Create(Point location, CAEnvironment environment) { var c = new Cell(location); var key = c.GetKey(); if (environment.States.Contains(key)) { c.State = true; } return c; }
public bool CanBeActivated(Cell currentCell, CellCollection neighbours) { IEnumerator<Cell> enumerator = neighbours.GetEnumerator(); byte currentCase = 0; int index = neighbours.Count - 1; while (enumerator.MoveNext()) { if (enumerator.Current.State) { currentCase += (byte) Math.Pow(2, index); } index--; } return _rule[currentCase]; }
public bool CanBeActivated(Cell currentCell, CellCollection neighbours) { short count = 0; IEnumerator<Cell> enumerator = neighbours.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.State) { count++; } } if (count == 3) { return true; } if (count == 2 && currentCell.State) { return true; } return false; }
/// <summary> /// Gets and sets the new <see cref="Cell.State"/> of particular <see cref="Cell"/>. /// </summary> /// <param name="cell">The <see cref="Cell"/>, which <see cref="Cell.State"/> is pregenerated.</param> public bool SetCellState(Cell cell) { long key = cell.GetKey(); if (_rule.CanBeActivated(cell, _neighbourhood.GetNeighbours(cell.Location, this))) { cell.State = true; if (!StatesNew.Contains(key)) { StatesNew.Add(key); } } else { cell.State = false; if (StatesNew.Contains(key)) { StatesNew.Remove(key); } } return cell.State; }