void check_good_shuffle(){ int i; Deck * deck1 = malloc(sizeof(Deck)); Deck * deck2 = malloc(sizeof(Deck)); build_deck(deck1); build_deck(deck2); shuffle_deck(deck2); sort_cards(deck1->card, DECK_SIZE); sort_cards(deck2->card, DECK_SIZE); print(deck1->card, DECK_SIZE); print(deck2->card, DECK_SIZE); for (i = 0; i < DECK_SIZE; ++i) if (deck1->card[i].value != deck2->card[i].value) { printf("Bad Shuffle\n"); return; } printf("Good Shuffle\n"); return; }
int test_queue(){ int i,j; Card card; Deck * deck = malloc(sizeof(Deck)); Deck * deck2 = malloc(sizeof(Deck)); Hand * hand = malloc(sizeof(Hand)); build_deck(deck); shuffle_deck(deck); build_deck(deck2); shuffle_deck(deck2); i = 0; for (;;){ printf("Initialized Deck and Hand\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); for (j = 0; j < HAND_SIZE; ++j){ card = deal_card(deck); hand->card[j] = card; } printf("\nAdded cards to hand\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); for (j = 0; j < HAND_SIZE; ++j){ add_card(deck, hand->card[j]); hand->card[j].suite = -1; hand->card[j].value = -1; } printf("\nPut cards back into deck\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); printf("\n\n"); i++; if (i == 100) break; } sort_cards(deck->card, DECK_SIZE); sort_cards(deck2->card, DECK_SIZE); for (i = 0; i < DECK_SIZE; ++i) if (deck->card[i].value != deck2->card[i].value) printf("Bad Shuffle\n"); printf("Good Shuffle\n"); return 0; }
void pick_up_pile_and_face_down(struct game_t *game, const int face_down_choice) { struct player_t *player = &game->players[game->current_player]; const struct card_t card = player->face_down[face_down_choice]; pick_up_pile(game); deal_to_hand(player, card); sort_cards(player->hand, player->hand_size); remove_from_face_down(player, &card); }
/* should be self-explanatory, I'm putting the values of the exchange struct from the deck back into the hand */ void insert_exchange_into_hand(Exchange*e, Hand*h, int size){ int i; Card temp; i = 0; sort_cards(h->card, HAND_SIZE); for (i=0;i<size;i++){ temp = e->card[i]; e->card[i] = h->card[i]; h->card[i] = temp; } }
void build_stubs(stub_t * stubs, int stubs_len) { int stub_i = 0; for (; stub_i < stubs_len; stub_i++) { stub_t * stub = &stubs[stub_i]; sort_cards(stub); stub->type = parse_stub_type(stub); reorder_straight(stub); set_groups(stub); } sort_stubs(stubs, stubs_len); }
void pick_up_pile(struct game_t *game) { struct player_t *player = &game->players[game->current_player]; int i; for (i = 0; i < game->pile_size; i++) deal_to_hand(player, game->pile[i]); sort_cards(player->hand, player->hand_size); game->pile_size = 0; set_last_move_pickup(game->last_move, player->name); }
static void play_from_hand(struct game_t *game, const struct card_t *to_lay, const int num_cards) { int i; struct player_t *player = &game->players[game->current_player]; for (i = 0; i < num_cards; i++) { add_to_pile(game->pile, &game->pile_size, to_lay[i]); remove_from_hand(player, &to_lay[i]); if (game->deck_size > 0 && (player->hand_size < game->num_cards_each)) { deal_to_hand(player, game->deck[game->deck_size-1]); game->deck_size--; } } sort_cards(player->hand, player->hand_size); }
static void deal(struct game_t *game) { int i, j; struct player_t *player = NULL; struct card_t *deck = game->deck; int *deck_size = &game->deck_size; for (i = 0; i < game->num_players; i++) { player = &game->players[i]; for (j = 0; j < game->num_cards_each; j++) { deal_to_hand(player, deck[*deck_size]); (*deck_size)--; deal_to_face_up(player, deck[*deck_size]); (*deck_size)--; deal_to_face_down(player, deck[*deck_size]); (*deck_size)--; } sort_cards(player->hand, player->hand_size); } }
void sort_cards2(char* cards, int len, int lz) { change_12_2_A2(cards, len); sort_cards(cards, len, change_12_2_A2(lz)); change_A2_2_12(cards, len); }
void sort_player_cards(PPlayer player) { sort_cards(player->cards,player->num_cards); }
bool is_hand_legal(PHand hand) { sort_cards(hand->cards,hand->num_cards); return get_hand_type(hand) != ILLEGAL; }