]> git.cworth.org Git - ttt/blobdiff - kub/kub.c
Kub can now _reliably_ shuffle deck and deal in 1-4 players
[ttt] / kub / kub.c
index 0f538594b3b8040317f73e0ea6fc77c3f71b8c9f..5377fc47534bd0dff12cc3aab470ba507d90cdcf 100755 (executable)
--- 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;
     }
 }