/*
* deal -- compute combination probabilities for card draws
*
- * ($Id: deal.c,v 1.19 1995/04/14 13:55:40 esr Exp esr $)
+ * ($Id: deal.c,v 1.20 1995/04/17 11:44:49 esr Exp esr $)
*
* Based on the `cardprobs' program written by Jeremy C. York
* <jeremy@stat.cmu.edu> in September 1993; cleanup, comments,
static void usage(void)
{
- (void) printf("usage: deal [-h] [-b initial] [-t turns] [-c columns] specials total\n");
+ (void) printf("usage: deal [-h] [-b initial] [-t turns] [-c columns] [-g] specials total\n");
exit(0);
}
int base = BASE_DEFAULT;
int turns = TURNS_DEFAULT;
int gammatest = FALSE;
+ int ormore = FALSE;
int hypertest = FALSE;
int choosetest = FALSE;
int headers = TRUE;
+ int wide = FALSE;
- while ((status = getopt(argc, argv, "b:c:ht:vBGH")) != EOF)
+ while ((status = getopt(argc, argv, "b:c:ght:vwBGH")) != EOF)
{
switch (status)
{
hypertest = TRUE;
break;
+ case 'g':
+ wide = ormore = TRUE;
+ break;
+
case 'h':
headers = FALSE;
break;
verbose = TRUE;
break;
+ case 'w':
+ wide = TRUE;
+ break;
+
default:
usage();
}
(void) printf("%d in initial hand, %d specials out of %d total\n",
base, special, total);
- (void) printf(" | %% chance of given number of specials (. means < 0.5%%)\n");
+ (void) printf(" | %% chance of given number %sof specials (. means < 0.5%%)\n", ormore ? "or more " : "");
(void) printf("Turn | ");
for (j = 0; j < columns; j++)
- (void) printf("%2d ",j);
+ (void) printf(wide ? "%3d " : "%2d ", j);
(void) printf("\n");
(void) printf("-----+");
for (j = 0; j < columns; j++)
- (void) printf("---",j);
+ (void) printf(wide ? "----" : "---", j);
(void) printf("\n");
}
(void) printf("%2d | ",i);
for (j = 0; j < columns && j <= i + base && j <= special; j++)
{
- int p = (int)rint(hyper_prob(j, i + base, special, total) * 100);
+ double prob = hyper_prob(j, i + base, special, total);
+ int percent, k;
+
+ if (ormore)
+ for (k = j+1; k < columns && k <= i+base && k <= special; k++)
+ prob += hyper_prob(k, i + base, special, total);
- if (p == 0)
- (void) fputs(" . ", stdout);
+ percent = (int)rint(prob * 100);
+ if (percent == 0)
+ (void) fputs(wide ? " . " : " . ", stdout);
else
- (void) printf("%2d ", p);
+ (void) printf(wide ? "%3d " : "%2d ", percent);
}
(void) printf("\n");