protected bool DoesCellLive(int X, int Y, LifeGrid grid) { bool result = grid.DoesCellLive(X, Y); if (fOnDoesCellLive != null) { fOnDoesCellLive(this, X, Y, grid, ref result); } return(result); }
public LifeViewer() { DoubleBuffered = true; fOptions = new LifeOptions(); fRules = new LifeRules(); fGrid = new LifeGrid(LifeConsts.DefaultGridWidth, LifeConsts.DefaultGridHeight); fHistory = new LifeHistory(LifeConsts.DefaultNumberOfHistoryLevels); fGridLineColor = LifeConsts.DefaultGridLineColor; fGridLineStyle = LifeConsts.DefaultGridLineStyle; }
public int Contains(LifeGrid grid) { int result = 0; while ((result < fList.Count) && !grid.Equals(this[result])) { result++; } if (result >= fList.Count) { result = -1; } return(result); }
public LifeGrid Add(LifeGrid grid) { if (fList.Count < fList.Capacity) { fList.Add(new LifeGrid()); fMostRecent = fList.Count - 1; } else { fMostRecent = (fMostRecent + 1) % Count; } LifeGrid result = fList[fMostRecent]; result.Assign(grid); return(result); }
public int NextGeneration() { LifeGrid MostRecentGrid = fHistory.Add(fGrid); for (int y = 0; y < GridHeight; y++) { for (int x = 0; x < GridWidth; x++) { bool live = DoesCellLive(x, y, MostRecentGrid); SetCell(x, y, (short)((live) ? 1 : 0)); } } fGeneration++; Change(); int result = fHistory.Contains(fGrid) + 1; return(result); }