Skip to content
Snippets Groups Projects

Fixed bugs in box completion and duplicate line drawing

Merged Carol-Ann Donaldson requested to merge 1-fix-assignment-errors into main
1 file
+ 10
3
Compare changes
  • Side-by-side
  • Inline
@@ -112,7 +112,9 @@ 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;
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
return getHorizontal(x, y) && getHorizontal(x, y + 1) &&
getVertical(x, y) && getVertical(x + 1, y);
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
@@ -140,7 +142,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if (horizontals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.horizontals[x][y] = true;
// Try to claim the north or south boxes
@@ -171,7 +175,10 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (verticals[x][y]) {
throw new IllegalStateException("Line already drawn");
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
boolean claimE = claimBox(x, y, player);
Loading