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
78dfd10b
Commit
78dfd10b
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add structure for the game
Also implemented the methods for initialize and destroy the game.
parent
f88cbf43
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
main.c
+4
-0
4 additions, 0 deletions
main.c
puissance.c
+43
-0
43 additions, 0 deletions
puissance.c
puissance.h
+39
-0
39 additions, 0 deletions
puissance.h
with
86 additions
and
0 deletions
main.c
+
4
−
0
View file @
78dfd10b
...
...
@@ -8,7 +8,11 @@
#include
"puissance.h"
int
main
()
{
puissance
game
;
game_init
(
&
game
,
RAND_AI
,
DEFAULT_ROW
,
DEFAULT_COL
);
game_destroy
(
&
game
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
puissance.c
+
43
−
0
View file @
78dfd10b
...
...
@@ -5,3 +5,46 @@
#include
"puissance.h"
#include
<stdio.h>
void
game_init
(
puissance
*
p
,
GameMode
mode
,
int
row
,
int
col
)
{
p
->
mode
=
mode
;
p
->
current_player
=
PLAYER_ONE
;
p
->
row
=
row
;
p
->
col
=
col
;
p
->
data
=
malloc
(
col
*
sizeof
(
int
*
));
for
(
int
i
=
0
;
i
<
col
;
i
++
)
{
p
->
data
[
i
]
=
malloc
(
row
*
sizeof
(
int
*
));
}
}
void
print_game
(
puissance
p
)
{
}
void
verify_game
(
puissance
p
)
{
}
bool
manual_play
(
puissance
*
p
,
int
selected_col_index
)
{
bool
valid_action
=
true
;
return
valid_action
;
}
bool
random_play
(
puissance
*
p
)
{
bool
valid_action
=
true
;
return
valid_action
;
}
bool
smart_play
(
puissance
*
p
)
{
bool
valid_action
=
true
;
return
valid_action
;
}
void
game_destroy
(
puissance
*
p
)
{
free
(
p
->
data
);
p
=
NULL
;
}
This diff is collapsed.
Click to expand it.
puissance.h
+
39
−
0
View file @
78dfd10b
...
...
@@ -9,4 +9,43 @@
#include
<stdlib.h>
#include
<stdbool.h>
#define ROW_MIN 4
#define COL_MIN 4
#define DEFAULT_ROW 6
#define DEFAULT_COL 7
typedef
enum
{
RAND_AI
,
SMART_AI
,
TWO_PLAYERS
,
}
GameMode
;
typedef
enum
{
PLAYER_ONE
,
PLAYER_TWO
,
}
Player
;
typedef
enum
{
ONGOING
,
DRAW
,
PLAYER_ONE_WIN
,
PLAYER_TWO_WIN
,
}
GameResult
;
typedef
struct
_puissance
{
GameMode
mode
;
Player
current_player
;
int
row
;
int
col
;
int
**
data
;
}
puissance
;
void
game_init
(
puissance
*
p
,
GameMode
mode
,
int
row
,
int
col
);
void
print_game
(
puissance
p
);
void
verify_game
(
puissance
p
);
bool
manual_play
(
puissance
*
p
,
int
selected_col_index
);
bool
random_play
(
puissance
*
p
);
bool
smart_play
(
puissance
*
p
);
void
game_destroy
(
puissance
*
p
);
#endif
\ No newline at end of file
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