Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DotsAndBoxes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gsjollem
DotsAndBoxes
Commits
a13cd1bc
Commit
a13cd1bc
authored
3 years ago
by
gsjollem
Browse files
Options
Downloads
Patches
Plain Diff
tests now work and bugs corrected
parent
cfe39cdc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+23
-3
23 additions, 3 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+9
-2
9 additions, 2 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
32 additions
and
5 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
23
−
3
View file @
a13cd1bc
...
@@ -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 numb
gra
er 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
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
9
−
2
View file @
a13cd1bc
...
@@ -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
));
...
...
This diff is collapsed.
Click to expand it.
gsjollem
@gsjollem
mentioned in issue
#1 (closed)
·
3 years ago
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment