|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 2328 (0x918) Types: TextFile Names: »shuffle.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Bj2/shuffle.c«
/* shuffle.c */ /* B.J. - Las Vegas Blackjack, Version 1.0 by Nathan Glasser nathan@brokaw.lcs.mit.edu (internet) nathan@mit-eddie.uucp (usenet) April, 1989 ------------------------------------------------------------------------------ Copyright 1989 by Nathan Glasser. You may feel free to distribute this program in its current form. Please do not remove this copyright information. */ #include "bj.h" static int num_cards; /* Fill the decks with (NUM_SUITS * num_decks) different occurances of each of the numbers from 0 to NUM_RANKS-1. */ shuffle_decks() { int i,j; int pos; CARD *tmp; int tmp_num = num_cards; printf("\n****** SHUFFLING CARDS ******\n"); fflush(stdout); for (i = 0; i < tmp_num; i++) deck[i] = -1; for (i = 0; i < NUM_RANKS; i++) for (j = NUM_SUITS * num_decks; j > 0; j--) { pos = rnum(tmp_num); tmp = deck; do { while (*tmp >= 0) tmp++; tmp++; } while (pos--); tmp[-1] = i; tmp_num--; } cardptr = deck + 1; if (show_burn) printf("\nCard burned: %c\n",cardinfo[*deck].display_char); #if 0 for (i = 0; i < num_cards; i++) printf("%c\t",cardinfo[deck[i]].display_char); putchar('\n'); #endif } check_shuffle() { if (100 * (cardptr - deck) / num_cards >= reshuffle_percentage) shuffle_decks(); if (show_pct) { #define DECK_SPACE 64 int i; int limit = 0.5 + DECK_SPACE * (1.0 - ((double)(cardptr - deck)) / num_cards); int shuf_pt = 0.5 + DECK_SPACE * (1.0 - reshuffle_percentage / 100.0); printf("Deck remaining: "); for (i = 1; i <= limit; i++) putchar((i == shuf_pt) ? 'S' : '*'); putchar('\n'); } } /* Returns a random integer from 0 to max */ /* This will be very slightly biased in favor of the lower numbers if max isn't a power of 2 */ #ifndef MSDOS rnum(max) int max; { long random(); long tmp = random(); return((int)(tmp % max)); } #else rnum(max) int max; { int tmp = rand(); return((int)(tmp % max)); } #endif init_decks() { long time(); long tmp; tmp = time(NULL); #ifndef MSDOS srandom((int)tmp); #else srand((int)tmp); #endif num_cards = NUM_RANKS * NUM_SUITS * num_decks; deck = (CARD *)malloc(sizeof(CARD) * num_cards); cardptr = deck + num_cards; }