Skip to content

Commit

Permalink
Update LightBoard.java
Browse files Browse the repository at this point in the history
  • Loading branch information
breadsticker1 authored Apr 30, 2024
1 parent daf2167 commit f578dbc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/LightBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ 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++)
for(int r = 0; r < numRows; r++){
for(int c = 0; c < numCols; c++){
double rand = Math.random();
lights[r][c] = rand < 0.4;

}
}
}

/** Evaluates a light in row index row and column index col and returns a status
Expand All @@ -28,13 +29,16 @@ public boolean evaluateLight(int row, int col)
/* to be implemented in part (b) */
int count = 0;
for(int r = 0; r < lights.length; r++){
if(lights[r][col])
if(lights[r][col]){
count++;
}
}
if(lights[row][col] && count%2 == 0)
if(lights[row][col] && count%2 == 0){
return false;
if(!lights[row][col] && count%3 == 0)
}
if(!lights[row][col] && count%3 == 0){
return true;
}
return lights[row][col];
}
public boolean[][] getLights()
Expand Down

0 comments on commit f578dbc

Please sign in to comment.