From 545b554054b78b9659aa27db1587d36104c537b2 Mon Sep 17 00:00:00 2001
From: "remi.greub" <remi.greub@hes-so.ch>
Date: Thu, 27 Mar 2025 00:56:18 +0100
Subject: [PATCH] correction (inverser height et width)

---
 puissance4_GRB/puissance4.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/puissance4_GRB/puissance4.c b/puissance4_GRB/puissance4.c
index 1ab1c9e..605f79a 100644
--- a/puissance4_GRB/puissance4.c
+++ b/puissance4_GRB/puissance4.c
@@ -13,13 +13,13 @@ grid game;
  * 		et alloue la mémoire dynamiquement
  ***********************************/
 struct cell **Create_grid2D(){
-	struct cell** cells = malloc(game.height*sizeof(struct cell*));
-	for(int k =0; k<game.height; k++){
-		cells[k] = malloc(game.width*sizeof(struct cell));
+	struct cell** cells = malloc(game.width*sizeof(struct cell*));
+	for(int k =0; k<game.width; k++){
+		cells[k] = malloc(game.height*sizeof(struct cell));
 	}
 	//initialise les positions et les valeurs de base
-	for(int i = 0; i<game.height; i++){
-		for(int j=0; j<game.width; j++){
+	for(int i = 0; i<game.width; i++){
+		for(int j=0; j<game.height; j++){
 			cells[i][j].pressed = false;
 			cells[i][j].symbol = EMPTY;
 			cells[i][j].i_pos = i;
@@ -30,8 +30,8 @@ struct cell **Create_grid2D(){
 }
 
 void print_cells(struct cell **cell){
-	for(int i=0; i<game.height; i++){
-		for(int j=0; j<game.width; j++){
+	for(int i=0; i<game.width; i++){
+		for(int j=0; j<game.height; j++){
 			printf("%d, ", cell[i][j].symbol);
 		}
 		printf("\n");
@@ -91,7 +91,7 @@ int is_cell_free(int j_p, int i, symbol_t symbol){
 		//retourne la ligne disponible
 		return i;
 	}else{
-		if(i<(game.width-1)){
+		if(i<(game.height-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");
@@ -108,13 +108,13 @@ int Launch_puissance4(){
 		//print_grille();
 		print_gameCells();
 		printf("au tour de %d de jouer\n", game.curr_player);
-		printf("balance un chiffre entre 0 et %d\n", game.height-1);
+		printf("balance un chiffre entre 0 et %d\n", game.width-1);
 		do{
 			scanf("%d",&chiffre);
-			if(chiffre >= game.height || chiffre < 0){
+			if(chiffre >= game.width || chiffre < 0){
 				printf("HEP HEPHEP !! donne un chiffre dans la plage donnee manche a couille\n");
 			}
-		}while((chiffre >= game.height) || (chiffre < 0) || is_cell_free(chiffre, 0, game.players[game.curr_player].symbol)<0);
+		}while((chiffre >= game.width) || (chiffre < 0) || is_cell_free(chiffre, 0, game.players[game.curr_player].symbol)<0);
 
 		game.gamePlayed -= 1; //peut être le mettre plus bas non ?
 		int i = 0;
@@ -235,7 +235,7 @@ symbol_t CheckWin_in_a_direction(int dir[2], struct cell **grid, struct cell cel
 	int x2 = cell.j_pos+dir[1];
 	symbol_t result = EMPTY;
 
-	if(x1<game.height && x1>=0 && x2<game.width && x2>=0){
+	if(x1<game.width && x1>=0 && x2<game.height && x2>=0){
 		if(grid[x1][x2].symbol==cell.symbol){
 			if(cell.symbol == CIRCLE){
 				game.players[0].check_win += 1;
-- 
GitLab