示例#1
0
ADAPT_STAT *get_adapt_stat(const int dim, const char *name,
                           const char *prefix, int info,
                           ADAPT_STAT *adapt_stat)
{
    FUNCNAME("get_adapt_stat");
    ADAPT_STAT  adapt_stand = {nil, 1.0, 2, 30, 2, nil, nil, nil, nil,
                               nil, 0.0, 0.0, nil, nil, nil, nil,
                               dim, 0, dim, 1, 0.5, 0.1, 0.9, 0.2,
                               0.6, 0.1, 0.1
                              };
    char  key[1024];
    ADAPT_STAT *adapt;

    if (dim == 0) {
        WARNING("Adaption does not make sense for dim == 0!\n");
        return nil;
    }

    if (adapt_stat)
        adapt = adapt_stat;
    else {
        adapt = MEM_ALLOC(1, ADAPT_STAT);
        *adapt = adapt_stand;
        if (name)
            adapt->name = strdup(name);
        if (!adapt->name  && prefix)
            adapt->name = strdup(prefix);
    }

    if (!prefix)
        return(adapt);

    sprintf(key, "%s->tolerance", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->tolerance);
    sprintf(key, "%s->p", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->p);
    sprintf(key, "%s->max_iteration", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->max_iteration);
    sprintf(key, "%s->info", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->info);

    sprintf(key, "%s->refine_bisections", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->refine_bisections);
    sprintf(key, "%s->coarsen_allowed", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->coarsen_allowed);
    if (adapt->coarsen_allowed)
    {
        sprintf(key, "%s->coarse_bisections", prefix);
        GET_PARAMETER(info-2, key, "%d", &adapt->coarse_bisections);
    }

    init_strategy(funcName, prefix, info-1, adapt);

    return(adapt);
}
示例#2
0
ADAPT_INSTAT *get_adapt_instat(const int dim, const char *name,
                               const char *prefix, int info,
                               ADAPT_INSTAT *adapt_instat)
{
    FUNCNAME("get_adapt_instat");
    ADAPT_INSTAT adapt_stand = {nil,
        {{nil,
                1.0, 2.0, 1, -1, nil, nil, nil, nil,
                nil, 0.0, 0.0, nil, nil, nil, nil,
                dim, 0, dim, 2, 0.5, 0.1, 0.9, 0.2,
                0.6, 0.1, 0.1}},
        {{nil,
                1.0, 2.0, 1, -1, nil, nil, nil, nil,
                nil, 0.0, 0.0, nil, nil, nil, nil,
                dim, 1, dim, 2, 0.5, 0.1, 0.9, 0.2,
                0.6, 0.1, 0.1}},
        0.0, 0.0, 1.0, 0.01, nil, nil, nil, nil, nil,
        0, 0, 1.0, 0.1, 0.4, 0.4, 1.0, 0.3,
        0.7071, 1.4142, 8
    };
    char  key[1024];
    ADAPT_INSTAT *adapt;

    if (dim == 0) {
        WARNING("Adaption does not make sense for dim == 0!\n");
        return nil;
    }

    if (adapt_instat)
        adapt = adapt_instat;
    else
    {
        adapt = MEM_ALLOC(1, ADAPT_INSTAT);
        *adapt = adapt_stand;
        if (name)
            adapt->name = strdup(name);
        if (!adapt->name  && prefix)
            adapt->name = strdup(prefix);
    }

    if (!prefix)
        return(adapt);

    sprintf(key, "%s initial", adapt->name);
    adapt->adapt_initial->name = strdup(key);
    sprintf(key, "%s space", adapt->name);
    adapt->adapt_space->name = strdup(key);

    /*---8<---------------------------------------------------------------------*/
    /*---   and now, all other entries                                       ---*/
    /*--------------------------------------------------------------------->8---*/

    sprintf(key, "%s->start_time", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->start_time);
    adapt->time = adapt->start_time;
    sprintf(key, "%s->end_time", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->end_time);
    sprintf(key, "%s->timestep", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->timestep);
    sprintf(key, "%s->strategy", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->strategy);
    sprintf(key, "%s->max_iteration", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->max_iteration);
    sprintf(key, "%s->tolerance", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->tolerance);
    sprintf(key, "%s->rel_initial_error", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->rel_initial_error);
    sprintf(key, "%s->rel_space_error", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->rel_space_error);
    sprintf(key, "%s->rel_time_error", prefix);
    GET_PARAMETER(info-1, key, "%f", &adapt->rel_time_error);
    sprintf(key, "%s->time_theta_1", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->time_theta_1);
    sprintf(key, "%s->time_theta_2", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->time_theta_2);
    sprintf(key, "%s->time_delta_1", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->time_delta_1);
    sprintf(key, "%s->time_delta_2", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->time_delta_2);
    sprintf(key, "%s->info", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->info);

    /*---8<---------------------------------------------------------------------*/
    /*---  initialization of the adapt_stat for the initial grid             ---*/
    /*--------------------------------------------------------------------->8---*/

    /*---  tolerance does not have to be initialized, is set!                ---*/
    adapt->adapt_initial->tolerance = adapt->tolerance*adapt->rel_initial_error;
    sprintf(key, "%s->initial->p", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->adapt_initial->p);
    sprintf(key, "%s->initial->max_iteration", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->adapt_initial->max_iteration);
    sprintf(key, "%s->initial->info", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_initial->info);
    if (adapt->adapt_initial->info < 0)
        adapt->adapt_initial->info = adapt->info-2;

    sprintf(key, "%s->initial->refine_bisections", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_initial->refine_bisections);
    sprintf(key, "%s->initial->coarsen_allowed", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_initial->coarsen_allowed);
    if (adapt->adapt_initial->coarsen_allowed)
    {
        sprintf(key, "%s->initial->coarse_bisections", prefix);
        GET_PARAMETER(info-2, key, "%d", &adapt->adapt_initial->coarse_bisections);
    }
    sprintf(key, "%s->initial", prefix);
    init_strategy(funcName, key, info-1, adapt->adapt_initial);


    /*---8<---------------------------------------------------------------------*/
    /*---  initialization of the adapt_stat for the time-step iteration      ---*/
    /*--------------------------------------------------------------------->8---*/

    /*---  tolerance does not have to be initialized, is set!                ---*/
    adapt->adapt_space->tolerance   = adapt->tolerance*adapt->rel_space_error;
    sprintf(key, "%s->space->p", prefix);
    GET_PARAMETER(info-2, key, "%f", &adapt->adapt_space->p);
    sprintf(key, "%s->space->max_iteration", prefix);
    GET_PARAMETER(info-1, key, "%d", &adapt->adapt_space->max_iteration);
    sprintf(key, "%s->space->info", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_space->info);
    if (adapt->adapt_space->info < 0)
        adapt->adapt_space->info = adapt->info-2;

    sprintf(key, "%s->space->refine_bisections", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_space->refine_bisections);
    sprintf(key, "%s->space->coarsen_allowed", prefix);
    GET_PARAMETER(info-2, key, "%d", &adapt->adapt_space->coarsen_allowed);
    if (adapt->adapt_space->coarsen_allowed)
    {
        sprintf(key, "%s->space->coarse_bisections", prefix);
        GET_PARAMETER(info-2, key, "%d", &adapt->adapt_space->coarse_bisections);
    }
    sprintf(key, "%s->space", prefix);
    init_strategy(funcName, key, info-1, adapt->adapt_space);

    return(adapt);
}
示例#3
0
int main() {
	Game *game = init_game();
	char username[50];
	Deck *deck = init_deck();
	Strategy *strategy;
	int exchange[] = {1,2,4,5,0};
	int i;
	Player *playerptr;
	
	strategy = init_strategy(4, &exchange[0]);

	printf("\n\nWelcome to Five-Card Draw!\n\n\nPlease enter your name: ");
	scanf("%s",username);
	
	/*add players to game*/
	/*add live user first*/
	game_insert_player(game, NULL, username, HUMAN);
	/*add three CPU players*/
	game_insert_player(game, game->head->prev, "Dennis Ritchie", CPU);
	game_insert_player(game, game->head->prev, "Brian Kernighan", CPU);
	game_insert_player(game, game->head->prev, "Kyle Loudon", CPU);
	
	printf("\n\nWelcome, %s. You will begin with $%.2f in chips.\n\n",game->human->name, game->human->chips);
	
	/*human player is dealer in the first game. dealer designation rotates afterward*/
	set_dealer(game, game->human);
	
	while (game->continue_game) { 
		/*
			player may quit by pressing CTRL+C at any time and will be given the option to continue after the game
			has been settled. if the player does not have enough in chips remaining to pay the ante, s/he will be 
			removed from the table.
		*/

		/*announce dealer*/
		if(game->dealer->type == HUMAN)
			printf("You are the dealer.\n\n");
		else
			printf("%s is the dealer.\n\n", game->dealer->name);
		
		/*players ante*/
		playerptr = game->dealer->next;
		for (i = 0; i < NUMPLAYERS; ++i) {
			make_bet(game, playerptr, (float) ANTE);
			playerptr = playerptr->next;
		}
		
		/*deal cards*/
		shuffle_deck(deck, NUMCARDS, NULL, 0);
		printf("Dealing...\n\n");
		deal_game(deck, game);
		
		/*bet_round(game);*/
		
		/*if (game->folded < 4) {*/
			exchange_round(game, deck);
		/*} else {
			printf("Just one player remains.\n");
			settle_game(game);
		}
		
		bet_round(game);
		*/
		
		settle_game(game);
	}
	
	printf("Thanks for playing!\n\n\n");
	
	return 0;
}