]> thyrsus.com Git - deal.git/commitdiff
Add -g and -w options.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 26 Sep 1996 22:30:35 +0000 (22:30 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 26 Sep 1996 22:30:35 +0000 (22:30 +0000)
deal.c

diff --git a/deal.c b/deal.c
index 30341635aed6918d89d7a161285deeab7931553f..2ed7c8b962c43a7d915fe2821b8258c46d056795 100644 (file)
--- 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
  * <jeremy@stat.cmu.edu> 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");