Browse Source

add function « winner »

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

+ 19
- 18
main.c View File

@ -17,10 +17,9 @@ enum api_function_t {ia_lib_init, ia_start_match, ia_start_game, ia_end_game , i
struct player_state_t {
enum bool play;
size_t branch;
unsigned int error;
void *ia_lib_p;
size_t pawn[10];
};
enum bool char_to_int(char *argv, int *nombre) {
@ -139,21 +138,16 @@ ssize_t move_calculation(size_t index, enum direction_t move) {
}
}
enum bool valid_move(struct move_t move, struct player_state_t player, struct game_state_t game) {
size_t src, j;
enum bool valid_move(const struct move_t move, const struct player_state_t player, const struct game_state_t game) {
size_t j;
ssize_t dest, dest2;
src = 0;
do
if(move.start_pos == player.pawn[src])
break;
while (++src < 10);
if(src == 10)
if(game.board[move.start_pos] != (player.branch)+1)
return false; /* la case de départ ne comporte pas le pion du joueur */
/* on regarde autour */
j = 0;
do {
if((dest = move_calculation(src,j)) != -1) {
if((dest = move_calculation(move.start_pos, j)) != -1) {
switch(((dest == move.end_pos)?1:0)+((game.board[dest] == none)?2:0)) {
case 0:
/* saut */
@ -176,6 +170,17 @@ enum bool valid_move(struct move_t move, struct player_state_t player, struct ga
return false;
}
enum bool winner(struct player_state_t player, const size_t start_position[6][10], const struct game_state_t game) {
size_t final_branch, j;
final_branch = player.branch+(player.branch>2?-3:3);
j = 0;
do
if(game.board[start_position[final_branch][j]] != (player.branch)+1 )
return false;
while(++j < 10);
return true;
}
int main(int argc, char** argv) {
const size_t start_position[6][10] = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{19, 20, 21, 22, 32, 33, 34, 44, 45, 55},
@ -187,7 +192,6 @@ int main(int argc, char** argv) {
struct game_state_t game_state;
int nb_game, nb_player;
enum bool win;
size_t branch;
int i, j;
@ -270,13 +274,10 @@ int main(int argc, char** argv) {
/* initialisation : on place les pions */
for( i=0 ; i < nb_player ; i++ ) {
player_state[i].play = true;
player_state[i].error = 0;
branch = star_branch(nb_player, i);
for( j=0 ; j < 10 ; j++ ) {
player_state[i].pawn[j] = start_position[branch][j];
game_state.board[start_position[branch][j]] = i+1;
}
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;
}
for(i=0;i<121; i++)


Loading…
Cancel
Save