Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
assignment_2
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
Steve McKinnon
assignment_2
Commits
dbd7b6b5
Commit
dbd7b6b5
authored
3 years ago
by
Steve McKinnon
Browse files
Options
Downloads
Patches
Plain Diff
fixed duplicate line and complete box bugs
parent
4450a8e9
Branches
1-fix-assignment-errors
main
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
+12
-3
12 additions, 3 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+3
-3
3 additions, 3 deletions
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
15 additions
and
6 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
12
−
3
View file @
dbd7b6b5
...
...
@@ -113,7 +113,10 @@ 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).
return
true
;
if
(
this
.
horizontals
[
x
][
y
]
&&
this
.
horizontals
[
x
][
y
+
1
]
&&
this
.
verticals
[
x
][
y
]
&&
this
.
verticals
[
x
+
1
][
y
])
{
return
true
;
}
return
false
;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -140,7 +143,10 @@ public class DotsAndBoxesGrid {
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
}
// FIXME: You need to throw an exception if the line was already drawn.
// Throw an exception if the line was already drawn.
if
(
this
.
horizontals
[
x
][
y
])
{
throw
new
IllegalStateException
(
"This line has already been drawn"
);
}
this
.
horizontals
[
x
][
y
]
=
true
;
...
...
@@ -171,7 +177,10 @@ public class DotsAndBoxesGrid {
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
-
1
));
}
// You need to throw an exception if the line was already drawn.
// Throw an exception if the line was already drawn.
if
(
this
.
verticals
[
x
][
y
])
{
throw
new
IllegalStateException
(
"This line has already been drawn"
);
}
this
.
verticals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
...
...
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
3
−
3
View file @
dbd7b6b5
...
...
@@ -17,7 +17,7 @@ public class DotsAndBoxesGridTest {
/*
* A test to check if a box is correctly marked as complete.
* Asserting
Fals
e after drawing a complete box
* Asserting
Tru
e after drawing a complete box
*/
...
...
@@ -31,13 +31,13 @@ public class DotsAndBoxesGridTest {
grid
.
drawVertical
(
1
,
1
,
1
);
grid
.
drawVertical
(
2
,
1
,
1
);
assert
Fals
e
(
grid
.
boxComplete
(
1
,
1
));
assert
Tru
e
(
grid
.
boxComplete
(
1
,
1
));
}
/*
* A test to see if a line can be redrawn after it has already been drawn,
* test should throw an exception
* test should throw an exception
.
*/
@Test
public
void
testRedrawLineFails
()
{
...
...
This diff is collapsed.
Click to expand it.
Steve McKinnon
@smckin27
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