From a1996e400af53239e575e6883c37e752bc2d49f9 Mon Sep 17 00:00:00 2001 From: SauravSaurav <saurav@myune.edu.au> Date: Sat, 24 Jul 2021 16:41:46 +0300 Subject: [PATCH] bug fixes --- src/main/java/dotsandboxes/DotsAndBoxesGrid.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java index 32667af..cbcc9f2 100644 --- a/src/main/java/dotsandboxes/DotsAndBoxesGrid.java +++ b/src/main/java/dotsandboxes/DotsAndBoxesGrid.java @@ -1,6 +1,5 @@ package dotsandboxes; - import java.util.ArrayList; import java.util.Arrays; import java.util.Observer; @@ -113,7 +112,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). - return true; + if (getHorizontal(x,y) && getVertical(x,y)) { + return true; + } + return false; } /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */ @@ -141,6 +143,9 @@ public class DotsAndBoxesGrid { } // FIXME: You need to throw an exception if the line was already drawn. + if (getHorizontal(x,y)) { + throw new IllegalStateException(String.format("line x=%d,y=%d was already drawn",x,y)); + } this.horizontals[x][y] = true; -- GitLab