Ejemplo n.º 1
0
int try_all_perm_random_restart(int n, int restart_at, int stop_after) {
  int curr_best = get_current_score(n, dbname);
  int n1_score = get_current_score(n-1, dbname);
  perm deck(n), best(n);
  init_deck(deck);
  shuffle_no_fix(deck);
  int highest_count_so_far = 0;
  int count = 0;
  int iterations = 0;
  // while (next_perm_swap1(deck)) {
  //while (next_perm_rand_swap2(deck)) {
  while (next_permutation(deck.begin(), deck.end())) {
  //while (next_perm_seq_pair(deck)) {
  //while (next_perm_all_pair(deck)) {
  //while (next_perm_all_pair_rev(deck)) {
    ++iterations;
    if (iterations >= stop_after) return highest_count_so_far;

    ++count;

    if (deck[0] == 1) {
      shuffle_no_fix(deck);
      count = 0;
      ping('1');
    }

    if (count >= restart_at) {
      count = 0;
      shuffle_no_fix(deck);
      ping('.');
    }

    const int score = do_all_top_swops_copy(deck);

    /*
    // Heuristic cut-off: if the last number is home, then re-start if
    // the previous perm's best score plus the current score is less
    // than the highest score so far.
    if (deck.back() == n && n1_score + score < highest_count_so_far) {
      count = 0;
      shuffle_no_fix(deck);
      ping('c');
    }
    */

    if (score > highest_count_so_far) {
      highest_count_so_far = score;
      best = deck;
      if (highest_count_so_far > curr_best) {
        ping('!');
        //int diff = highest_count_so_far - curr_best;
        curr_best = highest_count_so_far;
        set_current_perm(n, best, dbname);
      }
    }
  }
  //  cout << best << " (n=" << n << ", optimal_count=" << highest_count_so_far 
  //       << ")" << endl;
  return highest_count_so_far;
}
Ejemplo n.º 2
0
void test_perm() {
  vector<int> deck(4);
  init_deck(deck);
  while (next_permutation(deck.begin(), deck.end())) {
    cout << deck << endl;
  }
  cout << "done\n";
}
Ejemplo n.º 3
0
JNIEXPORT void JNICALL Java_handevaluator_jni_JNIHandEvaluator_runOverhead(JNIEnv *env , jclass clazz, jint trials) {
	init_random(trials);
	deck_struct deck;
	init_deck(&deck);
	int i, j;
	char cards[7];
	for (i=0; i < trials; i++) {
		reset_deck(&deck);
		for (j=0; j < 7; j++) {
			cards[j] = draw_random_card(&deck); 
		}
	}
}
Ejemplo n.º 4
0
void main(){

	stats s;	
	s.plys_in_game = 6;
	s.bigblind = 20;
	s.cards_on_table = 0;
	
	init_players(&s);
	init_window(&s);		
	
	while(1){	
		init_deck(dec);
		s.cards_on_table = 0;
		game(&s);
	}

}
Ejemplo n.º 5
0
int main() {
	std::vector<int> deck, dealtCards;
	init_deck(deck);
	std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
	for (int n = 0; n < 50; ++n) {
		dealtCards = deal(deck, PREFLOP); 
		std::cout << "######## New Deal #######" << std::endl;
		for (auto i = dealtCards.begin(); i != dealtCards.end(); ++i) {
			std::cout << hexToCard(*i) << std::endl;
		}
	}
	std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
	std::cout << duration << std::endl;

	return 0;
}
Ejemplo n.º 6
0
main()
{
    int deck[52], hand[5], freq[10];
    int a, b, c, d, e, i, j;

    // seed the random number generator
    srand48( getpid() );

    // initialize the deck
    init_deck( deck );

    // zero out the frequency array
    for ( i = 0; i < 10; i++ )
        freq[i] = 0;

    // loop over every possible five-card hand
    for(a=0;a<48;a++)
    {
	hand[0] = deck[a];
	for(b=a+1;b<49;b++)
	{
	    hand[1] = deck[b];
	    for(c=b+1;c<50;c++)
	    {
		hand[2] = deck[c];
		for(d=c+1;d<51;d++)
		{
		    hand[3] = deck[d];
		    for(e=d+1;e<52;e++)
		    {
			hand[4] = deck[e];

			i = eval_5hand( hand );
			j = hand_rank(i);
			freq[j]++;
		    }
		}
	    }
	}
    }

    for(i=1;i<=9;i++)
	printf( "%15s: %8d\n", value_str[i], freq[i] );
}
Ejemplo n.º 7
0
void setup(){
  init_deck();
  shuffle();
  
  dealer[0] = top();
  dealer[1] = top();
  dnumcards = 2;
  dnum = dealer[0]->value + dealer[1]->value;
  
  player[0] = top();
  player[1] = top();
  pnumcards = 2;
  pnum = player[0]->value + player[1]->value;
  
  send_msg("msg", client_sock);
  sprintf(String, "Dealer: X %s\n", dealer[1]->rep);
  send_msg(String, client_sock);
  
  send_msg("msg", client_sock);
  sprintf(String, "Player: %s %s\n", player[0]->rep, player[1]->rep);
  send_msg(String, client_sock);
    
}
Ejemplo n.º 8
0
int main()
{
    struct board_t boardd;
    int player = 0;

    init_board(&boardd);



    init_deck(&boardd.Player[player].deck);
    card_generator( &boardd, player);
    //deck_from_file(&boardd, "ggop.txt", player);
    init_player(&boardd.Player[player]);
    init_manapool(&boardd.Player[player].manapool);


    init_deck(&boardd.Player[player + 1].deck);
    //card_generator( *boardd, player + 1);
    deck_from_file(&boardd, "ggopme.txt", player + 1);
    init_player(&boardd.Player[player +1]);
    init_manapool(&boardd.Player[player + 1].manapool);

    int i;
    for(i = 0; i < 5; i++){
        turn_begin( &boardd.Player[player]);
        turn_begin( &boardd.Player[player + 1]);
    }

    int card;
    int board_num = 0;
    int board_num2 = 0;
    int choice;
    player++;

    do{
  

    if ( bot(&boardd,&board_num2) == 1 ) board_num2++; 

    PrintBoard(boardd);

   


    scanf("%d",&choice);
    if (choice > 0 && choice <= 5 ){
        card = choice - 1;
        if (play_card(&boardd, player, card, board_num) == 1 ) {
                boardd.Card_Positions[board_num][player] = 0;
                board_num++;
		boardd.Player[player].manapool.left -= boardd.Player[player].cards_in_hand[card].magic_cost;
		
		/*struct card_t card_to_use;
		draw_card(&boardd.Player[player].deck, &card_to_use);
		boardd.Player[player].cards_in_hand[card] = card_to_use;*/
		
        }
    }
	
    PrintBoard(boardd);

    turn_end(&boardd, player, &board_num, &board_num2);

    PrintBoard(boardd);
	
    char a; scanf("%s",&a);

    //system("cls");
    printf("\033[2J\033[1;1H");

	if(board_num >= 5) board_num = 0;
	if(board_num2 >= 5) board_num2 = 0;

    }while(boardd.Player[player].health > 0 && boardd.Player[1 - player].health > 0);

    if(boardd.Player[player].health > 0) printf("Ti pechelish ;) \n");
        else printf("Ti gubish\n");

    return 0;
}
Ejemplo n.º 9
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;
}
int main (int argc, char *argv[]) {
	Card deck[DECK_SIZE];
	Card starting_deck[DECK_SIZE];

	char in_message[MAX_MESSAGE_LENGTH];
	char out_message[MAX_MESSAGE_LENGTH];
	int mode = 0; //encrypt = 0, decrypt = 1

	if (argc != 1) {
		printf("usage: SolitareEncryption1\n");
		printf("SEKEY environment variable must be set to the key value\n");
		exit(1);
	}

	init_deck(starting_deck);
	while (1) {
		//set the deck to the key starting position
		memcpy(deck, starting_deck, sizeof(Card) * DECK_SIZE);
		print_deck(deck);
		if (!mode) {
			printf("Enter message to be encrypted (type '/help' for help):\n");
		} else {
			printf("Enter message to be decrypted (type '/help' for help):\n");
		}
		fflush(stdout);
		if (fgets(in_message, MAX_MESSAGE_LENGTH, stdin) == NULL) {
			printf("fgets failure\n");
			exit(1);
		}

		//get rid of the newline from fgets
		int i;
		for (i = 0; in_message[i] != '\0'; i++) {
			if (in_message[i] == '\n') {
				in_message[i] = '\0';
				break;
			}
		}
		if (!strcmp(in_message, "/quit")) {
			break;
		} else if (!strcmp(in_message, "/encrypt")) {
			mode = 0;
			printf("Encryption mode\n");
		} else if (!strcmp(in_message, "/decrypt")) {
			mode = 1;
			printf("Decryption mode\n");
		} else if (!strcmp(in_message, "/help")) {
			printf("/encrypt: switch to encryption mode\n"
				   "/decrypt: switch to decryption mode\n"
				   "/quit: quit program\n");
		} else {
			if (!mode) {
				printf("Unencrypted: %s\n", in_message);
				printf("Encrypted: %s\n",
						encrypt(deck, in_message, out_message));
			} else {
				printf("Encrypted: %s\n", in_message);
				printf("Decrypted: %s\n",
						decrypt(deck, in_message, out_message));
			}
		}
	}
	return 0;
}
Ejemplo n.º 11
0
int main () {
	srand(time(NULL));	

	board_t *board = NULL;

	/*int finished = 0;
	char blank[255];
	
	while(!finished)
	{
		write(1,"\E[H\E[2J",7);

		print_menu();
		int option = validate_input(1, 4);

		switch(option)
		{
			case 1: */
				board = (board_t*)malloc(sizeof(board_t));

				init_deck(&board->p[P_ONE].deck);	
				load_deck(&board->p[P_ONE].deck, "player_deck.csv");
				switch(shuffleChoice()){
					case 1:{
						if(RandomShuffling(&(board->p[P_ONE].deck))){
							file_save(&(board->p[P_ONE].deck));
							//printf("ns\n");
						}
						break;
					}
					case 2:{
						if(manaOrder(&(board->p[P_ONE].deck))){
							file_save(&(board->p[P_ONE].deck));
						}
						break;
					}
					case 3:{
						if(lifeOrder(&(board->p[P_ONE].deck))){
							file_save(&(board->p[P_ONE].deck));
						}
						break;
					}
					case 4:{
						if(attackOrder(&(board->p[P_ONE].deck))){
							file_save(&(board->p[P_ONE].deck));
						}
						break;
					}
					case 5:{
						if(costattackOrder(&(board->p[P_ONE].deck))){
							file_save(&(board->p[P_ONE].deck));
						}
						break;
						}	
				}
				//printf("ns\n");
				//printf("ls\n");
				init_deck(&board->p[P_TWO].deck);	
				load_deck(&board->p[P_TWO].deck, "enemy_deck.csv");
				//printf("ns\n");
				//printf("ls\n");
				// the board inits the player and the player needs a deck
				/*board_init(board);	
				printf("ls\n");
				if(rand() % 2 == 0)
				{
					printf("The enemy goes first!\n");
					sleep(2);
					write(1,"\E[H\E[2J",7);
					turn_begin(&board->p[P_TWO]);
					print_field(*board);
					sleep(1);
					write(1,"\E[H\E[2J",7);

					enemy_AI(board);
					
					write(1,"\E[H\E[2J",7);
					print_field(*board);
					sleep(1);
					printf("\nEnemy's turn is over!\n");
					//--board.p[P_TWO].manapool.max_mana; // the turn_begin function
					//--board.p[P_TWO].manapool.current_mana; // increments these 
				}
				else
				{
					printf("The player goes first!\n");
					sleep(2);
				}

				write(1,"\E[H\E[2J",7);

				int i;
				while(1)
				{
					turn_begin(&board->p[P_ONE]);
					turn_begin(&board->p[P_TWO]);	

					print_field(*board);
					printf("\nGo, go, go!! :)\n");
					
					if(turn(board))
					{
						break;
					}
					
					write(1,"\E[H\E[2J",7);
					print_field(*board);
					sleep(1);
					printf("\nPlayer's turn is over!\n");
					sleep(2);
					
					enemy_AI(board);
					
					write(1,"\E[H\E[2J",7);
					print_field(*board);
					sleep(1);
					printf("\nEnemy's turn is over!\n");
					sleep(2);
					
					turn_attacks(board);
					printf("End-of-turn attacks!\n");
					
					if(is_player_dead(board->p[P_ONE]))
					{
						printf("Game over! \nThe player is dead!\n");
						break;
					}
					if(is_player_dead(board->p[P_TWO]))
					{
						printf("Game over! \nThe enemy is dead!\n");
						break;
					}
					
					sleep(2);
					write(1,"\E[H\E[2J",7);
				}
				free(board);
				break;
			case 2:
				write(1,"\E[H\E[2J",7);
				read_file("instructions.txt");
				printf("\n\nEnter anything to go back to the main menu.\n");
				scanf("%s", blank); 
				break;
			case 3:
				write(1,"\E[H\E[2J",7); 
				read_file("about.txt");
				printf("\nEnter anything to go back to the main menu.\n");
				scanf("%s", blank);
				break;
			case 4: 
				printf("Thank you for using this software! Please call us to get your free Awesome Person certificate!\n");
				
				finished = 1;
				break;
		}
	}*/
	return 0;
}
Ejemplo n.º 12
0
int main()
{

	//struct card_t card_to_push;
	struct card_t one = { "card_one", 1, 7, 3 };
	struct card_t two = { "card_two", 3, 7, 10 };
	struct card_t three = { "card_three", 3, 2, 5 };
	struct card_t four = { "card_four", 1, 2, 2 };
	struct card_t five = { "card_five", 3, 2, 4 };
	struct card_t six = { "card_six", 5, 4, 1 };
	struct card_t seven = { "card_seven", 6, 2, 4 };
	struct card_t eight = { "card_eight", 1, 7, 2 };
	struct card_t nine = { "card_nine", 3, 7, 1 };
	struct card_t ten = { "card_ten", 3, 2, 2 };
	struct card_t eleven = { "card_eleven", 1, 2, 2 };
	struct card_t twelve = { "card_twelve", 3, 2, 4 };
	struct card_t thirteen = { "card_thirteen", 5, 4, 2 };
	struct card_t fourteen = { "card_fourteen", 2, 2, 1 };
	
	struct card_t one_special = { "special_card_one", -1, 0, 1};// +5 life
	struct card_t two_special = { "special_card_two", -2, 0, 1};// *2 card_power and +5 card_life 
	struct card_t three_special = { "special_card_three", -3, 0, 5};// +1 mana
	struct card_t shaman = {"shaman", 4, 5, 2};
	struct card_t grivna = {"grivna", 6, 3, 3};
	struct card_t kolelo = {"kolelo", 5, 2, 2};
	
	//printf("%d\n", attack(&one, &two));
	
	//---------------------------------------------------------------
	//struct deck_t player_deck;
	//struct player_t player;
	
	struct player_t first_player;
	struct player_t second_player;
	struct deck_t first_player_deck;
	struct deck_t second_player_deck;
	first_player.name_player = "TGS";
	second_player.name_player = "Baba Gusi";
	init_deck(&first_player_deck);
	init_deck(&second_player_deck);
	
	push_card(one, &first_player_deck);
	push_card(two, &first_player_deck);
	push_card(three, &first_player_deck);
	push_card(four, &first_player_deck);
	push_card(five, &first_player_deck);
	push_card(six, &first_player_deck);
	push_card(seven, &first_player_deck);
	
	push_card(eight, &first_player_deck);
	push_card(nine, &first_player_deck);
	push_card(ten, &first_player_deck);
	
	push_card(eleven, &second_player_deck);
	push_card(twelve, &second_player_deck);
	push_card(thirteen, &second_player_deck);
	push_card(fourteen, &second_player_deck);
	
	push_card(one_special, &second_player_deck);
	push_card(two_special, &second_player_deck);
	push_card(three_special, &second_player_deck);
	push_card(shaman, &second_player_deck);
	push_card(grivna, &second_player_deck);
	push_card(kolelo, &second_player_deck);
	
	print_stack(first_player_deck);
	print_stack(second_player_deck);

	Null_player_hand(&first_player);
	Null_player_hand(&second_player);
	
	init_player(&first_player_deck, &first_player);
	
	init_player(&second_player_deck, &second_player);
	down_hp(&second_player,5);
	up_hp(&second_player,2);
	
	
	
	turn_begin(&first_player_deck, &first_player);
	
	turn_begin(&second_player_deck, &second_player);
	printf("\n--------------------------------------------------------");
	printf("\nTGS hand:\n");
	print_cards_in_hand(&first_player);
	printf("\n--------------------------------------------------------");
	printf("\nBaba Gusi hand:\n");
	print_cards_in_hand(&second_player);
	//play_card_from_hand(&player, "card_four");
	
	
	struct board_t board;

	init_board(&board);
	
	turn_end(&board, &first_player, 0);
	turn_end(&board, &second_player, 1);
	turn_end(&board, &first_player, 0);
	turn_end(&board, &second_player, 1);
	turn_end(&board, &first_player, 0);
	turn_end(&board, &second_player, 1);
	turn_end(&board, &first_player, 0);
	turn_end(&board, &second_player, 1);
	turn_end(&board, &first_player, 0);
	turn_end(&board, &second_player, 1);
	turn_end(&board, &first_player, 0);

	
	
	can_play_card(&board, &first_player, 0, six, 3);// players 0 or 1
	
	play_card(&board, &first_player, 0, six, 3);// players 0 or 1
	
	can_play_card(&board, &second_player, 1, grivna, 3);// players 0 or 1
	
	play_card(&board, &second_player, 1, grivna, 3);// players 0 or 1
	
	print_board(board, first_player, second_player, 1);
	printf("\n--------------------------------------------------------\n");
	
	
	turn_begin(&first_player_deck, &first_player);
	
	turn_begin(&second_player_deck, &second_player);
	
	play_card(&board, &first_player, 0, seven, 2);// players 0 or 1
	
	play_card(&board, &second_player, 1, two_special, 3);// players 0 or 1

	print_board(board, first_player, second_player, 3);
	printf("\n--------------------------------------------------------\n");
	
	
	turn_begin(&first_player_deck, &first_player);
	
	turn_begin(&second_player_deck, &second_player);
	
	play_card(&board, &first_player, 0, eight, 1);// players 0 or 1
	
	play_card(&board, &second_player, 1, shaman, 1);// players 0 or 1

	print_board(board, first_player, second_player, 5);
	
	
	printf("\n--------------------------------------------------------\n");
	
	winner(first_player, second_player);
	
	printf("\n--------------------------------------------------------\n");
	
	/*
	//---------------------------------------------------------------
	// manapool
	struct manapool_t pool;
	init_mana(&pool);
	print_manapool(&pool);
	push_mana(&pool);//2 mana
	push_mana(&pool);//3 mana
	push_mana(&pool);//4 mana
	push_mana(&pool);//5 mana
	push_mana(&pool);//6 mana
	printf("\nCan we put card?(yes-1, no-0): %d\n", can_put_card(one, &pool));
	take_mana(one, &pool);//1 mana
	push_mana(&pool);//7 mana
	printf("\nCan we put card?(yes-1, no-0): %d\n", can_put_card(two, &pool));
	take_mana(two, &pool);//3 mana
	push_mana(&pool);//8 mana
	push_mana(&pool);//9 mana
	push_mana(&pool);//10 mana
	push_mana(&pool);//10 mana
	printf("\nCan we put card?(yes-1, no-0): %d\n", can_put_card(two, &pool));
	take_mana(three, &pool);//6 mana
	push_mana(&pool);//=> 10 mana
	//---------------------------------------------------------------
	// board
	//---------------------------------------------------------------
	
	

*/



return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[]){

	char *ep;
	u_long temp, trials;
	struct state *gp;
	struct state game;
	
	/* structures to hold the stats */
	struct stats b_before;
	struct stats b_after;
	struct stats b_both;
	struct stats m_card, m_dice;
	
	struct stats game_stats;	

	struct card deck[DECKS*CARDS*SUITS];

	int i;
	int card_index = 0;
	float outcome; 
	int die_total;

	gp = &game;

	if (argc != 2)
		usage();

	temp = strtoul(argv[1], &ep, 10);
	if (*argv[1] == '\0'|| *ep != '\0'){
		fprintf(stderr, "%s - not a number\n", argv[1]);
		usage();
	}

	if (argv[1][0] == '-'){
		fprintf(stderr, "%s - no negative numbers\n", argv[1]);
		usage();
	}
	
	if (( errno == ERANGE && temp == ULONG_MAX ) && (temp > 1)){
		fprintf(stderr, "%s - value out of range\n", argv[1]);
		usage();
	}
	trials = temp;

	/* seed the random number generator */
	srand(time(NULL));
	
	/* initialize the deck */
	init_deck(deck);
	
	/* shuffle the cards */
	shuffle(deck);

	/* initialize the statistics structs */
	init_stats(&b_before);
	init_stats(&b_after);
	init_stats(&b_both);
	init_stats(&m_card);
	init_stats(&m_dice);
	init_stats(&game_stats);

	/* run the simulations */
	for (i = 0 ; i < trials ; i++){
		
		/* initialize the game */
		game.die_1 = rand()%6 + 1;
		game.die_2 = rand()%6 + 1;
		die_total = game.die_1 + game.die_2;

		game.before_card = deck[card_index];
		game.after_card = deck[card_index+1];
		card_index+=2;		

		/* beat before */
		if (die_total == 12)
			outcome = 4.0; 
		else if ( die_total > game.before_card.value )
			outcome = 1.0;
		else if ( die_total < game.before_card.value )
			outcome = -1.0;
		else
			outcome = 0.0;							
		inc_update_stats(&b_before, outcome, i+1);
 		inc_update_stats(&game_stats, outcome, i+1);
		
		/* beat after */
		if (die_total == 12)
			outcome = 4.0; 
		else if ( die_total > game.after_card.value )
			outcome = 1.0;
		else if ( die_total < game.after_card.value )
			outcome = -1.0;
		else
			outcome = 0.0;

		inc_update_stats(&b_after, outcome, i+1);
		inc_update_stats(&game_stats, outcome, i+1);
		
		/* beat both */
		if (die_total == 12)
			outcome = 6.0;

		else if ( (die_total > game.after_card.value) &&
		    (die_total > game.before_card.value) )
			outcome = 3.0;
		else if ( (die_total == game.after_card.value) &&
			(die_total == game.before_card.value))
			outcome = 0.0;	
		else
			outcome = -1.0;

		inc_update_stats(&b_both, outcome, i+1);
		inc_update_stats(&game_stats, outcome, i+1);
		
		/* match card */
		outcome = match_card(gp);
		inc_update_stats(&m_card, outcome, i+1);
		inc_update_stats(&game_stats, outcome, i+1);
		
		/* match dice */
		outcome = match_dice(gp);
		inc_update_stats(&m_dice, outcome, i+1);
 		inc_update_stats(&game_stats, outcome, i+1);

		if(card_index > (DECKS*SUITS*CARDS - 52)){
			card_index = 0;
			shuffle(deck);
		}

	}

	/* finalize the standard deviations */	
	b_before.stddev = sqrt(b_before.stddev/(trials-1));
	b_after.stddev = sqrt(b_after.stddev/(trials-1));
	b_both.stddev = sqrt(b_both.stddev/(trials-1));
	m_card.stddev = sqrt(m_card.stddev/(trials-1));
	m_dice.stddev = sqrt(m_dice.stddev/(trials-1));
	game_stats.stddev = sqrt(game_stats.stddev/(trials-1));

	/* Print the statistics of the each game's square */
	printf("Beat Before:\n");
	print_stats(&b_before);	
	printf("Beat After:\n");
	print_stats(&b_after);	
	printf("Beat Both:\n");
	print_stats(&b_both);	
	printf("Match Card:\n");
	print_stats(&m_card);	
	printf("Match Dice:\n");
	print_stats(&m_dice);	
	
	/* Print the game's overall EV */
	printf("Game Statistics:\n");
	print_stats(&game_stats);	

	return 0;

}
Ejemplo n.º 14
0
int main() {
    int i;
    double start_time;
    card_t high_card1[5];   /* now we're going to generate several hands and test the ranking stuff */
    card_t high_card2[5];
    card_t one_pair1[5];
    card_t one_pair2[5];
    card_t two_pair1[5];
    card_t two_pair2[5];
    card_t three_kind1[5];
    card_t three_kind2[5];
    card_t straight1[5];
    card_t straight2[5];
    card_t flush1[5];
    card_t flush2[5];
    card_t full_house1[5];
    card_t full_house2[5];
    card_t four_kind1[5];
    card_t four_kind2[5];
    card_t straight_flush1[5];
    card_t straight_flush2[5];
    card_t royal_flush1[5];
    card_t royal_flush2[5];
    card_t deck[52];

    init_deck(deck);

    /* construct high card */
    high_card1[0] = deck[26];       /* Ace of Hearts */
    high_card1[1] = deck[5];        /* 6 of Clubs */
    high_card1[2] = deck[28];       /* 3 of Hearts */
    high_card1[3] = deck[19];       /* 7 of Diamonds */
    high_card1[4] = deck[48];       /* 10 of Spades */

    high_card2[0] = deck[9];        /* 10 of Clubs */
    high_card2[1] = deck[20];       /* 8 of Diamonds */
    high_card2[2] = deck[18];       /* 6 of Diamonds */
    high_card2[3] = deck[16];       /* 4 of Diamonds */
    high_card2[4] = deck[40];       /* 2 of Spades */

    /* one pair */
    one_pair1[0] = deck[43];        /* 5 of Spades */
    one_pair1[1] = deck[30];        /* 5 of Hearts */
    one_pair1[2] = deck[14];        /* 2 of Diamonds */
    one_pair1[3] = deck[6];         /* 7 of Clubs */
    one_pair1[4] = deck[3];         /* 4 of Clubs */

    one_pair2[0] = deck[43];        /* 5 of Spades */
    one_pair2[1] = deck[4];         /* 5 of Clubs */
    one_pair2[2] = deck[21];        /* 9 of Diamonds */
    one_pair2[3] = deck[44];        /* 6 of Spades */
    one_pair2[4] = deck[33];        /* 8 of Hearts */

    /* two pair */
    two_pair1[0] = deck[26];        /* Ace of Hearts */
    two_pair1[1] = deck[0];         /* Ace of Clubs */
    two_pair1[2] = deck[20];        /* 8 of Diamonds */
    two_pair1[3] = deck[46];        /* 8 of Spades */
    two_pair1[4] = deck[28];        /* 3 of Hearts */

    two_pair2[0] = deck[9];         /* 10 of Clubs */
    two_pair2[1] = deck[22];        /* 10 of Diamonds */
    two_pair2[2] = deck[14];        /* 2 of Diamonds */
    two_pair2[3] = deck[40];        /* 2 of Spades */
    two_pair2[4] = deck[46];        /* 8 of Spades */

    /* three of a kind */
    three_kind1[0] = deck[26];      /* Ace of Hearts */
    three_kind1[1] = deck[0];       /* Ace of Clubs */
    three_kind1[2] = deck[39];      /* Ace of Spades */
    three_kind1[3] = deck[19];      /* 7 of Diamonds */
    three_kind1[4] = deck[50];      /* Queen of Spades */

    three_kind2[0] = deck[21];      /* 9 of Diamonds */
    three_kind2[1] = deck[47];      /* 9 of Spades */
    three_kind2[2] = deck[8];       /* 9 of Clubs */
    three_kind2[3] = deck[6];       /* 7 of Clubs */
    three_kind2[4] = deck[13];      /* Ace of Diamonds */

    /* straight */
    straight1[0] = deck[43];        /* 5 of Spades */
    straight1[1] = deck[5];         /* 6 of Clubs */
    straight1[2] = deck[32];        /* 7 of Hearts */
    straight1[3] = deck[7];         /* 8 of Clubs */
    straight1[4] = deck[21];        /* 9 of Diamonds */

    straight2[0] = deck[40];        /* 2 of Spades */
    straight2[1] = deck[2];         /* 3 of Clubs */
    straight2[2] = deck[29];        /* 4 of Hearts */
    straight2[3] = deck[43];        /* 5 of Spades */
    straight2[4] = deck[31];        /* 6 of Hearts */

    /* flush */
    flush1[0] = deck[14];           /* 2 of Diamonds */
    flush1[1] = deck[20];           /* 8 of Diamonds */
    flush1[2] = deck[17];           /* 5 of Diamonds */
    flush1[3] = deck[13];           /* Ace of Diamonds */
    flush1[4] = deck[18];           /* 6 of Diamonds */

    flush2[0] = deck[14];           /* 2 of Diamonds */
    flush2[1] = deck[16];           /* 4 of Diamonds */
    flush2[2] = deck[18];           /* 6 of Diamonds */
    flush2[3] = deck[21];           /* 9 of Diamonds */
    flush2[4] = deck[22];           /* 10 of Diamonds */

    /* full house */
    full_house1[0] = deck[19];      /* 7 of Diamonds */
    full_house1[1] = deck[45];      /* 7 of Spades */
    full_house1[2] = deck[6];       /* 7 of Clubs */
    full_house1[3] = deck[1];       /* 2 of Clubs */
    full_house1[4] = deck[27];      /* 2 of Hearts */

    full_house2[0] = deck[22];      /* 10 of Diamonds */
    full_house2[1] = deck[9];       /* 10 of Clubs */
    full_house2[2] = deck[35];      /* 10 of Hearts */
    full_house2[3] = deck[6];       /* 7 of Clubs */
    full_house2[4] = deck[19];      /* 7 of Diamonds */

    /* four of a kind */
    four_kind1[0] = deck[24];       /* Queen of Diamonds */
    four_kind1[1] = deck[37];       /* Queen of Hearts */
    four_kind1[2] = deck[50];       /* Queen of Spades */
    four_kind1[3] = deck[11];       /* Queen of Clubs */
    four_kind1[4] = deck[43];       /* 5 of Spades */

    four_kind2[0] = deck[21];       /* 9 of Diamonds */
    four_kind2[1] = deck[34];       /* 9 of Hearts */
    four_kind2[2] = deck[47];       /* 9 of Spades */
    four_kind2[3] = deck[8];        /* 9 of Clubs */
    four_kind2[4] = deck[19];       /* 7 of Diamonds */

    /* straight flush */
    straight_flush1[0] = deck[43];  /* 5 of Spades */
    straight_flush1[1] = deck[44];  /* 6 of Spades */
    straight_flush1[2] = deck[45];  /* 7 of Spades */
    straight_flush1[3] = deck[46];  /* 8 of Spades */
    straight_flush1[4] = deck[47];  /* 9 of Spades */

    straight_flush2[0] = deck[5];   /* 6 of Clubs */
    straight_flush2[1] = deck[6];   /* 7 of Clubs */
    straight_flush2[2] = deck[7];   /* 8 of Clubs */
    straight_flush2[3] = deck[8];   /* 9 of Clubs */
    straight_flush2[4] = deck[9];   /* 10 of Clubs */

    /* royal flush */
    royal_flush1[0] = deck[35];     /* 10 of Hearts */
    royal_flush1[1] = deck[36];     /* Jack of Hearts */
    royal_flush1[2] = deck[37];     /* Queen of Hearts */
    royal_flush1[3] = deck[38];     /* King of Hearts */
    royal_flush1[4] = deck[26];     /* Ace of Hearts */

    royal_flush2[0] = deck[9];      /* 10 of Clubs */
    royal_flush2[1] = deck[10];     /* Jack of Clubs */
    royal_flush2[2] = deck[11];     /* Queen of Clubs */
    royal_flush2[3] = deck[12];     /* King of Clubs */
    royal_flush2[4] = deck[0];      /* Ace of Clubs */

    /* print each of the above hands and pass them to rank_hand() 
     * A star is printed next to the one that's greater, or both if they're equal */
    printf("1: ");
    print_hand(high_card1);
    if (handcmp(high_card1, high_card2) > -1) 
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(high_card2);
    if (handcmp(high_card2, high_card1) > -1)
        printf(" *");
    puts("");
    puts("-----");
    
    printf("1: ");
    print_hand(one_pair1);
    if (handcmp(one_pair1, one_pair2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(one_pair2);
    if (handcmp(one_pair2, one_pair1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(two_pair1);
    if (handcmp(two_pair1, two_pair2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(two_pair2);
    if (handcmp(two_pair2, two_pair1) > -1)
        printf(" *");
    puts("");
    puts("-----");
    
    printf("1: ");
    print_hand(three_kind1);
    if (handcmp(three_kind1, three_kind2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(three_kind2);
    if (handcmp(three_kind2, three_kind1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(straight1);
    if (handcmp(straight1, straight2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(straight2);
    if (handcmp(straight2, straight1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(flush1);
    if (handcmp(flush1, flush2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(flush2);
    if (handcmp(flush2, flush1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(full_house1);
    if (handcmp(full_house1, full_house2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(full_house2);
    if (handcmp(full_house2, full_house1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(four_kind1);
    if (handcmp(four_kind1, four_kind2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(four_kind2);
    if (handcmp(four_kind2, four_kind1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(straight_flush1);
    if (handcmp(straight_flush1, straight_flush2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(straight_flush2);
    if (handcmp(straight_flush2, straight_flush1) > -1)
        printf(" *");
    puts("");
    puts("-----");

    printf("1: ");
    print_hand(royal_flush1);
    if (handcmp(royal_flush1, royal_flush2) > -1)
        printf(" *");
    puts("");
    printf("2: ");
    print_hand(royal_flush2);
    if (handcmp(royal_flush2, royal_flush1) > -1)
        printf(" *");
    puts("");

    /* testing comparations using simple ranks */
    printf("\n    Royal Flush ");
    if (handcmp(royal_flush1, high_card1) > -1)
        putchar('>');
    else
        putchar('<');
    puts(" High Card");

    printf("       One Pair ");
    if (handcmp(one_pair1, straight_flush1) > -1)
        putchar('>');
    else
        putchar('<');
    puts(" Straight Flush");

    printf(" Four of a Kind ");
    if (handcmp(four_kind1, two_pair1) > -1)
        putchar('>');
    else
        putchar('<');
    puts(" Two Pair");

    printf("Three of a Kind ");
    if (handcmp(three_kind1, full_house1) > -1)
        putchar('>');
    else
        putchar('<');
    puts(" Full House");

    printf("          Flush ");
    if (handcmp(flush1, straight1) > -1)
        putchar('>');
    else
        putchar('<');
    puts(" Straight");

    /* and now, benchmarking! */
    start_time = get_time();
    for (i = 0; i < 5000000; i++) {
        rank_hand(royal_flush1);
    }
    printf("\nProcessed 5,000,000 Royal Flushes in %f\n", get_time() - start_time);

    start_time = get_time();
    for (i = 0; i < 5000000; i++) {
        handcmp(one_pair1, one_pair2);
    }
    printf("Compared 5,000,000 sets of One Pair in %f\n", get_time() - start_time);

    return 0;
}