]> thyrsus.com Git - deal.git/commitdiff
Column defaults.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 13 Apr 1995 18:20:54 +0000 (18:20 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 13 Apr 1995 18:20:54 +0000 (18:20 +0000)
deal.c

diff --git a/deal.c b/deal.c
index 80634e529c14c904b55b7ef3a6d2e60f7134074a..caee448d9e2f28de89b66b38d896df671e43fffa 100644 (file)
--- a/deal.c
+++ b/deal.c
@@ -26,6 +26,7 @@
  *
  *     cc cardprobs.c -lm -o cardprobs
  */
+#include <stdio.h>
 #include <math.h>
 #include <signal.h>
 
@@ -50,20 +51,32 @@ main(argc, argv)
     double hyper_prob();
 
     if  (argc == 1) {
-        (void) printf("Help for Cardprobs : here's the order of the arguments:\n");
-        (void) printf("     # special cards; # total cards; # of turns; \n");
-        (void) printf("     # columns.\n");
+        (void) printf("usage: cardprobs M N [t] [c]\n");
+        (void) printf("     M = # special cards\n");
+        (void) printf("     N = # total cards\n");
+        (void) printf("     t = # of turns (optional)\n");
+        (void) printf("     c = columns in the report (optional).\n");
         (void) printf("No arguments are optional.\n");
     } else {
         special = atoi(argv[1]);
         total = atoi(argv[2]);
-        turns = atoi(argv[3]);
         if (total < special) {
             (void) printf("Can't have more specials than total cards!\n");
             exit(-1);
         }
-        columns = atoi(argv[4]);
-        if (columns > special-1) {
+
+       turns = 20;     /* fill a standard screen */
+       if (argc >= 4)
+           turns = atoi(argv[3]);
+       if (turns > total - BASEHAND) {
+            (void) printf("The deck can't last that long!\n");
+            exit(-1);
+        }
+
+       columns = special + 1;
+       if (argc >= 5)
+           columns = atoi(argv[4]);
+        if (columns > special) {
             (void) printf("using %d columns because can only have ",special+1);
             (void) printf("0 to %d specials\n",special);
             columns = special+1;
@@ -88,13 +101,14 @@ main(argc, argv)
             (void) printf("%2d   | ",i);
             for (j = 0; j < columns && j <= i + BASEHAND && j <= special; j++)
            {
-               double p = hyper_prob(j, i + BASEHAND, special, total);
+               int p = (int)rint(hyper_prob(j, i + BASEHAND, special, total) * 100);
 
-                (void) printf("%2.2d ",(int)rint(p * 100));
+               if (p == 0)
+                   (void) fputs(" . ", stdout);
+               else
+                   (void) printf("%2d ", p);
            }
 
-            for (; j < columns; j++)
-                (void) printf(" * ");
             (void) printf("\n");
         }
     }