@ -256,7 +256,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 , 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 ;
@ -266,16 +266,18 @@ void save(const char *filename, const int nb_game, const int nb_player, const ti
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 ( 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 " : " " ) ) ;
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 " : " " ) ) ;
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 ( 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 ) ;
}
}
fputs ( " \n " , file ) ;
fclose ( file ) ;
@ -401,7 +403,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
@ -438,7 +441,7 @@ 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 ) ;
@ -452,13 +455,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 )
@ -485,7 +488,7 @@ int main(int argc, char** argv) {
next_move = 0 ;
}
first_move = 0 ;
} while ( next_move ) ;
} while ( next_move & & ! quit ) ;
/* on sélectionne le joueur suivant */
j = i ;
do {
@ -493,9 +496,9 @@ 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 " ) ;
@ -517,7 +520,7 @@ int main(int argc, char** argv) {
}
/* 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 , nb_game , nb_game_end , nb_ player , time_start_match , winner_games , duration_games ) ;
free ( winner_games ) ;
free ( duration_games ) ;