Skip to content
Snippets Groups Projects
Commit ce6e86ae authored by Jonathan Tosio's avatar Jonathan Tosio
Browse files

added bux fixes

parent 66724dae
No related branches found
No related tags found
No related merge requests found
......@@ -111,9 +111,12 @@ 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 (getVertical(x, y) && getVertical(x + 1, y) && getHorizontal(x, y) && getHorizontal(x, y + 1)){
return true;
}
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) {
......@@ -140,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("Horizontal line already drawn"));
}
this.horizontals[x][y] = true;
......@@ -171,6 +177,9 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (getVertical(x, y)){
throw new IllegalStateException(String.format("Vertical line already drawn"));
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
......
......@@ -35,14 +35,15 @@ public class DotsAndBoxesGridTest {
public void testCompleteBox() {
logger.info("Testing whether the algorithm for testing whether a box is complete is wrong");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(1, 1, 2);
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
// draw three sides of a box, not four!
grid.drawVertical(0, 0, 1);
grid.drawVertical(1, 0, 1);
grid.drawHorizontal(0, 0, 1);
grid.drawVertical(1, 1, 1);
grid.drawVertical(2, 1, 1);
grid.drawHorizontal(1, 1, 1);
// grid.drawHorizontal(1, 2, 1);
assertFalse(grid.boxComplete(1, 0));
assertFalse(grid.boxComplete(1, 1));
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment