Skip to content

Commit

Permalink
Update LightBoard.java
Browse files Browse the repository at this point in the history
  • Loading branch information
dialtamirano authored Apr 29, 2024
1 parent 14a3ce0 commit 26dc2ab
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main/java/LightBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ 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 rnd = Math.random();
lights[r][c] = rnd < 0.4;
}
}
}

/** Evaluates a light in row index row and column index col and returns a status
Expand All @@ -21,8 +27,19 @@ public LightBoard(int numRows, int numCols)
public boolean evaluateLight(int row, int col)
{
/* to be implemented in part (b) */


int numOn = 0;
for(int r = 0; r < lights.length; r++){
if(lights[r][col]){
numOn++;
}
if(lights[row][col] && numOn %2 == 0){
return false;
}
if(!lights[row][col] && numOn % 3 == 0){
return true;
}
}
return lights[row][col];
}
public boolean[][] getLights()
{
Expand Down

0 comments on commit 26dc2ab

Please sign in to comment.