Browse Source

Merge branch 'master' into ai

master
Stéphane 8 years ago
parent
commit
e2f7c59189
8 changed files with 165 additions and 73 deletions
  1. +2
    -2
      Makefile
  2. +8
    -14
      dummy.c
  3. +75
    -12
      gui.c
  4. +4
    -1
      gui.h
  5. +5
    -0
      guidemo.c
  6. BIN
      img/cmunbmr.otf
  7. BIN
      img/msgboard.png
  8. +71
    -44
      main.c

+ 2
- 2
Makefile View File

@ -16,7 +16,7 @@ api.h : dameschinoises.h dameschinoises.patch
patch -o api.h dameschinoises.h dameschinoises.patch
main : main.o gui
gcc main.o gui.o -o main -pedantic $(LDFLAGS) -lSDL -lSDL_image -lSDL_gfx -lm $(WARNINGS)
gcc main.o gui.o -o main -pedantic $(LDFLAGS) -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lm $(WARNINGS)
main.o : main.c api.h
gcc -c main.c $(CFLAGS) $(WARNINGS)
@ -33,7 +33,7 @@ gui : gui.c api.h
gcc -c gui.c $(CFLAGS) $(WARNINGS)
guidemo : guidemo.c gui
gcc guidemo.c gui.o -o guidemo $(CFLAGS) $(LDFLAGS) -lSDL -lSDL_image -lSDL_gfx -lm $(WARNINGS)
gcc guidemo.c gui.o -o guidemo $(CFLAGS) $(LDFLAGS) -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lm $(WARNINGS)
clean :
rm -f *.o


+ 8
- 14
dummy.c View File

