From a811d45c1b9ccd48cdf8229f9b1da528cc0d4362 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 13 Apr 1995 18:20:54 +0000 Subject: [PATCH] Column defaults. --- deal.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/deal.c b/deal.c index 80634e5..caee448 100644 --- a/deal.c +++ b/deal.c @@ -26,6 +26,7 @@ * * cc cardprobs.c -lm -o cardprobs */ +#include #include #include @@ -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"); } } -- 2.43.0