Browse Source

Placement des pions

master
Bastien 8 years ago
committed by Squiz
parent
commit
6ce9091761
1 changed files with 60 additions and 15 deletions
  1. +60
    -15
      main.c

+ 60
- 15
main.c View File

@ -10,6 +10,7 @@ enum bool {false, true};
struct branch_t {
void *lib_strategy_p;
size_t pawn[10];
};
enum bool char_to_int(char *argv, int *nombre) {
@ -19,16 +20,26 @@ enum bool char_to_int(char *argv, int *nombre) {
return (error!=argv);
}
/* fonction qui retourne la branche de l'étoile du joueur i */
/* not used */
size_t star_branch(int i) {
return i%2?((i-1)/2)+3:i/2;
}
/* not used */
int star_branch2(unsigned int nb_player, size_t index) {
return (nb_player>=2 && nb_player<=4 && index >= nb_player/2)?index-(nb_player>3?2:1)+3:index;
}
int main(int argc, char** argv) {
struct branch_t player_branch[6];
int i, j, nb_game, nb_player;
int i, j, k, nb_game, nb_player;
struct game_state_t game_state;
const size_t start[6][10] = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{111, 112, 113, 114, 115, 116, 117, 118, 119, 120},
{19, 20, 21, 22, 32, 33, 34, 44, 45, 55},
{65, 75, 76, 86, 87, 88, 98, 99, 100, 101},
{74, 84, 85, 95, 96, 97, 107, 108, 109, 110},
{10, 11, 12, 13, 23, 24, 25, 35, 36, 46}};
if (argc < 3 || argc > 9) {
@ -58,16 +69,16 @@ int main(int argc, char** argv) {
/* on charge les IA */
j = 3;
for(i = 0; i < nb_player ; i++) {
for( i = 0; i < nb_player ; i++ ) {
/* on choisit de placer un joueur réel ou une stratégie */
if( (rand()%(nb_player-i)) < (argc-j) ) {
/* on ajoute une stratégie */
#ifdef debug
fprintf(stderr,"strategy %s (%d)\n", argv[j], i);
#endif
if( (player_branch[i].lib_strategy_p = dlopen(argv[j], RTLD_LAZY)) == NULL) {
if( (player_branch[i].lib_strategy_p = dlopen(argv[j], RTLD_LAZY)) == NULL ) {
/* échec du chargement, on décharge toutes les stratégies précédement chargées */
for(j=0; j<i; j++) {
for( j=0 ; j<i ; j++ ) {
if(player_branch[j].lib_strategy_p != NULL)
dlclose(player_branch[j].lib_strategy_p);
}
@ -96,17 +107,17 @@ int main(int argc, char** argv) {
}
#ifdef debug
for(i=0;i<nb_player;printf("%d\n", player_branch[i].lib_strategy_p), i++);
for( i=0 ; i<nb_player ; printf("%d\n", player_branch[i].lib_strategy_p), i++ );
puts("");
#endif
/* on démarre le jeu */
for(i=0 ; i < nb_player ; i++) {
if(player_branch[i].lib_strategy_p != NULL) {
/* appel de start_match */
for( i=0 ; i < nb_player ; i++ ) {
if( player_branch[i].lib_strategy_p != NULL ) {
char* error;
void (*library_start_match_pf)(const unsigned int, const enum player_t);
*(void **) (&library_start_match_pf) = dlsym(player_branch[i].lib_strategy_p, "StartMatch");
if((error=dlerror()) == NULL) {
if( (error=dlerror()) == NULL ) {
(*library_start_match_pf)(nb_player, i+1);
}
#ifdef debug
@ -116,14 +127,48 @@ int main(int argc, char** argv) {
}
}
for( i=0; i < nb_game ; i++ ) {
#ifdef debug
fprintf(stderr,"game %d\n", i);
#endif
/* appel de start_game */
for( j=0 ; j < nb_player ; j++ ) {
if( player_branch[j].lib_strategy_p != NULL ) {
char* error;
void (*library_start_game_pf)();
*(void **) (&library_start_game_pf) = dlsym(player_branch[j].lib_strategy_p, "StartGame");
if( (error=dlerror()) == NULL ) {
(*library_start_game_pf)();
}
#ifdef debug
else
fprintf(stderr,"function EndMatch not found in stratégie (%d)\n", j);
#endif
}
}
/* on place les pions */
for( j=0 ; j < nb_player ; j++ )
for( k=0 ; k < 10 ; k++ ) {
player_branch[j].pawn[k] = start[j][k];
game_state.board[start[j][k]] = j+1;
}
/* chaque joueur joue */
}
/* fin du jeu */
for(i=0 ; i < nb_player ; i++) {
if(player_branch[i].lib_strategy_p != NULL) {
/* appel de end_match */
for( i=0 ; i < nb_player ; i++ ) {
if( player_branch[i].lib_strategy_p != NULL ) {
char* error;
void (*library_end_match_pf)();
*(void **) (&library_end_match_pf) = dlsym(player_branch[i].lib_strategy_p, "EndMatch");
if((error=dlerror()) == NULL) {
if( (error=dlerror()) == NULL ) {
(*library_end_match_pf)();
}
#ifdef debug


Loading…
Cancel
Save