Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-puissance4
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
progseq-puissance4
Commits
f694e733
Commit
f694e733
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add diagonal verification
Also fixed a typo in the readme.
parent
543897ff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
main.c
+11
-5
11 additions, 5 deletions
main.c
puissance.c
+52
-0
52 additions, 0 deletions
puissance.c
with
64 additions
and
6 deletions
README.md
+
1
−
1
View file @
f694e733
...
...
@@ -17,7 +17,7 @@ Use this command to compile the project.
Use this command to clean the project.
### Run the tests
> `make test`
> `make test
s
`
>
> `./test`
...
...
This diff is collapsed.
Click to expand it.
main.c
+
11
−
5
View file @
f694e733
...
...
@@ -13,16 +13,22 @@ int main() {
puissance
game
;
game_init
(
&
game
,
RAND_AI
,
DEFAULT_ROW
,
DEFAULT_COL
);
manual_play
(
&
game
,
4
);
print_game
(
game
);
manual_play
(
&
game
,
0
);
manual_play
(
&
game
,
1
);
print_game
(
game
);
manual_play
(
&
game
,
1
);
manual_play
(
&
game
,
2
);
print_game
(
game
);
manual_play
(
&
game
,
3
);
manual_play
(
&
game
,
0
);
manual_play
(
&
game
,
2
);
print_game
(
game
);
manual_play
(
&
game
,
6
);
manual_play
(
&
game
,
2
);
manual_play
(
&
game
,
3
);
print_game
(
game
);
manual_play
(
&
game
,
1
);
manual_play
(
&
game
,
4
);
manual_play
(
&
game
,
3
);
print_game
(
game
);
manual_play
(
&
game
,
3
);
print_game
(
game
);
game_destroy
(
&
game
);
...
...
This diff is collapsed.
Click to expand it.
puissance.c
+
52
−
0
View file @
f694e733
...
...
@@ -197,11 +197,63 @@ GameResult horizontal_game_check(puissance *p, int last_col_index_played) {
return
ONGOING
;
}
bool
diagonal_parse
(
puissance
*
p
,
int
x_r
,
int
y_c
,
int
starting_row
,
int
starting_col
)
{
bool
four_aligned
=
true
;
int
last_played_value
=
p
->
data
[
starting_row
][
starting_col
];
for
(
int
i
=
1
;
i
<=
NB_VERIFICATION_FOR_WIN
;
i
++
)
{
int
r
=
x_r
*
i
+
starting_row
;
int
c
=
y_c
*
i
+
starting_col
;
if
(
r
<
0
||
r
>=
p
->
row
||
c
<
0
||
c
>=
p
->
col
)
{
return
false
;
}
if
(
p
->
data
[
r
][
c
]
!=
last_played_value
)
{
four_aligned
=
false
;
break
;
}
}
return
four_aligned
;
}
GameResult
diagonal_game_check
(
puissance
*
p
,
int
last_col_index_played
)
{
if
(
p
->
state
!=
ONGOING
)
{
return
p
->
state
;
}
bool
four_aligned
=
false
;
// Get the row index
int
last_row_index_played
=
get_available_row_index
(
p
,
last_col_index_played
)
+
1
;
// down right
if
(
diagonal_parse
(
p
,
1
,
1
,
last_row_index_played
,
last_col_index_played
))
{
return
get_winning_player
(
p
);
}
// up left
if
(
diagonal_parse
(
p
,
-
1
,
-
1
,
last_row_index_played
,
last_col_index_played
))
{
return
get_winning_player
(
p
);
}
// up right
if
(
diagonal_parse
(
p
,
-
1
,
1
,
last_row_index_played
,
last_col_index_played
))
{
return
get_winning_player
(
p
);
}
// down left
if
(
diagonal_parse
(
p
,
1
,
-
1
,
last_row_index_played
,
last_col_index_played
))
{
return
get_winning_player
(
p
);
}
return
ONGOING
;
}
GameResult
verify_game
(
puissance
*
p
,
int
last_col_index_played
)
{
// Vertical check
vertical_game_check
(
p
,
last_col_index_played
);
// Horizontal check
horizontal_game_check
(
p
,
last_col_index_played
);
// Diagonal check
diagonal_game_check
(
p
,
last_col_index_played
);
return
p
->
state
;
}
...
...
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