Esempio n. 1
0
score_best
traite_best(Game game, int num, unsigned short int state[3])
{
    int i;
    score_best sscore ;
    unsigned short int contexte[3] ;
    Game g ;
    int tir ;

    /* sauve le contexte rand */
    for (i=0 ; i<3 ; i++) {
        contexte[i] = state[i] ;
    }

    /* Fait une copie de game dans g pour faire ce qu'on veut */
    g = Game_create(game->dic) ;
    Game_copy_n(g,game) ;
    /* joue le round num dans la copie de game */
    Game_play_round(g,Results_get(game->searchresults,num)) ;
    // tir vaut 1 si retirage ; -1 si vide et 0 sinon
    tir=Game_setrack_random(g, state, 0) ;
    sscore.retir = 2 - (tir == 1) ;
    if ( tir == -1) {
        sscore.pts = 0 ;
        sscore.nb  = 0 ;
        goto fin ;
    }
    Game_search(g);
    if (Game_getnresults(g) == 0) {
        sscore.pts = 0 ;
        sscore.nb  = 0 ;
    } else {
        sscore.pts = Game_getsearchedpoints(g, 0) ;
        sscore.nb  = Game_getntotal(g) ;
    }

    if (verbeux >=2) {
        printf("<best_pts>%d</best_pts>\n", sscore.pts);
        printf("<best_sol>%d</best_sol>\n", sscore.nb);
        printf("<best_tirage>%d</best_tirage>\n", sscore.retir);
    }

    if (verbeux >= 3) {
        char mot[WORD_SIZE_MAX] ;
        char coord[COOR_SIZE_MAX];
        for (i=0 ; i<Game_getnresults(g); i++) {
            Game_getsearchedcoord(g,i,coord);
            Game_getsearchedword(g,i,mot) ;
            printf("<mot>%s - %s</mot>\n",coord, mot );
        }
    }

fin:
    Game_destroy(g) ;
    /* restaure le contexte random */
    for (i=0 ; i<3 ; i++) {
        state[i]=contexte[i] ;
    }
    return sscore ;
}
Esempio n. 2
0
void GameOverModule_onStartButton(UiNode* button, void* callbackContext) {
	GameOverModule* this = callbackContext;
	this->engine->nextModule = Game_create(this->engine)->module;
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
    Game game ;
    Dictionary dic ;
    unsigned short int state[3] ;
    static char* nomdic = "../dic/ods7.dawg" ;
    unsigned long int seed = time(0) ;
    int noprint = 0;
    int notiret = 0;
    int nbessai = 1000;
    int c;
    verbeux = 0;

    srand48(0);
    state[2] = 0xB97A ;

    opterr = 0;
    while ((c = getopt (argc, argv, "qd:n:s:e:vht")) != -1) {
        switch (c) {
            case 'v':
                verbeux++;
                break;
            case 's':
                state[2]= atoi(optarg);
                break;
            case 'e':
                nbessai = atoi(optarg);
                break;
            case 't':
                notiret = 1;
                break;
            case 'q':
                noprint = 1;
                break;
            case 'd':
                nomdic = optarg;
                break;
            case 'n':
                seed = strtoul(optarg, NULL, 10);
                break;
            case 'h' :
                help() ;
                exit(10) ;
                break ;
            case '?':
                if (isprint (optopt)) {
                    help() ;
                    fprintf (stderr, "Option inconnue `-%c'.\n", optopt);
                } else {
                    help() ;
                    fprintf (stderr, "Caractère non reconnu dans les options `\\x%x'.\n",optopt);
                }
                return 1;
            default:
                abort ();
        }
    }

    if (! nomdic) {
        help() ;
        puts("Spécifier un dictionnaire avec l'option -d (ex : -d ods7.dawg)") ;
        exit(11);
    }

    switch (Dic_load(&dic, nomdic)) {
        case 0:
            /* cas normal */
            break;
        case 1:
            help();
            printf("chargement: problème d'ouverture de %s\n",nomdic) ;
            exit(1);
            break;
        case 2:
            help();
            printf("chargement: mauvais en-tete de dictionnaire\n");
            exit(2);
            break;
        case 3:
            help();
            printf("chargement: problème 3 d'allocation mémoire\n");
            exit(3);
            break;
        case 4:
            help();
            printf("chargement: problème 4 d'allocation mémoire\n");
            exit(4);
            break;
        case 5:
            help();
            printf("chargement: problème de lecture des arcs du dictionnaire\n");
            exit(5);
            break;
        default:
            help();
            printf("chargement: problème non-repertorié\n");
            exit(6);
            break;
    }

    state[0] = seed>>16 ;
    state[1] = seed&0x0000FFFF ;

    printf("<?xml version=\"1.0\"?>\n");
    printf("<partie ");
    printf("num=\"%lu\" ",seed);
    printf("seed=\"%u\" ",state[2]);
    printf("dic=\"%s\" >\n",nomdic) ;

    game = Game_create(dic);
    main_loop(game,noprint,notiret,nbessai,state);
    Game_destroy(game);
    Dic_destroy(dic);
    return 0;
}
Esempio n. 4
0
void MainMenu_onStartButton(UiNode* button, void* callbackContext) {
    MainMenu* this = callbackContext;
    this->engine->nextModule = Game_create(this->engine)->module;
}
Esempio n. 5
0
int main()
{

    /* Random seed */
    unsigned int seed = (unsigned int)time(NULL);
    srand(seed);

    /* Moves */
    games[0] = Game_create("Scissors", "cut", "paper");
    games[1] = Game_create("Paper", "covers", "rock");
    games[2] = Game_create("Rock", "crushes", "lizard");
    games[3] = Game_create("Lizard", "poisons", "Spock");
    games[4] = Game_create("Spock", "smashes", "scissors");
    games[5] = Game_create("Scissors", "decapitate", "lizard");
    games[6] = Game_create("Lizard", "eats", "paper");
    games[7] = Game_create("Paper", "disproves", "Spock");
    games[8] = Game_create("Spock", "vaporizes", "rock");
    games[9] = Game_create("Rock", "crushes", "Scissors");

    /* Move computer or human pick up */
    int computer = 0;
    int human = 0;

    /* Initial */
    printf("Rock, paper, scissors, lizard, spock game\n");


    while(1) {
        printf("\n========\n");
        printf("Pick a choice\n");
        printf("1> Scissors\n");
        printf("2> Paper\n");
        printf("3> Rock\n");
        printf("4> Lizard\n");
        printf("5> Spock\n");
        printf("q> Quit!\n");
        printf("==========\n");

        printf("Human: ");

        char line[256];
        if(fgets(line, sizeof(line), stdin) != NULL) {

                    /* We are more civilized than this, thus will use bstrlib for comparision later. */  
            if(strcmp(line, "q\n") == 0 || strcmp(line, "Q\n") == 0) {
                printf("Thanks for playing\n");

                printf("\nResult: Wins: Human: %d, Computer: %d :: Draws: %d\n\n", hwins, cwins, draws);

                exit(0);
            }

            human = atoi(line);
            if (human < 1 || human > 5) {
                printf("Input %d out of range\n", human);                   
                continue;
            }
        }

        computer = rand() % PICK + 1;

        printf("\n");
        printf("Player picks: %s\n", choices[human]);
        printf("Computer picks: %s\n", choices[computer]);

        /* If both select same */
        if (human == computer) {
            draws++;
            printf("Draw !!\n");
            continue;
        }

        int output = result(human, computer);
        printf("%s %s %s.\n", games[output]->player1, games[output]->action, games[output]->player2);

    }   

    return 0;

}