Browse Source

On ne vérifie pas le mouvement si l'utilisateur a quitté

master
Bastien 8 years ago
committed by Squiz
parent
commit
2992cba868
1 changed files with 64 additions and 62 deletions
  1. +64
    -62
      main.c

+ 64
- 62
main.c View File

@ -301,80 +301,82 @@ int main(int argc, char **argv) {
else
/* on a un joueur réel */
quit += display_usermove_pawn(&gui_res, &game_state_ia_copy, player_state[i].branch, &movement, &next_move);
printf("(GUI) Moving pawn %d → hole %d\n", movement.start_pos, movement.end_pos);
if(first_move)
start_pos_first_move = movement.start_pos; /* on retient le point de départ pour éviter les coups qui reviendraient là où on est parti */
/* on cherche à valider le coup */
validation_movement = valid_move(start_pos_first_move, movement, previous_movement, player_state[i], game_state_copy, start_position, !next_move);
#ifdef debug
switch(validation_movement) {
case invalid: fputs("validation → invalide\n", stderr); break;
case jump: fputs("validation → jump\n", stderr); break;
case neighbour_valid: fputs("validation → voisin\n", stderr); break;
case jump_valid: fputs("validation → commit jump\n", stderr); break;
}
#endif
/* on effectue le mouvement à l'écran */
if(validation_movement != jump_valid && movement.start_pos != movement.end_pos && movement.start_pos >= 0 && movement.end_pos >= 0 && movement.start_pos < 121 && movement.end_pos < 121 && player_state[i].ia_lib_p)
quit += display_animove_pawn(&gui_res, game_state_copy, player_state[i].branch, movement.start_pos, movement.end_pos);
/* on regarde le résultat de la validation */
if(validation_movement == invalid) {
if(!quit) {
printf("(GUI) Moving pawn %d → hole %d\n", movement.start_pos, movement.end_pos);
if(first_move)
start_pos_first_move = movement.start_pos; /* on retient le point de départ pour éviter les coups qui reviendraient là où on est parti */
/* on cherche à valider le coup */
validation_movement = valid_move(start_pos_first_move, movement, previous_movement, player_state[i], game_state_copy, start_position, !next_move);
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) invalide\n",movement.start_pos, movement.end_pos);
switch(validation_movement) {
case invalid: fputs("validation → invalide\n", stderr); break;
case jump: fputs("validation → jump\n", stderr); break;
case neighbour_valid: fputs("validation → voisin\n", stderr); break;
case jump_valid: fputs("validation → commit jump\n", stderr); break;
}
#endif
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);
/* on effectue le mouvement à l'écran */
if(validation_movement != jump_valid && movement.start_pos != movement.end_pos && movement.start_pos >= 0 && movement.end_pos >= 0 && movement.start_pos < 121 && movement.end_pos < 121 && player_state[i].ia_lib_p)
quit += display_animove_pawn(&gui_res, game_state_copy, player_state[i].branch, movement.start_pos, movement.end_pos);
/* on regarde le résultat de la validation */
if(validation_movement == invalid) {
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) invalide\n",movement.start_pos, movement.end_pos);
#endif
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] == player_state[i].branch) {
game_state.board[j] = none;
k++;
}
} while(++j < 121 && k < 10);
if( player_state[i].ia_lib_p )
ia_call_function(player_state[i], ia_end_game, NULL);
}
}
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] == player_state[i].branch) {
game_state.board[j] = none;
k++;
}
} while(++j < 121 && k < 10);
if( player_state[i].ia_lib_p )
ia_call_function(player_state[i], ia_end_game, NULL);
if(validation_movement == jump || validation_movement == neighbour_valid) {
/* on effectue le mouvement */
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) valide\n",movement.start_pos, movement.end_pos);
#endif
game_state_copy.board[movement.start_pos]=none;
game_state_copy.board[movement.end_pos]=player_state[i].branch;
previous_movement=movement;
}
}
if(validation_movement == jump || validation_movement == neighbour_valid) {
/* on effectue le mouvement */
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) valide\n",movement.start_pos, movement.end_pos);
#endif
game_state_copy.board[movement.start_pos]=none;
game_state_copy.board[movement.end_pos]=player_state[i].branch;
previous_movement=movement;
}
if(validation_movement == jump_valid || validation_movement == neighbour_valid) {
/* commit */
#ifdef debug
fputs("commit\n",stderr);
#endif
game_state=game_state_copy; /* commit */
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;
if( player_state[i].ia_lib_p )
ia_call_function(player_state[i], ia_end_game, NULL);
if(validation_movement == jump_valid || validation_movement == neighbour_valid) {
/* commit */
#ifdef debug
fputs("commit\n",stderr);
#endif
game_state=game_state_copy; /* commit */
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;
if( player_state[i].ia_lib_p )
ia_call_function(player_state[i], ia_end_game, NULL);
}
}
first_move=0;
}
first_move=0;
} while(validation_movement == jump && nb_player_end < nb_player-1 && !quit);
/* on sélectionne le joueur suivant */
j=i;
do {
++i;
i%=nb_player;
} while(player_state[i].error >= 3);
} while(player_state[i].error >= 3 && !quit);
/* le joueur a joué, rotation du plateau à l'écran vers le suivant */
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);


Loading…
Cancel
Save