Browse Source

Vidage du buffer de dlerror si on n'active pas de debug. Correction de la fonction save dans le cas où le programme a été quitté avant la fin du match.

master
Bastien 8 years ago
committed by Squiz
parent
commit
a944706e02
1 changed files with 19 additions and 16 deletions
  1. +19
    -16
      main.c

+ 19
- 16
main.c View File

@ -265,20 +265,20 @@ void save(const char *filename, const int nb_game, const int nb_game_end, const
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++) {
if(i < nb_game_end-1) {
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)>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)>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);
else
fputs("no player has won\n", file);
}
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)>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)>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);
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);
}
@ -286,6 +286,7 @@ void save(const char *filename, const int nb_game, const int nb_game_end, const
else
fprintf(stderr, "cannot open file \"%s\"\n", filename);
#endif
printf("→ %d \n", nb_game_end);
}
int main(int argc, char** argv) {
@ -301,6 +302,7 @@ int main(int argc, char** argv) {
int first_move, next_move;
int nb_game, nb_player, nb_game_end, nb_player_end;
int i, j;
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;
@ -340,9 +342,10 @@ int main(int argc, char** argv) {
#ifdef debug
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++ )
@ -520,7 +523,7 @@ int main(int argc, char** argv) {
}
/* on enregistre le résultat du jeu dans le fichier */
save(score_filename, nb_game, nb_game_end, nb_player, time_start_match, winner_games, duration_games);
save(score_filename, 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