From a5f32fa1ecb0fefaa4474d578d3dddb92ea1c928 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 26 Sep 1996 22:30:35 +0000 Subject: [PATCH] Add -g and -w options. --- deal.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/deal.c b/deal.c index 3034163..2ed7c8b 100644 --- a/deal.c +++ b/deal.c @@ -1,7 +1,7 @@ /* * 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 * in September 1993; cleanup, comments, @@ -69,7 +69,7 @@ static void choosecatch(int sig) 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); } @@ -85,11 +85,13 @@ char **argv; 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) { @@ -109,6 +111,10 @@ char **argv; hypertest = TRUE; break; + case 'g': + wide = ormore = TRUE; + break; + case 'h': headers = FALSE; break; @@ -125,6 +131,10 @@ char **argv; verbose = TRUE; break; + case 'w': + wide = TRUE; + break; + default: usage(); } @@ -194,14 +204,14 @@ char **argv; (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"); } @@ -212,12 +222,18 @@ char **argv; (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"); -- 2.43.0