Browse Source

Suppression des pions d'un joueur qui a perdu (correction).

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

+ 27
- 8
main.c View File

@ -35,6 +35,13 @@ enum bool char_to_int(char *argv, int *nombre) {
return (error!=argv);
}
unsigned int number_length(int n) {
int ret=0;
n=(n<0?ret++,-n:n);
while(ret++, (n/=10) > 0);
return ret;
}
enum bool ia_call_function(const struct player_t player, const enum api_function_t api_function, void *result, ...) {
va_list ap;
char* error;
@ -303,7 +310,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, k;
char *error;
char *buffer;
/* 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;
@ -347,9 +354,9 @@ int main(int argc, char** argv) {
fprintf(stderr,"strategy %s (%d)\n", argv[j], i);
#endif
player_state[i].ia_lib_p = dlopen(argv[j], RTLD_LAZY);
if( (error = dlerror()) != NULL ) {
if( (buffer = dlerror()) != NULL ) {
#ifdef debug
fprintf(stderr,"error while loading %s : %s (%d)\n", argv[j], error, i);
fprintf(stderr,"error while loading %s : %s (%d)\n", argv[j], buffer, i);
#endif
/* échec du chargement, on décharge toutes les stratégies précédement chargées */
for( j=0 ; j<i ; j++ )
@ -444,7 +451,13 @@ 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);
if( (buffer = (char*) malloc( (23+number_length(nb_game_end+1)+number_length(nb_game)) *sizeof(char) ) ) == NULL)
display_animsg(gui_res, game_state, player_state[0].branch, "Début de la manche", 1200);
else {
snprintf(buffer, 22+number_length(nb_game_end+1)+number_length(nb_game), "Début de la manche %d/%d", nb_game_end+1, nb_game);
display_animsg(gui_res, game_state, player_state[0].branch, buffer, 1200);
free(buffer);
}
#ifdef debug
for(i=0;i<121; i++)
@ -493,19 +506,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);
if( (buffer = (char*) malloc( 28 *sizeof(char) ) ) == NULL)
display_animsg(gui_res, game_state, player_state[i].branch, "Coup non valide", 1000);
else {
snprintf(buffer, 28, "Coup non valide (%d erreur%s)", player_state[i].error+1, (player_state[i].error+1>1)?"s":"");
display_animsg(gui_res, game_state, player_state[i].branch, buffer, 1200);
free(buffer);
}
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) {
do {
if(game_state.board[j] == player_state[i].branch) {
game_state.board[j] = none;
k++;
}
while(++j < 121 && k < 10);
} while(++j < 121 && k < 10);
ia_call_function(player_state[i], ia_end_game, NULL);
}
next_move=0;


Loading…
Cancel
Save