Browse Source

déroulement du jeu (segmentation fault)

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

+ 47
- 9
main.c View File

@ -17,6 +17,7 @@ enum api_function_t {ia_lib_init, ia_start_match, ia_start_game, ia_end_game , i
struct player_t {
enum bool play;
size_t branch;
unsigned int error;
void *ia_lib_p;
@ -199,9 +200,10 @@ int main(int argc, char** argv) {
{65, 75, 76, 86, 87, 88, 98, 99, 100, 101},
{10, 11, 12, 13, 23, 24, 25, 35, 36, 46}};
struct player_t player_state[6];
struct game_state_t game_state;
int nb_game, nb_player;
enum bool win;
struct game_state_t game_state, game_state_copy, game_state_ia_copy;
struct move_t movement, previous_movement;
int first_move, next_move;
int nb_game, nb_player, nb_player_end;
int i, j;
@ -285,6 +287,7 @@ int main(int argc, char** argv) {
/* initialisation : on place les pions */
for( i=0 ; i < nb_player ; i++ ) {
player_state[i].error = 0;
player_state[i].play = true;
player_state[i].branch = star_branch(nb_player, i);
for( j=0 ; j < 10 ; j++ )
game_state.board[start_position[player_state[i].branch][j]] = (player_state[i].branch)+1;
@ -295,17 +298,52 @@ int main(int argc, char** argv) {
printf("%d %d\n",i, game_state.board[i]);
/* chaque joueur joue */
win = false;
nb_player_end = 0;
i=0;
while(!win) {
while(nb_player_end < nb_player) {
++i;
i%=nb_player;
/* on demande un mouvement */
// TODO
/* on vérifie si le mouvement est valide */
/* on effectue le déplacement */
/* si le joueur peut jouer */
if(player_state[i].play) {
game_state_copy = game_state;
first_move = 1;
do { /* on demande la suite de coup */
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((!first_move && previous_movement.end_pos == movement.start_pos && valid_move(movement, player_state[i], game_state_copy)) || (first_move && movement.start_pos == movement.end_pos) || (first_move && valid_move(movement, player_state[i], game_state_copy))) {
game_state_copy.board[movement.start_pos]=none;
game_state_copy.board[movement.end_pos]=i+1;
if(next_move)
previous_movement=movement;
else {
game_state=game_state_copy; /* commit */
if(winner(player_state[i], start_position, game_state)) {
player_state[i].play = false;
nb_player_end++;
puts("le joueur a gagné");
}
}
} else {
if(++player_state[i].error==3) {
player_state[i].play = false;
nb_player_end++;
puts("perdu");
/* on enleve les pions du joueur */
for(j=0;j<121; i++) /* mauvais */
if(game_state.board[j]==i+1)
game_state.board[j]=none;
}
next_move=0;
}
first_move=0;
} while(next_move);
}
}
puts("fin de la partie");
}


Loading…
Cancel
Save