{
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();
{
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;
{
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;
}
}