Skip to content

Commit

Permalink
Update LightBoard.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Dannylui58 authored Apr 30, 2024
1 parent 533e714 commit ce8f4c5
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/LightBoard.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

public class LightBoard
{
/** The lights on the board, where true represents on and false represents off.
Expand All @@ -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;
}
}

}

Expand All @@ -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;
Expand Down

0 comments on commit ce8f4c5

Please sign in to comment.