@ -5,31 +5,25 @@
#include "api.h"
struct stockage {
char *name;
unsigned int nb_joueur;
enum hole_t color;
};
struct stockage storage(unsigned int write, char* name, unsigned int nb_joueur, enum hole_t color) {
struct stockage storage(unsigned int write, unsigned int nb_joueur, enum hole_t color) {
static struct stockage stock={NULL,0};
if(write & 1)
stock.color = color;
if(write & 2)
stock.nb_joueur = nb_joueur;
if(write & 4) {
if(stock.name)
free(stock.name);
stock.name = (char*) malloc((strlen(name)+1)*sizeof(char));
if(stock.name)
strncpy(stock.name, name, strlen(name));
}
return stock;
}
void InitLibrary(char name[50]) {
struct stockage stock;
stock = storage(4,name,0,0);
printf("stratégie init %s\n", stock.name);
struct stockage stock;;
stock = storage(3,0,0);
puts("name ?");
scanf("%s",name);
printf("stratégie init %s\n", name);
}
void StartGame() {
puts("stratégie start game");
@ -37,7 +31,7 @@ void StartGame() {
void StartMatch(const unsigned int nb_joueur, const enum hole_t color) {
srand(time(NULL));
struct stockage stock;
stock = storage(3,NULL,nb_joueur, color);
stock = storage(3,nb_joueur, color);
printf("stratégie start match (%d players, color%d)\n", stock.nb_joueur, stock.color);
}
@ -53,7 +47,7 @@ int NextMove(const SGameState * const gameState, int firstMove, SMove *move) {
struct stockage stock;
size_t i;
int start, end, next;
stock = storage(0, NULL, 0, 0);
stock = storage(0, 0, 0);
printf("joueur %d, pions : [ ", stock.color);
for(i=0;i<121;i++) {
if(gameState->board[i] == stock.color)


+ 75
- 12
gui.c View File

@ -8,7 +8,7 @@
#include "api.h"
#include "gui.h"
/*#define rant*/
/*#define rant // spout messages if the machine is too slow */
#define null_die(instruction, error) do if(!(instruction)) { fprintf(stderr, "(fatal) %s%s", error, "\n"); exit(1); } while(0)
@ -19,18 +19,27 @@ SDL_Surface *IMG_LoadBoost(const char *path) {
return ret;
}
#define SCREEN_X 800
#define SCREEN_Y 600
struct gui_resource_t display_start() {
struct gui_resource_t res;
null_die(SDL_Init(SDL_INIT_VIDEO) != -1, "SDL initialization failed");
null_die(TTF_Init() != -1, "TTF initialization failed");
/* création fenêtre */
SDL_Init(SDL_INIT_VIDEO);
res.screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
res.screen = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("跳棋", NULL);
/* chargement images */
null_die(res.title_img = IMG_LoadBoost("img/title.png"), "cannot load title img");
null_die(res.bgnd_img = IMG_LoadBoost("img/background.png"), "cannot load bg img");
null_die(res.board_img = IMG_LoadBoost("img/board.png"), "cannot load board img");
SDL_Surface *msgboard_srcimg;
null_die(msgboard_srcimg = IMG_Load("img/msgboard.png"), "cannot load message board img");
res.msgboard_img = SDL_DisplayFormat(msgboard_srcimg);
SDL_FreeSurface(msgboard_srcimg);
null_die(res.pawn_img[0] = IMG_LoadBoost("img/pawn0-void.png"), "cannot load void pawn img");
null_die(res.pawn_img[1] = IMG_LoadBoost("img/pawn1-yellow.png"), "cannot load yellow pawn img");
null_die(res.pawn_img[2] = IMG_LoadBoost("img/pawn2-black.png"), "cannot load black pawn img");
@ -39,6 +48,10 @@ struct gui_resource_t display_start() {
null_die(res.pawn_img[5] = IMG_LoadBoost("img/pawn5-green.png"), "cannot load green pawn img");
null_die(res.pawn_img[6] = IMG_LoadBoost("img/pawn6-purple.png"), "cannot load purple pawn img");
/* chargement police de caractères */
null_die(res.font_big = TTF_OpenFont("img/cmunbmr.otf", 34), "cannot load font");
null_die(res.font_small = TTF_OpenFont("img/cmunbmr.otf", 18), "cannot load font");
return res;
}
@ -107,14 +120,12 @@ void draw_all(struct gui_resource_t *res, struct game_state_t *gamestate, SDL_Su
int index_lines[] = {1, 3, 6, 10, 23, 35, 46, 56, 65, 75, 86, 98, 111, 115, 118, 120};
int index_line_offsets[] = {0, 0, 2, 2, 8, 11, 11, 9, 9, 8, 10, 10, 12, 7, 3, 1, 1};
int line = 0;
#define CENTER_X 400
#define CENTER_Y 300
#define PAWNSIZE 28
#define FUZZSPACING 19
#define HORIZSPACING 10
#define VERTSPACING 5
pawn_pos.x = CENTER_X - PAWNSIZE/2 - (PAWNSIZE+HORIZSPACING);
pawn_pos.y = (PAWNSIZE/2+8);
pawn_pos.x = SCREEN_X/2 - PAWNSIZE/2 - (PAWNSIZE+HORIZSPACING);
pawn_pos.y = PAWNSIZE/2 + 8;
int i;
for(i = 0; i < 121; i++) {
if(i == index_lines[line]) {
@ -125,11 +136,11 @@ void draw_all(struct gui_resource_t *res, struct game_state_t *gamestate, SDL_Su
pawn_pos.x += PAWNSIZE+HORIZSPACING;
}
/* matrix rotation on pawn_pos using cos & sin of param angle */
pawn_pos_rot.x = pawn_pos.x + PAWNSIZE/2 - CENTER_X;
pawn_pos_rot.y = pawn_pos.y + PAWNSIZE/2 - CENTER_Y;
pawn_pos_rot.x = pawn_pos.x + PAWNSIZE/2 - SCREEN_X/2;
pawn_pos_rot.y = pawn_pos.y + PAWNSIZE/2 - SCREEN_Y/2;
pawn_pos_rot = coord_rotate(pawn_pos_rot, sinA, cosA);
pawn_pos_rot.x -= PAWNSIZE/2 - CENTER_X;
pawn_pos_rot.y -= PAWNSIZE/2 - CENTER_Y;
pawn_pos_rot.x -= PAWNSIZE/2 - SCREEN_X/2;
pawn_pos_rot.y -= PAWNSIZE/2 - SCREEN_Y/2;
SDL_BlitSurface(res->pawn_img[gamestate->board[i]], NULL, buffer, &pawn_pos_rot);
/* export coords */
if(export) {
@ -212,13 +223,63 @@ int display_animove_pawn(struct gui_resource_t res, struct game_state_t gamestat
SDL_Delay(PANIFRAMETIME - (time2-time1));
#ifdef rant
else
fprintf(stderr,"(rant) animation: the machine is slow, frame took %dms\n", time2-time1);
fprintf(stderr,"(rant) pawn animation: the machine is slow, frame took %dms\n", time2-time1);
#endif
}
SDL_FreeSurface(buffer);
return frame != PANIMTIME/PANIFRAMETIME + 1;
}
int display_animsg(struct gui_resource_t res, struct game_state_t gamestate, enum hole_t currentplayer, const char *msg, uint32_t duration) {
#define MANIFRAMETIME 40 /* 40ms → 25fps */
/* mise en buffer de l'image de fond */
SDL_Surface *bgbuffer = SDL_ConvertSurface(res.bgnd_img, res.bgnd_img->format, res.bgnd_img->flags);
draw_all(&res, &gamestate, bgbuffer, ((((double)currentplayer)-1)*M_PI)/3, 1/*antialias*/, NULL);
/* mise en buffer de l'image du message */
SDL_Surface *msgbuffer = SDL_ConvertSurface(res.msgboard_img, res.msgboard_img->format, res.msgboard_img->flags);
SDL_Color text_color = {20, 18, 17}; /* RGB */
SDL_Surface *text_img = TTF_RenderUTF8_Blended(res.font_big, msg, text_color);
SDL_Rect textclip = { msgbuffer->w/2 - text_img->w/2, msgbuffer->h/2 - text_img->h/2 };
SDL_BlitSurface(text_img, NULL, msgbuffer, &textclip); /* dessin du texte */
SDL_FreeSurface(text_img);
uint32_t time1, time2; /* mesure du temps de rendu de frame */
SDL_Event event;
int frame;
for(frame = 0; frame <= duration/MANIFRAMETIME; frame++) {
time1 = SDL_GetTicks();
while(SDL_PollEvent(&event))
if(event.type == SDL_QUIT)
frame = duration/MANIFRAMETIME + 2;
SDL_BlitSurface(bgbuffer, NULL, res.screen, NULL); /* dessin du fond */
double progress = ((double)frame)/((double)(duration/MANIFRAMETIME)); /* 0→1 */
double sqprogress = (progress-1)*(progress-1);
SDL_Surface *zoomed_msg_img = rotozoomSurface(msgbuffer, sqprogress*10/M_PI, sqprogress+0.6, 1/*antialias*/);
SDL_SetAlpha(zoomed_msg_img, SDL_SRCALPHA|SDL_RLEACCEL, (int)round(sin(sqprogress*M_PI)*255));
SDL_Rect clip = { SCREEN_X/2 - zoomed_msg_img->w/2, SCREEN_Y/2 - zoomed_msg_img->h/2 };
SDL_BlitSurface(zoomed_msg_img, NULL, res.screen, &clip); /* dessin du message */
SDL_FreeSurface(zoomed_msg_img);
SDL_Flip(res.screen);
/* attente du temps restant dans la frame */
time2 = SDL_GetTicks();
if(time2-time1 < MANIFRAMETIME)
SDL_Delay(MANIFRAMETIME - (time2-time1));
#ifdef rant
else
fprintf(stderr,"(rant) text animation: the machine is slow, frame took %dms\n", time2-time1);
#endif
}
SDL_FreeSurface(bgbuffer);
SDL_FreeSurface(msgbuffer);
return frame != duration/MANIFRAMETIME + 1;
}
void display_close(struct gui_resource_t res) {
int i;
@ -228,9 +289,11 @@ void display_close(struct gui_resource_t res) {
SDL_FreeSurface(res.bgnd_img);
SDL_FreeSurface(res.title_img);
SDL_FreeSurface(res.board_img);
SDL_FreeSurface(res.msgboard_img);
for( i = 0; i < 7; i++)
SDL_FreeSurface(res.pawn_img[i]);
/* Fermeture fenêtre */
SDL_Quit();
TTF_Quit();
}

+ 4
- 1
gui.h View File

@ -1,5 +1,8 @@
#include <SDL/SDL_ttf.h>
struct gui_resource_t {
SDL_Surface *screen, *title_img, *bgnd_img, *board_img, *pawn_img[7];
SDL_Surface *screen, *title_img, *bgnd_img, *board_img, *msgboard_img, *pawn_img[7];
TTF_Font *font_big, *font_small;
};
struct gui_resource_t display_start();


+ 5
- 0
guidemo.c View File

@ -84,6 +84,11 @@ int main(int argc, char* argv[]) {
break;
}
if( display_animsg(gui_res, gamestate, player2, "Next player’s turn!", 1200/*ms*/) ) {
quit = 1;
break;
}
player1 = player2;
}


BIN
img/cmunbmr.otf View File


BIN
img/msgboard.png View File

Before After
Width: 420  |  Height: 136  |  Size: 66 KiB

+ 71
- 44
main.c View File

@ -22,6 +22,7 @@ enum api_function_t {ia_lib_init, ia_start_match, ia_start_game, ia_end_game , i
struct player_t {
char name[50];
enum hole_t branch;
unsigned int error;
void *ia_lib_p; /* NULL si le joueur n'est pas une stratégie */
@ -256,7 +257,7 @@ enum bool winner(struct player_t player, const size_t start_position[6][10], con
}
void save(const char *filename, const int nb_game, const int nb_player, const time_t start_match, const int *winner, const time_t *duration) {
void save(const char *filename, struct player_t *player_state, const int nb_game, const int nb_game_end, const int nb_player, const time_t start_match, const int *winner, const time_t *duration) {
FILE* file;
char *buffer;
int i;
@ -265,18 +266,20 @@ void save(const char *filename, const int nb_game, const int nb_player, const ti
buffer = ctime(&start_match);
buffer[strlen(buffer)-1] = '\0';
fprintf(file, "=== %s (%d game%s - %d players) ===\n", buffer, nb_game, (nb_game>1)?"s":"", nb_player);
for(i=0; i < nb_game ; i++) {
for(i=0; i < nb_game_end ; i++) {
if(duration[i] > 3600)
fprintf(file, "game %d (%d hour%s %d minute%s %d second%s) : ", i+1, duration[i]/3600, ((duration[i]/3600)>1?"s":""), (duration[i]%3600)/60, (((duration[i]%3600)/60)?"s":""), (duration[i]%3600)%60, (((duration[i]%3600)%60)>1?"s":""));
fprintf(file, "game %d (%d hour%s %d minute%s %d second%s) : ", i+1, duration[i]/3600, ((duration[i]/3600)>1?"s":""), (duration[i]%3600)/60, ((((duration[i]%3600)/60)>1)?"s":""), (duration[i]%3600)%60, (((duration[i]%3600)%60)>1?"s":""));
else if(duration[i] > 60)
fprintf(file, "game %d (%d minute%s %d second%s) : ", i+1, duration[i]/60, ((duration[i]/60)?"s":""), duration[i]%60, ((duration[i]%60)>1?"s":""));
fprintf(file, "game %d (%d minute%s %d second%s) : ", i+1, duration[i]/60, (((duration[i]/60)>1)?"s":""), duration[i]%60, ((duration[i]%60)>1?"s":""));
else
fprintf(file, "game %d (%d second%s) : ", i+1, duration[i], ((duration[i]%60)>1?"s":""));
if(winner[i] >=0 && winner[i] < nb_player)
fprintf(file, "won by player %d\n", i+1);
if(winner[i] >= 0 && winner[i] < nb_player)
fprintf(file, "won by player %d (%s)\n", winner[i]+1, player_state[winner[i]].name);
else
fputs("no player has won\n", file);
}
if(nb_game != nb_game_end)
fputs("match stopped abruptly\n", file);
fputs("\n", file);
fclose(file);
}
@ -284,6 +287,7 @@ void save(const char *filename, const int nb_game, const int nb_player, const ti
else
fprintf(stderr, "cannot open file \"%s\"\n", filename);
#endif
printf("→ %d \n", nb_game_end);
}
int main(int argc, char** argv) {
@ -298,7 +302,8 @@ int main(int argc, char** argv) {
struct move_t movement, previous_movement;
int first_move, next_move;
int nb_game, nb_player, nb_game_end, nb_player_end;
int i, j;
int i, j, k;
char *error;
/* heure de début du match et tableaux pour stocker les gagnants et la durée des parties */
time_t time_start_match, *duration_games;
@ -329,35 +334,46 @@ int main(int argc, char** argv) {
srand(time(NULL));
/* on charge les IA */
/* on charge les IA et on initialise les joueurs « réels » */
j = 3;
for( i = 0; i < nb_player ; i++ ) {
/* on choisit de placer un joueur réel ou une stratégie */
if( (rand()%(nb_player-i)) < (argc-j) ) {
/* on ajoute une stratégie */
/* on prépare pour le nom */
snprintf(player_state[i].name,50,"player %d",i+1);
player_state[i].name[49] = '\0';
/* on choisit de placer un joueur réel ou une stratégie */
if( (rand()%(nb_player-i)) < (argc-j) ) {
/* on ajoute une stratégie */
#ifdef debug
fprintf(stderr,"strategy %s (%d)\n", argv[j], i);
fprintf(stderr,"strategy %s (%d)\n", argv[j], i);
#endif
if( (player_state[i].ia_lib_p = dlopen(argv[j], RTLD_LAZY)) == NULL ) {
player_state[i].ia_lib_p = dlopen(argv[j], RTLD_LAZY);
if( (error = dlerror()) != NULL ) {
#ifdef debug
fprintf(stderr,"error while loading %s : %s (%d)\n", argv[j], dlerror(), i);
fprintf(stderr,"error while loading %s : %s (%d)\n", argv[j], error, i);
#endif
/* échec du chargement, on décharge toutes les stratégies précédement chargées */
for( j=0 ; j<i ; j++ )
if( player_state[j].ia_lib_p )
dlclose(player_state[j].ia_lib_p);
return 5;
} else
/* on initialise la bibliothèque */
ia_call_function(player_state[i], ia_lib_init, NULL, "toto"); // TODO : what name should be used ?
j++;
} else {
/* on ajoute un joueur réel */
/* échec du chargement, on décharge toutes les stratégies précédement chargées */
for( j=0 ; j<i ; j++ )
if( player_state[j].ia_lib_p )
dlclose(player_state[j].ia_lib_p);
return 5;
} else
/* on initialise la bibliothèque */
ia_call_function(player_state[i], ia_lib_init, NULL, player_state[i].name); /* x = &x puisque c'est un tableau */
j++;
} else {
/* on ajoute un joueur réel */
#ifdef debug
fprintf(stderr,"real player (%d)\n", i);
fprintf(stderr,"real player (%d)\n", i);
#endif
player_state[i].ia_lib_p = NULL;
}
player_state[i].ia_lib_p = NULL;
}
/* on vérifie le nom */
if(player_state[i].name[49] != '\0') {
#ifdef debug
fprintf(stderr,"warning : the length of the player's name %d must be to 49 characters maximum.\n", i);
#endif
} else
player_state[i].name[49] = '\0';
}
#ifdef debug
@ -369,14 +385,14 @@ int main(int argc, char** argv) {
if((winner_games = (int*) malloc(nb_game*sizeof(int))) == NULL) {
#ifdef debug
fputs("malloc error\n", stderr);
return 5;
#endif
return 6;
}
if((duration_games = (time_t*) malloc(nb_game*sizeof(time_t))) == NULL) {
#ifdef debug
fputs("malloc error\n", stderr);
return 5;
#endif
return 6;
}
@ -401,7 +417,8 @@ int main(int argc, char** argv) {
/* on note l'heure du début du jeu */
time_start_match = time(NULL);
for( nb_game_end = 0 ; nb_game_end < nb_game ; nb_game_end++ ) {
int quit = 0;
for( nb_game_end = 0 ; nb_game_end < nb_game && !quit ; nb_game_end++ ) {
#ifdef debug
fprintf(stderr,"%d %s left\n", nb_game, nb_game>1?"games":"game");
#endif
@ -427,7 +444,7 @@ int main(int argc, char** argv) {
printf("(GUI) Rendering board, branch %d\n", player_state[0].branch);
display_render_board(gui_res, game_state, player_state[0].branch);
SDL_Flip(gui_res.screen);
/* display_animsg(gui_res, game_state, player_state[0].branch, "Début de la manche", 1200); TODO */
display_animsg(gui_res, game_state, player_state[0].branch, "Début de la manche", 1200);
#ifdef debug
for(i=0;i<121; i++)
@ -438,10 +455,10 @@ int main(int argc, char** argv) {
/* chaque joueur joue */
i = 0;
nb_player_end = 0;
while(nb_player_end < nb_player-1) {
while(nb_player_end < nb_player-1 && !quit) {
#ifdef debug
fprintf(stderr, "joueur %d\n", i);
fprintf(stderr, "joueur %d (%s)\n", i, player_state[i].name);
#endif
game_state_copy = game_state;
previous_movement.start_pos=-1; previous_movement.end_pos=-1;
@ -452,13 +469,13 @@ int main(int argc, char** argv) {
/* on suppose qu'on a une stratégie */
ia_call_function(player_state[i], ia_next_move, &next_move, &game_state_ia_copy, first_move, &movement);
/* on cherche à valider le coup */
printf("(GUI) Moving pawn %d → hole %d\n", movement.start_pos, movement.end_pos);
quit += display_animove_pawn(gui_res, game_state_copy, player_state[i].branch, movement.start_pos, movement.end_pos);
if(valid_move(movement, previous_movement, player_state[i], game_state_copy, start_position, !next_move)) {
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) valide\n", movement.start_pos, movement.end_pos);
#endif
/* on effectue le mouvement */
printf("(GUI) Moving pawn %d → hole %d\n", movement.start_pos, movement.end_pos);
display_animove_pawn(gui_res, game_state_copy, player_state[i].branch, movement.start_pos, movement.end_pos);
game_state_copy.board[movement.start_pos]=none;
game_state_copy.board[movement.end_pos]=player_state[i].branch;
if(next_move)
@ -468,7 +485,7 @@ int main(int argc, char** argv) {
if(winner(player_state[i], start_position, game_state)) {
nb_player_end=nb_player /* la partie se termine */;
puts("le joueur a gagné");
winner_games[nb_game_end] = i+1;
winner_games[nb_game_end] = i;
ia_call_function(player_state[i], ia_end_game, NULL);
}
}
@ -476,16 +493,25 @@ int main(int argc, char** argv) {
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) invalide\n",movement.start_pos, movement.end_pos);
#endif
/* display_animsg(gui_res, game_state, player_state[i].branch, "Coup non valide", 1000); TODO*/
display_animsg(gui_res, game_state, player_state[i].branch, "Coup non valide", 1000);
if(++(player_state[i].error)==3) {
nb_player_end++;
puts("perdu");
/* on enlève les pions du joueur */
j=0;
k=0;
do
if(game_state.board[j] == i+1) {
game_state.board[j] = none;
k++;
}
while(++j < 121 && k < 10);
ia_call_function(player_state[i], ia_end_game, NULL);
}
next_move=0;
}
first_move=0;
} while(next_move);
} while(next_move && !quit);
/* on sélectionne le joueur suivant */
j=i;
do {
@ -493,13 +519,13 @@ int main(int argc, char** argv) {
i%=nb_player;
} while(player_state[i].error >= 3);
/* le joueur a joué, rotation du plateau à l'écran vers le suivant */
if(nb_player_end < nb_player-1) { // TODO condition identique au while, c'est pour quand on arrive à la fin de la partie, ne pas tourner le plateau
if( (nb_player_end < nb_player-1) && !quit) { // TODO condition identique au while, c'est pour quand on arrive à la fin de la partie, ne pas tourner le plateau
printf("(GUI) Rotating board, branch %d → %d\n", player_state[j].branch, player_state[i].branch);
display_anirotate_board(gui_res, game_state, player_state[j].branch, player_state[i].branch + (j+1!=i)*6 /*places des joueurs actuel et suivant, ∈[1-6]*/);
quit += display_anirotate_board(gui_res, game_state, player_state[j].branch, player_state[i].branch + (j+1!=i)*6 /*places des joueurs actuel et suivant, ∈[1-6]*/);
}
}
puts("fin de la partie");
/* display_animsg(gui_res, game_state, player_state[i].branch, "Manche terminée", 1000); TODO*/
display_animsg(gui_res, game_state, player_state[i].branch, "Manche terminée", 1200);
/* pour les joueurs qui n'ont pas perdu */
for (i=0; i < nb_player ; i++)
if(player_state[i].error < 3)
@ -509,15 +535,16 @@ int main(int argc, char** argv) {
}
/* appel de end_match */
for( i=0 ; i < nb_player ; i++ )
for( i=0 ; i < nb_player ; i++ ) {
if( player_state[i].ia_lib_p ) {
ia_call_function(player_state[i], ia_end_match, NULL);
/* on décharge toutes les stratégies */
dlclose(player_state[i].ia_lib_p);
}
}
/* on enregistre le résultat du jeu dans le fichier */
save(score_filename, nb_game, nb_player, time_start_match, winner_games, duration_games);
save(score_filename, player_state, nb_game, nb_game_end-(quit?1:0), nb_player, time_start_match, winner_games, duration_games);
free(winner_games);
free(duration_games);


Loading…
Cancel
Save