diff --git a/src/main/java/LightBoard.java b/src/main/java/LightBoard.java index 83df049..16a3e32 100644 --- a/src/main/java/LightBoard.java +++ b/src/main/java/LightBoard.java @@ -1,3 +1,4 @@ + public class LightBoard { /** The lights on the board, where true represents on and false represents off. @@ -10,7 +11,16 @@ public class LightBoard */ public LightBoard(int numRows, int numCols) { - /* to be implemented in part (a) */ + lights = new boolean[numRows][numCols]; + for(int r = 0; r < numRows; r++){ + for(int c = 0; c < numCols; c++){ + double onOrOff = Math.random(); + if(onOrOff < 0.4) + lights[r][c] = true; + else + lights[r][c] = false; + } + } } @@ -20,10 +30,20 @@ public LightBoard(int numRows, int numCols) */ public boolean evaluateLight(int row, int col) { - /* to be implemented in part (b) */ + int count = 0; + for(int i = 0; i < lights.length; i++){ + if(lights[i][col] == true) + count++; + } + if(lights[row][col] == true && count%2 == 0) + return false; + if(lights[row][col] == false && count%3 == 0) + return true; + return lights[row][col]; + } - } + public boolean[][] getLights() { return lights;