Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smajrash
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
Shahad
smajrash
Commits
2dccc0de
Commit
2dccc0de
authored
1 year ago
by
Shahad
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs in the code
parent
e779d58a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/test/java/dotsandboxes/DotsAndBoxesGame.java
+47
-0
47 additions, 0 deletions
src/test/java/dotsandboxes/DotsAndBoxesGame.java
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+1
-1
1 addition, 1 deletion
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
with
48 additions
and
1 deletion
src/test/java/dotsandboxes/DotsAndBoxesGame.java
0 → 100644
+
47
−
0
View file @
2dccc0de
public
class
DotsAndBoxesGame
{
private
boolean
[][]
horizontalLines
;
private
boolean
[][]
verticalLines
;
private
int
gridSize
;
public
DotsAndBoxesGame
(
int
gridSize
)
{
this
.
gridSize
=
gridSize
;
horizontalLines
=
new
boolean
[
gridSize
+
1
][
gridSize
];
verticalLines
=
new
boolean
[
gridSize
][
gridSize
+
1
];
}
public
boolean
drawHorizontalLine
(
int
row
,
int
col
)
{
if
(
row
>=
0
&&
row
<
gridSize
+
1
&&
col
>=
0
&&
col
<
gridSize
&&
!
horizontalLines
[
row
][
col
])
{
horizontalLines
[
row
][
col
]
=
true
;
return
true
;
}
return
false
;
}
public
boolean
drawVerticalLine
(
int
row
,
int
col
)
{
if
(
row
>=
0
&&
row
<
gridSize
&&
col
>=
0
&&
col
<
gridSize
+
1
&&
!
verticalLines
[
row
][
col
])
{
verticalLines
[
row
][
col
]
=
true
;
return
true
;
}
return
false
;
}
public
boolean
isLineDrawn
(
int
row
,
int
col
,
LineType
type
)
{
if
(
type
==
LineType
.
HORIZONTAL
)
{
return
horizontalLines
[
row
][
col
];
}
else
if
(
type
==
LineType
.
VERTICAL
)
{
return
verticalLines
[
row
][
col
];
}
return
false
;
}
public
boolean
isSquareComplete
(
int
row
,
int
col
)
{
return
isLineDrawn
(
row
,
col
,
LineType
.
HORIZONTAL
)
&&
isLineDrawn
(
row
+
1
,
col
,
LineType
.
HORIZONTAL
)
&&
isLineDrawn
(
row
,
col
,
LineType
.
VERTICAL
)
&&
isLineDrawn
(
row
,
col
+
1
,
LineType
.
VERTICAL
);
}
}
enum
LineType
{
HORIZONTAL
,
VERTICAL
}
This diff is collapsed.
Click to expand it.
src/test/java/dotsandboxes/DotsAndBoxesGridTest.java
+
1
−
1
View file @
2dccc0de
...
...
@@ -7,7 +7,7 @@ public class DotsAndBoxesGameTest {
@Test
public
void
testSquareComplete
()
{
// Given
DotsAndBoxesGame
game
=
new
DotsAndBoxesGame
();
DotsAndBoxesGame
game
=
new
DotsAndBoxesGame
(
2
);
// Assuming the following lines form a complete square
game
.
drawHorizontalLine
(
0
,
0
);
game
.
drawHorizontalLine
(
0
,
1
);
...
...
This diff is collapsed.
Click to expand it.
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