BSD 4_1c_2 release
[unix-history] / usr / src / games / cribbage / support.c
index bcbb5a8..b9424da 100644 (file)
@@ -1,7 +1,8 @@
-#include       <curses.h>
+static char sccsid[] = "       support.c       1.1     82/05/12        ";
+
+#include       <stdio.h>
 #include       "deck.h"
 #include       "cribbage.h"
 #include       "deck.h"
 #include       "cribbage.h"
-#include       "cribcur.h"
 
 
 #define                NTV             10              /* number scores to test */
 
 
 #define                NTV             10              /* number scores to test */
@@ -72,119 +73,81 @@ cchose( h, n, s )
 
 
 /*
 
 
 /*
- * plyrhand:
- *     Evaluate and score a player hand or crib
+ * evaluate and score a player hand or crib
  */
  */
-plyrhand(hand, s)
-CARD           hand[];
-char           *s;
+
+plyrhand( hand, s )
+
+    CARD               hand[];
+    char               *s;
 {
 {
-       register int            i, j;
+       register  int           i, j;
        BOOLEAN                 win;
        BOOLEAN                 win;
-       static char             prompt[BUFSIZ];
-
-       prhand(hand, CINHAND, Playwin);
-       sprintf(prompt, "Your %s scores ", s);
-       i = scorehand(hand, turnover, CINHAND, FALSE, explain); /* count */
-       if ((j = number(0, 29, prompt)) == 19)
-           j = 0;
-       if (i != j) {
-           if (i < j) {
-               win = chkscr(&pscore, i);
-               msg("It's really only %d points, I get %d.", i, 2);
-               if (!win)
-                   win = chkscr(&cscore, 2);
+
+       printf( "Your %s is: ", s );
+       prhand( hand, CINHAND, TRUE );
+       printf( "  [" );
+       printcard( turnover, TRUE );
+       printf( "].   How many points? " );
+       i = scorehand( hand, turnover, CINHAND, FALSE );        /* count */
+       if(  ( j = number(0, 29) )  ==  19  )  j = 0;
+       if(  i != j  )  {
+           if( i < j )  {
+               win = chkscr( &pscore, i );
+               printf( "It's really only %d points, I get %d.\n", i, 2 );
+               if( !win )  win = chkscr( &cscore, 2 );
            }
            }
-           else {
-               win = chkscr(&pscore, j);
-               msg("You should have taken %d, not %d!", i, j);
+           else  {
+               win = chkscr( &pscore, j );
+               printf( "You should have taken %d, not %d!\n", i, j );
            }
            }
-           if (explain)
-               msg("Explanation: %s", expl);
+           if( explain )  {
+               printf( "Explanation: %s\n", expl );
+           }
+       }
+       else  {
+           win = chkscr( &pscore, i );
        }
        }
-       else
-           win = chkscr(&pscore, i);
-       return win;
+       return(  win  );
 }
 
 }
 
-/*
- * comphand:
- *     Handle scoring and displaying the computers hand
- */
-comphand(h, s)
-CARD           h[];
-char           *s;
-{
-       register int            j;
 
 
-       j = scorehand(h, turnover, CINHAND, FALSE, FALSE);
-       prhand(h, CINHAND, Compwin);
-       Hasread = FALSE;
-       msg("My %s scores %d", s, (j == 0 ? 19 : j));
-       return chkscr(&cscore, j);
-}
 
 /*
 
 /*
- * chkscr:
- *     Add inc to scr and test for > glimit, printing on the scoring
- *     board while we're at it.
+ * handle scoring and displaying the computers hand
  */
 
  */
 
-int    Lastscore[2] = {-1, -1};
+comphand( h, s )
 
 
-chkscr(scr, inc)
-int            *scr, inc;
+    CARD               h[];
+    char               *s;
 {
 {
-       BOOLEAN         myturn;
-
-       myturn = (scr == &cscore);
-       if (inc != 0) {
-               prpeg(Lastscore[myturn], '.', myturn);
-               Lastscore[myturn] = *scr;
-               *scr += inc;
-               prpeg(*scr, PEG, myturn);
-       }
-       return (*scr >= glimit);
+       register  int           j;
+
+       j = scorehand( h, turnover, CINHAND, FALSE );
+       printf( "My %s ( ", s );
+       prhand( h, CINHAND, TRUE );
+       printf( "  [" );
+       printcard( turnover, TRUE );
+       printf( "] ) scores %d.\n", (j == 0 ? 19 : j) );
+       return(  chkscr( &cscore, j )  );
 }
 
 }
 
+
+
 /*
 /*
- * prpeg:
- *     put out the peg character on the score board
+ * add inc to scr and test for > glimit
  */
  */
-prpeg(score, peg, myturn)
-register int   score;
-char           peg;
-BOOLEAN                myturn;
+
+chkscr( scr, inc )
+
+    int                        *scr, inc;
 {
 {
-       register int    y, x;
-
-       if (!myturn)
-               y = SCORE_Y + 2;
-       else
-               y = SCORE_Y + 5;
-
-       if (score <= 0 || score >= glimit) {
-               if (peg == '.')
-                       peg = ' ';
-               if (score == 0)
-                       x = SCORE_X + 2;
-               else {
-                       x = SCORE_X + 2;
-                       y++;
-               }
-       }
-       else {
-               x = (score - 1) % 30;
-               if (score > 90 || (score > 30 && score <= 60)) {
-                       y++;
-                       x = 29 - x;
-               }
-               x += x / 5;
-               x += SCORE_X + 3;
-       }
-       mvaddch(y, x, peg);
+       return(  ( (*scr += inc) >= glimit ? TRUE : FALSE )  );
 }
 
 }
 
+
+
 /*
  * cdiscard -- the computer figures out what is the best discard for
  * the crib and puts the best two cards at the end
 /*
  * cdiscard -- the computer figures out what is the best discard for
  * the crib and puts the best two cards at the end
@@ -216,7 +179,7 @@ cdiscard( mycrib )
                remove( chand[i], h, FULLHAND );
                remove( chand[j], h, FULLHAND - 1 );
                for( k = 0; k < nc; k++ )  {
                remove( chand[i], h, FULLHAND );
                remove( chand[j], h, FULLHAND - 1 );
                for( k = 0; k < nc; k++ )  {
-                   sums[ns] += scorehand( h, d[k], CINHAND, TRUE, FALSE );
+                   sums[ns] += scorehand( h, d[k], CINHAND, TRUE );
                    if( mycrib )  sums[ns] += adjust( cb, d[k] );
                    else          sums[ns] -= adjust( cb, d[k] );
                }
                    if( mycrib )  sums[ns] += adjust( cb, d[k] );
                    else          sums[ns] -= adjust( cb, d[k] );
                }