Skip to content
Snippets Groups Projects
Commit 78dfd10b authored by dario.genga's avatar dario.genga
Browse files

Add structure for the game

Also implemented the methods for initialize and destroy the game.
parent f88cbf43
Branches
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -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;
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment