Browse Source

On ne tourne le plateau que vers un joueur qui n'a pas perdu.

master
Bastien 8 years ago
committed by Squiz
parent
commit
7d3c3b0741
1 changed files with 46 additions and 45 deletions
  1. +46
    -45
      main.c

+ 46
- 45
main.c View File

@ -352,62 +352,63 @@ int main(int argc, char** argv) {
#endif
/* chaque joueur joue */
i = -1;
i = 0;
nb_player_end = 0;
while(nb_player_end < nb_player-1) {
++i;
i%=nb_player;
#ifdef debug
fprintf(stderr, "joueur %d\n", i);
#endif
/* si le joueur peut jouer */
if(player_state[i].error < 3) {
game_state_copy = game_state;
first_move = 1;
do { /* on demande la suite de coup */
movement.start_pos=-1; movement.end_pos=-1;
previous_movement.start_pos=-1; previous_movement.end_pos=-1;
game_state_ia_copy = game_state_copy;
/* 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 */
if(valid_move(movement, previous_movement, player_state[i], game_state_copy, start_position, !next_move)) {
game_state_copy = game_state;
first_move = 1;
do { /* on demande la suite de coup */
movement.start_pos=-1; movement.end_pos=-1;
previous_movement.start_pos=-1; previous_movement.end_pos=-1;
game_state_ia_copy = game_state_copy;
/* 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 */
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);
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, 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)
previous_movement=movement;
else {
game_state=game_state_copy; /* commit */
if(winner(player_state[i], start_position, game_state)) {
nb_player_end=nb_player-1 /* la partie se termine */;
puts("le joueur a gagné");
ia_call_function(player_state[i], ia_end_game, NULL);
}
/* 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, 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)
previous_movement=movement;
else {
game_state=game_state_copy; /* commit */
if(winner(player_state[i], start_position, game_state)) {
nb_player_end=nb_player-1 /* la partie se termine */;
puts("le joueur a gagné");
ia_call_function(player_state[i], ia_end_game, NULL);
}
} else {
}
} else {
#ifdef debug
fprintf(stderr, "mouvement (%d,%d) invalide\n",movement.start_pos, movement.end_pos);
fprintf(stderr, "mouvement (%d,%d) invalide\n",movement.start_pos, movement.end_pos);
#endif
/* display_text(gui_res, game_state, player_state[i].branch, "Coup non valide"); TODO*/
if(++(player_state[i].error)==3) {
nb_player_end++;
puts("perdu");
ia_call_function(player_state[i], ia_end_game, NULL);
}
next_move=0;
/* display_text(gui_res, game_state, player_state[i].branch, "Coup non valide"); TODO*/
if(++(player_state[i].error)==3) {
nb_player_end++;
puts("perdu");
ia_call_function(player_state[i], ia_end_game, NULL);
}
first_move=0;
/* le joueur a joué, rotation du plateau à l'écran vers le suivant */
printf("(GUI) Rotating board, branch %d → %d\n", player_state[i].branch, player_state[((i+1)%nb_player)].branch);
display_anirotate_board(gui_res, game_state, player_state[i].branch, player_state[((i+1)%nb_player)].branch + (((i+1)%nb_player)!=i+1)*6 /*places des joueurs actuel et suivant, ∈[1-6]*/);
} while(next_move);
}
next_move=0;
} first_move=0;
} while(next_move);
/* on sélectionne le joueur suivant */
j=i;
do {
++i;
i%=nb_player;
} while(player_state[i].error >= 3);
/* le joueur a joué, rotation du plateau à l'écran vers le suivant */
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]*/);
}
puts("fin de la partie");
/* display_text(gui_res, game_state, player_state[i].branch, "Manche terminée"); TODO*/


Loading…
Cancel
Save