Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gsjollem
DotsAndBoxes
Commits
a13cd1bc
Commit
a13cd1bc
authored
Jul 25, 2021
by
gsjollem
Browse files
tests now work and bugs corrected
parent
cfe39cdc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
View file @
a13cd1bc
...
...
@@ -19,7 +19,7 @@ import java.util.function.Consumer;
*
* 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 numb
gra
er of 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 column, there is one less vertical than the number of corner dots.
...
...
@@ -111,9 +111,18 @@ public class DotsAndBoxesGrid {
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.
// FIXME: You'll need to fix this code (after writing a test first).
return
true
;
// FIXME: You'll need to fix this code (after writing a test first)
}
/** 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 {
// 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
;
// Try to claim the north or south boxes
...
...
@@ -173,6 +187,12 @@ public class DotsAndBoxesGrid {
// 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
;
// Try to claim the north or south boxes
boolean
claimE
=
claimBox
(
x
,
y
,
player
);
...
...
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
View file @
a13cd1bc
...
...
@@ -36,7 +36,7 @@ public class DotsAndBoxesGridTest {
public
void
testLineDraw
(){
//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"
);
...
...
@@ -45,7 +45,8 @@ public class DotsAndBoxesGridTest {
grid
.
drawVertical
(
0
,
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 {
public
void
testBoxComplete
()
{
// 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"
);
assertTrue
(
grid
.
boxComplete
(
0
,
0
));
assertFalse
(
grid
.
boxComplete
(
2
,
2
));
...
...
gsjollem
@gsjollem
mentioned in issue
#1 (closed)
·
Jul 25, 2021
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment