diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java index a9e7c5b6639e8a2a8728809d9b17c8d155baf9b6..af3a73dd8ec812130225751e4b74181d0b3ee693 100644 --- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java +++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.function.Consumer; +import javax.management.RuntimeErrorException; + /** * The state of a dots and boxes grid. * @@ -111,7 +113,10 @@ public class DotsAndBoxesGrid { } // A box is complete if the north and south horizontals and the east and west verticals have all been drawn. - // FIXME: You'll need to fix this code (after writing a test first). + if (!getHorizontal(x,y) || !getVertical(x, y) || + !getHorizontal(x, y + 1) || !getVertical(x + 1, y)) { + return false; + } return true; } @@ -139,7 +144,9 @@ public class DotsAndBoxesGrid { throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height)); } - // FIXME: You need to throw an exception if the line was already drawn. + if (getHorizontal(x, y)) { + throw new RuntimeException(String.format("This horizontal line has already been drawn")); + } this.horizontals[x][y] = true; @@ -170,7 +177,9 @@ public class DotsAndBoxesGrid { throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1)); } - // You need to throw an exception if the line was already drawn. + if (getVertical(x, y)) { + throw new RuntimeException(String.format("This vertical line has already been drawn")); + } this.verticals[x][y] = true; // Try to claim the north or south boxes