Skip to content
Snippets Groups Projects
Commit b3b52cb9 authored by remi.greub's avatar remi.greub
Browse files

factorisation de fonction qui detecte une case de libre dans une colonne donnée

parent 20ac8f0c
Branches
No related tags found
No related merge requests found
......@@ -73,14 +73,28 @@ int kill_game(){
}*/
int put_free_cell(int j_p, int i, symbol_t symbol){
if(game.cells[j_p][i].symbol == EMPTY){
//put the player's symbol
int put_free_cell(int j_p, symbol_t symbol){
int i=0;
if((i = is_cell_free(j_p, 0, game.players[game.curr_player].symbol)) != -1){
game.cells[j_p][i].symbol = symbol;
}
return i;
}
/*
retourne la ligne d'une cellule de libre dans une
colonne donnée
(si il y en a une, retourn -1 si il n'y en a aucune)
*/
int is_cell_free(int j_p, int i, symbol_t symbol){
if(game.cells[j_p][i].symbol == EMPTY){
//retourne la ligne disponible
return i;
}else{
if(i<=game.height){
return put_free_cell(j_p, i+1, symbol);
if(i<(game.width-1)){
return is_cell_free(j_p, i+1, symbol);
}else{
printf("il n'y a plus de case de disponible sur cette colonne\n");
return -1;
}
}
......
......@@ -45,7 +45,8 @@ void init_puissance4(int height, int width);
void cell_destroy(struct cell **cells, int height);
int kill_game();
int put_free_cell(int j_p, int i, symbol_t symbol);
int put_free_cell(int j_p, symbol_t symbol);
int is_cell_free(int j_p, int i, symbol_t symbol);
int Launch_puissance4();
bool Is_Grid_full();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment