public GameOfLife(int width, int height, int initPercentage, GameRule rule) { matrix = new BinaryMatrix (width, height, initPercentage); Generations = 0; rules = rule; Active = true; }
public bool Equals(BinaryMatrix matrix) { if (this.Width != matrix.Width || this.Height != matrix.Height) return false; bool equals = true; for (int i = 0; i < this.Width; i++) { for (int j = 0; j < this.Height; j++) { equals = this.entries [i, j] == matrix.entries [i, j]; if (!equals) return false; } } return equals; }
private int GetNeighborCount(BinaryMatrix m, int row, int col) { int neighbors = 0; //Top left, top, top right, left, right, bottom left, bottom, bottom right if (row > 0 && col > 0 && m.GetElement (row - 1, col - 1)) neighbors++; if (row > 0 && m.GetElement (row - 1, col)) neighbors++; if (row > 0 && col < m.Width - 1 && m.GetElement (row - 1, col + 1)) neighbors++; if (col > 0 && m.GetElement (row, col - 1)) neighbors++; if (col < m.Width - 1 && m.GetElement (row, col + 1)) neighbors++; if (row < m.Height - 1 && col > 0 && m.GetElement (row + 1, col - 1)) neighbors++; if (row < m.Height - 1 && m.GetElement (row + 1, col)) neighbors++; if (row < m.Height - 1 && col < m.Width - 1 && m.GetElement (row + 1, col + 1)) neighbors++; return neighbors; }