From 365c2cd0d194e2dadc04574c7ab025e9a61ea9fd Mon Sep 17 00:00:00 2001 From: Javed Ali <jali6@myune.edu.au> Date: Sat, 9 Sep 2023 18:20:43 +1000 Subject: [PATCH] the bug was fixed and the unit tests were passed --- src/main/java/dotsandboxes/DotsAndBoxesGrid.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java index a9e7c5b..ded636d 100644 --- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java +++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java @@ -112,9 +112,14 @@ 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). - return true; + if (getHorizontal(0, 0) && getHorizontal(0, 1) && getVertical(0, 0) && getVertical(1, 0)) { + return true; + } + else + return false; } + /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */ private boolean claimBox(int x, int y, int p) { if (boxComplete(x, y)) { @@ -140,6 +145,7 @@ public class DotsAndBoxesGrid { } // FIXME: You need to throw an exception if the line was already drawn. + if (getHorizontal(x, y)) throw new IllegalStateException(); this.horizontals[x][y] = true; -- GitLab