/* input: a player pointer * output: none * return: none * comments: initializes the player */ void player_init(player * foo) { foo->cash = 0; foo->value1 = 0; foo->value2 = 0; hand_init(&(foo->one)); hand_init(&(foo->two)); }
/* input: a player pointer and a shoe pointer * output: none * return: none * comments: resets the player after a hand */ void player_reset(player * foo, shoe * bar) { while (!hand_empty(&foo->one)) take_card(bar, hand_deq(&foo->one)); while (!hand_empty(&foo->two)) take_card(bar, hand_deq(&foo->two)); foo->value1 = 0; foo->value2 = 0; hand_init(&foo->one); hand_init(&foo->two); }
/* input: a dealer pointer, a shoe pointer * output: none * return: none * comments: resets the dealer */ void dealer_reset(dealer * foo, shoe * bar) { card tmp; card_init(&tmp); while (!hand_empty(&foo->one)) { tmp = hand_deq(&foo->one); take_card(bar, tmp); } foo->value = 0; hand_init(&foo->one); }
void warlock_init (void) { #ifdef DEBUG g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif preferences_init (); highlight_init (); preferences_dialog_init (); profile_dialog_init (); text_strings_dialog_init (); hand_init (warlock_get_widget ("left_hand_label"), warlock_get_widget ("right_hand_label")); status_init (warlock_get_widget ("status_table")); compass_init (warlock_get_widget ("compass_table")); warlock_entry_init (warlock_get_widget ("warlock_entry")); macro_init (); macro_dialog_init (); warlock_time_init (); warlock_views_init (); warlock_log_init (); script_init (); }
void player_init(Player *player, int chips){ player->hand = (Hand *)malloc(sizeof(Hand)); hand_init(player->hand); player->chips = chips; }
int mc_findbest(Hand *hand, bool player){ int i, j, k, n; double score = 0.0; int best=0; double best_ev=0; Hand *handcopy = (Hand *)malloc(sizeof(Hand)); Deck *deck = (Deck *)malloc(sizeof(Deck)); hand_init(handcopy); deck_init(deck); if(hand->numCards < NUM_CARDS){ printf("Error: Can only advise on a full hand.\n"); return 0; } hand_sort(hand); for(i=0; i<=31; i++){/*0-31 corresponds to 00000-11111 in binary, 1 means discard that card*/ unsigned int seed = time(NULL); score = 0; for(j=0; j<NUM_TRIALS; j++){ for(k=0; k<NUM_CARDS; k++){ hand_add_card(handcopy, deck_remove_card(deck, hand->cards[k])); } if(handcopy->numCards < NUM_CARDS){ hand_print(hand); hand_print(handcopy); printf("Error: Could not find all cards in deck"); return 0; } seed = (seed+5); deck_shuffle(deck, seed); n=i; for(k=NUM_CARDS-1; k>=0; k--){ if(n >= power(2, k)){ n -= power(2, k); hand_discard(handcopy, k, deck); } } hand_draw5(handcopy, deck); score += imp_score_hand(handcopy); for(k=0; k<NUM_CARDS; k++){ hand_discard(handcopy, k, deck); } } if(score/NUM_TRIALS > best_ev){ best = i; best_ev = score/NUM_TRIALS; } } if(player){ printf("Current hand score: %.2f\n", imp_score_hand(hand)); printf("Best expected hand score: %.2f\n", best_ev); printf("Advise discarding cards:\n"); for(k=NUM_CARDS-1; k>=0; k--){ if(best >= power(2, k)){ best -= power(2, k); printf("\t"); printf("%d: ", k); card_print(hand->cards[k]); printf("\n"); } } printf("\n"); } hand_destroy(handcopy, deck); free(handcopy); deck_destroy(deck); free(deck); return best; }
/* input: a dealer pointer * output: none * return: none * comments: intitializes the dealer */ void dealer_init(dealer * foo) { hand_init(&foo->one); foo->value = 0; foo->cnt = 0; }