 }
 
 bool isSwitchOn(int row, int col) {
+  if (!isValid(row, col)) {
+    return false;
+  }
   return getSwitchValue(row, col) == SWITCH_ON;
 }
 

    col += dc;
  }
  return count;
}

int illuminationCount(int row, int col) {

bool update() {
  bool anyInvalid = false;
  bool anyEmpty = false;
  bool anyWallConstrainsViolated = false;
  for (int index = 0; index < GRIDSIZE * GRIDSIZE; index++) {
    int row = getRow(index);
    int col = getCol(index);
