Commit 223504b

mo khan <mo@mokhan.ca>
2019-08-05 20:04:26
extract variables to check if robots in cell
1 parent 8f840e9
Changed files (1)
src/Q9/Robot.java
@@ -51,8 +51,11 @@ public class Robot {
     String grid = "";
     for (int row = 0; row < 10; row++) {
       for (int column = 0; column < 10; column++) {
-        if (r1.atPosition(row, column)) grid += "|1";
-        else if (r2.atPosition(row, column)) grid += "|2";
+        boolean r1InCell = r1.atPosition(row, column);
+        boolean r2InCell = r2.atPosition(row, column);
+
+        if (r1InCell) grid += "|1";
+        else if (r2InCell) grid += "|2";
         else grid += "| ";
       }
       grid += String.format("|%s", System.lineSeparator());