Skip to content
Snippets Groups Projects
Commit a13cd1bc authored by gsjollem's avatar gsjollem
Browse files

tests now work and bugs corrected

parent cfe39cdc
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ import java.util.function.Consumer; ...@@ -19,7 +19,7 @@ import java.util.function.Consumer;
* *
* Notice that: * Notice that:
* *
* - for each row, there is one less horizontal than the number of corner dots * - for each row, there is one less horizontal than the numbgraer of corner dots
* - for each row, there are as many verticals as there are corner dots * - for each row, there are as many verticals as there are corner dots
* - for each row, there is one less box than the number of corner dots * - for each row, there is one less box than the number of corner dots
* - for each column, there is one less vertical than the number of corner dots. * - for each column, there is one less vertical than the number of corner dots.
...@@ -111,9 +111,18 @@ public class DotsAndBoxesGrid { ...@@ -111,9 +111,18 @@ public class DotsAndBoxesGrid {
return false; return false;
} }
else if((getHorizontal(x, y)) && (getHorizontal(x, y+1)) && (getVertical(x, y))
&& (getVertical(x + 1, y)))
{
return true;
}
else
{
return false;
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn. // 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). // FIXME: You'll need to fix this code (after writing a test first)
return true;
} }
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */ /** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...@@ -142,6 +151,11 @@ public class DotsAndBoxesGrid { ...@@ -142,6 +151,11 @@ public class DotsAndBoxesGrid {
// FIXME: You need to throw an exception if the line was already drawn. // FIXME: You need to throw an exception if the line was already drawn.
if(getHorizontal(x, y))
{
throw new IndexOutOfBoundsException("That connection has already been drawn");
}
this.horizontals[x][y] = true; this.horizontals[x][y] = true;
// Try to claim the north or south boxes // Try to claim the north or south boxes
...@@ -173,6 +187,12 @@ public class DotsAndBoxesGrid { ...@@ -173,6 +187,12 @@ public class DotsAndBoxesGrid {
// You need to throw an exception if the line was already drawn. // You need to throw an exception if the line was already drawn.
if(getVertical(x, y))
{
throw new IndexOutOfBoundsException("That connection has already been drawn");
}
this.verticals[x][y] = true; this.verticals[x][y] = true;
// Try to claim the north or south boxes // Try to claim the north or south boxes
boolean claimE = claimBox(x, y, player); boolean claimE = claimBox(x, y, player);
......
...@@ -36,7 +36,7 @@ public class DotsAndBoxesGridTest { ...@@ -36,7 +36,7 @@ public class DotsAndBoxesGridTest {
public void testLineDraw(){ public void testLineDraw(){
//This test will draw the lines that will also be used in the second test. It should draw the box //This test will draw the lines that will also be used in the second test. It should draw the box
//then attempt to draw one of the lines again. //then attempt to draw one of the lines again.
logger.info("Testing duplicate line drawing"); logger.info("Testing duplicate line drawing");
...@@ -45,7 +45,8 @@ public class DotsAndBoxesGridTest { ...@@ -45,7 +45,8 @@ public class DotsAndBoxesGridTest {
grid.drawVertical(0,0,1); grid.drawVertical(0,0,1);
grid.drawVertical(1,0,1); grid.drawVertical(1,0,1);
assertFalse(grid.drawHorizontal(0, 0, 1)); assertThrows(IndexOutOfBoundsException.class, () -> { grid.drawHorizontal(0, 0, 1);} );
//assertFalse(grid.drawHorizontal(0, 0, 1));
} }
...@@ -54,6 +55,12 @@ public class DotsAndBoxesGridTest { ...@@ -54,6 +55,12 @@ public class DotsAndBoxesGridTest {
public void testBoxComplete() public void testBoxComplete()
{ {
// will need to draw a box, then give it to box complete and assert that it should be true // will need to draw a box, then give it to box complete and assert that it should be true
grid.drawHorizontal(0, 0, 1);
grid.drawHorizontal(0,1, 1);
grid.drawVertical(0,0,1);
grid.drawVertical(1,0,1);
logger.info("Testing box completion"); logger.info("Testing box completion");
assertTrue(grid.boxComplete(0,0)); assertTrue(grid.boxComplete(0,0));
assertFalse(grid.boxComplete(2,2)); assertFalse(grid.boxComplete(2,2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment