From 6e212a84ba70bc4d194ce775acc75a3c2a419f22 Mon Sep 17 00:00:00 2001 From: "remi.greub" <remi.greub@hes-so.ch> Date: Sat, 29 Mar 2025 23:37:45 +0100 Subject: [PATCH] dernieres corrections sur smartbot --- puissance4_GRB/puissance4.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/puissance4_GRB/puissance4.c b/puissance4_GRB/puissance4.c index c702b54..d2cf416 100644 --- a/puissance4_GRB/puissance4.c +++ b/puissance4_GRB/puissance4.c @@ -358,6 +358,7 @@ int Launch_puissance4_smartBot(int seed){ int SmartBot(){ int pos=0; + int chfr1 = -1, chfr2 = -1; for(int chfr=0; chfr<game.width; chfr++){ //verifie que le coup est jouable if((pos = put_free_cell(chfr, game.players[game.curr_player].symbol))>=0){ @@ -366,20 +367,26 @@ int SmartBot(){ if (Find_winner(game.cells, game.cells[chfr][pos]) == game.players[game.curr_player].symbol){ //1er cas : a trouvé le bon coup à jouer pour gagner tempCell->symbol = EMPTY; - return chfr; + chfr1 = chfr; } //tente de chercher si l'autre joueur a un coup gagnant tempCell->symbol = game.players[game.curr_player^1].symbol; if (Find_winner(game.cells, game.cells[chfr][pos]) == game.players[game.curr_player^1].symbol){ //2e cas : joue le coup gagnant de l'autre joueur pour le bloquer tempCell->symbol = EMPTY; - return chfr; + chfr2 = chfr; } tempCell->symbol = EMPTY; } } - //3e cas : joue un coup au hasard - return rand()%game.width; + if(chfr1 != -1){ + return chfr1; + }else if(chfr2 != -1){ + return chfr2; + }else{ + //3e cas : joue un coup au hasard + return rand()%game.width; + } } bool Is_Grid_full(){ -- GitLab