From 69ad4c9abbeab095b20f9f2d91e3ebd7c52f134a Mon Sep 17 00:00:00 2001 From: MSAYIF Bassem <bassem.msayif@etu.univ-amu.fr> Date: Mon, 28 Sep 2020 19:23:44 +0200 Subject: [PATCH] Updated Grid Class -Implemented nextGeneration(), clear() and randomGeneration(Random random) methods. --- tp3/Grid.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tp3/Grid.java b/tp3/Grid.java index 22ca2a6..781db12 100644 --- a/tp3/Grid.java +++ b/tp3/Grid.java @@ -149,7 +149,11 @@ public class Grid implements Iterable<Cell> { * Sets all {@link Cell}s in this {@code Grid} as dead. */ void clear() { - + for (int i = 0; i < this.numberOfRows; i++) { + for (int j = 0; j < this.numberOfColumns; j++) { + cells[i][j].setDead(); + } + } } /** @@ -158,9 +162,15 @@ public class Grid implements Iterable<Cell> { * @param random {@link Random} instance used to decide if each {@link Cell} is alive or dead * @throws NullPointerException if {@code random} is {@code null} */ - - void randomGeneration(Random random) { + void randomGeneration(Random random) { + for (int i = 0; i < getNumberOfRows(); i++) { + for (int j = 0; j < getNumberOfColumns(); j++) { + if(random.nextBoolean()){ + cells[i][j].setAlive(); + } + } + } } } -- GitLab