X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=kub%2Fkub.c;h=f9dfc3448cc94bb96a6cf32bf394f50bec5a8148;hb=a8925bfcf99614560389cafd813951d827c08d68;hp=989277e30eccf1b1d722ea7b56385d1089f3efd2;hpb=f58b697f19a0c9478ffcc0359ffbffb17796e1eb;p=ttt diff --git a/kub/kub.c b/kub/kub.c index 989277e..f9dfc34 100755 --- a/kub/kub.c +++ b/kub/kub.c @@ -71,6 +71,39 @@ static void player_init(player_t *player) card_group_init(&player->hand); } +#if 0 +static int card_group_is_run(card_group_t *card_group) +{ + int i; + int lowest = 14, highest = 0; + if (card_group->num_cards > 13 || card_group->num_cards < 3) + { + return 0; + } + for (i = 0; i < card_group->num_cards - 1; ++i) + { + if (card_group->cards[i].color != card_group->cards[i + 1].color) + { + return 0; + } + if (card_group->cards[i].number > highest) + { + highest = card_group->cards[i].number; + } + if (card_group->cards[i].number < lowest) + { + lowest = card_group->cards[i].number; + } + } + if (highest - lowest != card_group->num_cards - 1) + { + return 0; + } + return 1; +} +#endif + +#if 0 static int card_group_is_set(card_group_t *card_group) { int i; @@ -90,27 +123,46 @@ static int card_group_is_set(card_group_t *card_group) seen_color[i] = card_group->cards[i].color; for (i = 0; i < card_group->num_cards; ++i) { - seen_color[card_group->cards[i].color]++; + if (seen_color[card_group->cards[i].color] > 1) + { + return 0; + } } return 1; } +#endif -#if 0 -static void deck_deal(deck_t *deck) +static void deck_deal(game_t *game, deck_t *deck) { card_t temp; int rand_card; - int i; - for (i = 0; i < Players ) + int i, j, newline; + + printf ("How many players(1-4) should I deal in? "); + game->num_players = getchar(); + if (game->num_players == EOF) { - rand_card = ((last + 1.0) * rand()) / (RAND_MAX + 1.0); - temp = deck->cards[rand_card]; - deck->cards[rand_card] = deck->cards[last]; - deck->cards[last] = temp; + printf ("\nGoodbye.\n"); + exit (1); } + newline = getchar(); + game->num_players -= '0'; + + for (i = 0; i < game->num_players; ++i) + { + for (j = 0; j < 14; ++j) + { + rand_card = ((deck->num_cards + 1.0) * rand()) / (RAND_MAX + 1.0); + temp = deck->cards[rand_card]; + deck->cards[rand_card] = deck->cards[deck->num_cards - 1]; + game->players[i].hand.cards[j] = temp; + deck->num_cards -= 1; + game->players[i].hand.num_cards += 1; + } + } + printf ("Game dealt for %d player(s)\n", game->num_players); } -#endif static void deck_init(deck_t *deck) { @@ -125,6 +177,7 @@ static void deck_init(deck_t *deck) deck->cards[j + (i * 13) + (h * 52)].color = i; deck->cards[j + (i * 13) + (h * 52)].number = j; deck->num_cards += 1; + printf ("There are %d tiles in the deck\n", deck->num_cards); } } } @@ -139,8 +192,8 @@ static void deck_shuffle(deck_t *deck) { rand_card = ((last + 1.0) * rand()) / (RAND_MAX + 1.0); temp = deck->cards[rand_card]; - deck->cards[rand_card] = deck->cards[last]; - deck->cards[last] = temp; + deck->cards[rand_card] = deck->cards[last - 1]; + deck->cards[last - 1] = temp; } } @@ -157,6 +210,17 @@ static void deck_print(deck_t *deck) } } } + printf ("There are %d tiles in the deck\n" , deck->num_cards); +} + +static void hand_print(game_t *game) +{ + int i; + for (i = 0; i < game->players[0].hand.num_cards; ++i) + { + printf ("Player 1 has these tiles:\n"); + card_print(game->players[0].hand.cards[i]); + } } static void game_init(game_t *game) @@ -177,14 +241,15 @@ static void game_init(game_t *game) int main(void) { - deck_t deck; game_t game; srand(time(NULL)); game_init(&game); - deck_print(&deck); - + deck_print(&game.deck); + deck_deal(&game, &game.deck); + hand_print(&game); + deck_print(&game.deck); return 0; }