public Grid Update(Grid g) { Grid newgrid = GridFactory.GetGrid(g.Size); for (uint i = 1; i < g.Size - 1; ++i) { for (uint j = 1; j < g.Size - 1; ++j) { int nbAlive = 0; if (g.Cells[i - 1, j - 1].Alive) { nbAlive++; } if (g.Cells[i - 1, j].Alive) { nbAlive++; } if (g.Cells[i - 1, j + 1].Alive) { nbAlive++; } if (g.Cells[i, j - 1].Alive) { nbAlive++; } if (g.Cells[i, j + 1].Alive) { nbAlive++; } if (g.Cells[i + 1, j - 1].Alive) { nbAlive++; } if (g.Cells[i + 1, j].Alive) { nbAlive++; } if (g.Cells[i + 1, j + 1].Alive) { nbAlive++; } if (0 < nbAlive && nbAlive < 3) { newgrid.Cells[i, j] = CellFactory.GetAlive(); } if (nbAlive > 5 || nbAlive == 0) { newgrid.Cells[i, j] = CellFactory.GetDead(); } } } return(newgrid); }
public Grid Init(int Fichier) { var fileName = "InitAlo"; var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), $@"../../Configuration/Initialisation/" + fileName + ".txt"); string[] lines; lines = File.ReadAllLines(path); int Size = 0; foreach (var line in lines) { Size = Size < line.Length ? line.Length : Size; } Size = Size < lines.Length ? lines.Length : Size; Grid g = GridFactory.GetGrid(Size); int i = 0, j = 0; for (var k = 0; k < lines.Length; k++) { for (var l = 0; l < lines[k].Length; l++) { char c = lines[k][l]; if (c == '1') { g.Cells[j, i] = CellFactory.GetAlive(); } else { g.Cells[j, i] = CellFactory.GetDead(); } j++; } i++; j = 0; } return(g); }
public Grid Init(int Size) { Grid g = GridFactory.GetGrid(Size); for (int i = 0; i < g.Size; i++) { for (int j = 0; j < g.Size; j++) { if (j % 2 == 0 && i % 2 == 0) { g.Cells[i, j] = CellFactory.GetAlive(); } else { g.Cells[i, j] = CellFactory.GetDead(); } } } return(g); }
public Grid Init(int Size) { Random rand = new Random(); Grid g = GridFactory.GetGrid(Size); for (int i = 0; i < g.Size; i++) { for (int j = 0; j < g.Size; j++) { if (rand.Next(0, 99) <= rand.Next(0, 99)) { g.Cells[i, j] = CellFactory.GetAlive(); } else { g.Cells[i, j] = CellFactory.GetDead(); } } } return(g); }
public Grid Update(Grid g) { Grid newgrid = GridFactory.GetGrid(g.Size); for (uint i = 1; i < g.Size - 1; ++i) { for (uint j = 1; j < g.Size - 1; ++j) { int nbAlive = 0; if (i != 0 && i != g.Size && j != 0 && j != g.Size) { if (g.Cells[i - 1, j - 1].Alive) { nbAlive++; } if (g.Cells[i - 1, j].Alive) { nbAlive++; } if (g.Cells[i - 1, j + 1].Alive) { nbAlive++; } if (g.Cells[i, j - 1].Alive) { nbAlive++; } if (g.Cells[i, j + 1].Alive) { nbAlive++; } if (g.Cells[i + 1, j - 1].Alive) { nbAlive++; } if (g.Cells[i + 1, j].Alive) { nbAlive++; } if (g.Cells[i + 1, j + 1].Alive) { nbAlive++; } } if (g.Cells[i, j].Alive) { if (nbAlive < 1 || nbAlive > 5) { newgrid.Cells[i, j] = CellFactory.GetDead(); } else { newgrid.Cells[i, j] = CellFactory.GetAlive(); } } else if (nbAlive > 1) { newgrid.Cells[i, j] = CellFactory.GetAlive(); } } } return(newgrid); }