public Population(Population existingPopulation) { CellList = new List<Cell>(); Rules = existingPopulation.Rules; foreach (Cell thisCell in existingPopulation.CellList) CellList.Add(new Cell(thisCell)); }
public Main(int birthMin, int birthMax, int survivalMin, int survivalMax, int maxIterations, Population pop) { Rules = new Ruleset(birthMin, birthMax, survivalMin, survivalMax); LivingCells = pop; CurrentIteration = 0; MaxIterations = maxIterations; }
//Draw cells private void DrawCells(Population livingCells) { foreach (Cell cell in livingCells.CellList) Gpx.FillRectangle(CellBrush, (cell.XPos * CellSize), (cell.YPos * CellSize), CellSize, CellSize); pix_Grid.Refresh(); }
public void CheckForDuplicates() { Population tempPop = new Population(this); foreach (Cell thisCell in tempPop.CellList) { if (thisCell.CheckNumberDuplicates(tempPop.CellList) > 1) { this.RemoveCell(thisCell); tempPop.Nullify(thisCell); } } }
//True = keep iterating, False = stop iterating public bool Iterate() { LivingCells = new Population(LivingCells.Run(Rules)); LivingCells.CheckForDuplicates(); LivingCells.UpdateCellCount(); UpdateGridEvent(this, EventArgs.Empty); CurrentIteration++; if (CurrentIteration >= MaxIterations && MaxIterations != 0) { CurrentIteration = 0; return false; } else return true; }
public Population Run(Ruleset rules) { Population tempPop = new Population(this); for (int index = 0; index < CellList.Count; index++) { if (!Survive(CellList[index], rules)) tempPop.RemoveCell(CellList[index]); } tempPop.UpdateCellCount(); Reproduction(tempPop); return tempPop; }
public Main(int birthMin, int birthMax, int survivalMin, int survivalMax, int maxIterations) { Rules = new Ruleset(birthMin, birthMax, survivalMin, survivalMax); LivingCells = new Population(Rules); CurrentIteration = 0; }
private bool CheckReproduction(Population currentPop, Cell thisCell) { thisCell.CountNeighbors(currentPop.CellList); if (thisCell.NeighborCount >= Rules.BirthMinimum && thisCell.NeighborCount <= Rules.BirthMaximum) return true; return false; }
private void Reproduction(Population tempPopulation) { foreach (Cell thisCell in this.CellList) tempPopulation.CellList.AddRange(tempPopulation.MakeNewCells(this, thisCell).CellList); }
private Population MakeNewCells(Population currentPop, Cell thisCell) { Population spawn = new Population(this.Rules); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (CheckReproduction(currentPop, new Cell(thisCell.XPos + x, thisCell.YPos + y))) spawn.AddCell(new Cell(thisCell.XPos + x, thisCell.YPos + y)); } } return spawn; }