public void AddLife(int x, int y) { var newLife = new LifeInstance(x, y); if (!AllLife.Add(newLife)) { throw new InvalidOperationException($"Life {newLife} already exists"); } }
public override bool Equals(object obj) { LifeInstance compareInstance = (LifeInstance)obj; if (compareInstance != null && compareInstance.X == X && compareInstance.Y == Y) { return(true); } return(false); }
public int GetNumberOfNeighbours(LifeInstance life) { int numberOfNeighbours = 0; var neighbouringCells = life.GetNeighbouringCells(); foreach (var cell in neighbouringCells) { if (AllLife.Contains(cell)) { numberOfNeighbours++; } } return(numberOfNeighbours); }
public List <LifeInstance> GetNeighbouringCells() { List <LifeInstance> neighbouringCells = new List <LifeInstance>(); for (int deltaX = -1; deltaX < 2; deltaX++) { for (int deltaY = -1; deltaY < 2; deltaY++) { var potentialCell = new LifeInstance(X + deltaX, Y + deltaY); if (!potentialCell.Equals(this)) { neighbouringCells.Add(potentialCell); } } } return(neighbouringCells); }
public void AddLife(LifeInstance life) { AddLife(life.X, life.Y); }