From: Kevin Worth Date: Sat, 4 Feb 2006 18:33:43 +0000 (+0000) Subject: Kub can now _reliably_ shuffle deck and deal in 1-4 players X-Git-Url: https://git.cworth.org/git?p=ttt;a=commitdiff_plain;h=5358a2e76c2157d2f5f958b05a57cf65bb973ca5 Kub can now _reliably_ shuffle deck and deal in 1-4 players --- diff --git a/kub/kub.c b/kub/kub.c index 0f53859..5377fc4 100755 --- a/kub/kub.c +++ b/kub/kub.c @@ -137,7 +137,7 @@ static void deck_deal(game_t *game, deck_t *deck) { card_t temp; int rand_card; - int i, j, last = deck->num_cards, newline; + int i, j, newline; printf ("How many players(1-4) should I deal in? "); game->num_players = getchar(); @@ -153,9 +153,9 @@ static void deck_deal(game_t *game, deck_t *deck) { for (j = 0; j < 14; ++j) { - rand_card = ((last + 1.0) * rand()) / (RAND_MAX + 1.0); + rand_card = ((deck->num_cards + 1.0) * rand()) / (RAND_MAX + 1.0); temp = deck->cards[rand_card]; - deck->cards[rand_card] = deck->cards[last]; + 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; @@ -192,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; } }