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
mthoma48
dotsandboxes
Commits
62480a1d
Commit
62480a1d
authored
3 years ago
by
mthoma48
Browse files
Options
Downloads
Patches
Plain Diff
Initial bugfixes that pass unit tests
parent
3cff0b8d
No related branches found
Branches containing commit
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
+20
-8
20 additions, 8 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+4
-4
4 additions, 4 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
24 additions
and
12 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
20
−
8
View file @
62480a1d
...
...
@@ -107,13 +107,20 @@ public class DotsAndBoxesGrid {
* @return true if all four sides have been drawn.
*/
public
boolean
boxComplete
(
int
x
,
int
y
)
{
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
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
;
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
return
false
;
}
else
if
(
this
.
getVertical
(
x
,
y
)
==
true
&&
this
.
getVertical
(
x
+
1
,
y
)
==
true
)
{
if
(
this
.
getHorizontal
(
x
,
y
)
==
true
&&
this
.
getHorizontal
(
x
,
y
+
1
)
==
true
)
{
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
return
false
;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -142,7 +149,12 @@ public class DotsAndBoxesGrid {
// FIXME: You need to throw an exception if the line was already drawn.
this
.
horizontals
[
x
][
y
]
=
true
;
if
(
this
.
horizontals
[
x
][
y
]
==
true
)
{
throw
new
RuntimeException
(
"Line already here"
);
}
else
{
this
.
horizontals
[
x
][
y
]
=
true
;
}
// Try to claim the north or south boxes
boolean
claimN
=
claimBox
(
x
,
y
-
1
,
player
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
4
−
4
View file @
62480a1d
...
...
@@ -35,12 +35,12 @@ public class DotsAndBoxesGridTest {
public
void
completeBoxTest
()
{
logger
.
info
(
"Test to see if completion algorithm is working"
);
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
4
,
2
,
2
);
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
4
,
3
,
2
);
// draw a complete square
grid
.
drawHorizontal
(
1
,
1
,
1
);
grid
.
drawHorizontal
(
1
,
2
,
1
);
grid
.
drawVertical
(
1
,
2
,
1
);
assertTrue
(
grid
.
drawVertical
(
2
,
2
,
1
));
grid
.
drawHorizontal
(
1
,
2
,
2
);
grid
.
drawVertical
(
1
,
1
,
1
);
assertTrue
(
grid
.
drawVertical
(
2
,
1
,
1
));
}
// Test that DotsAndBoxesGrid currently allows drawing a line on an existing line
...
...
This diff is collapsed.
Click to expand it.
mthoma48
@mthoma48
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