From 78dfd10b1c1bd1caa70a26cf16ce8b5f08c00778 Mon Sep 17 00:00:00 2001 From: "dario.genga" <dario.genga@etu.hesge.ch> Date: Tue, 14 Dec 2021 14:56:24 +0100 Subject: [PATCH] Add structure for the game Also implemented the methods for initialize and destroy the game. --- main.c | 4 ++++ puissance.c | 43 +++++++++++++++++++++++++++++++++++++++++++ puissance.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/main.c b/main.c index b651b12..9c3e109 100644 --- a/main.c +++ b/main.c @@ -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; } diff --git a/puissance.c b/puissance.c index 010f54d..f926d3f 100644 --- a/puissance.c +++ b/puissance.c @@ -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; +} + diff --git a/puissance.h b/puissance.h index bf975a0..fdfec3c 100644 --- a/puissance.h +++ b/puissance.h @@ -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 -- GitLab