[comp.sources.games] v04i004: cribbage - 4.3BSD cribbage game, Part02/02

games@tekred.TEK.COM (04/01/88)

Submitted by: bostic@okeeffe.Berkeley.EDU (Keith Bostic)
Comp.sources.games: Volume 4, Issue 4
Archive-name: cribbage/Part02



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 2)."
# Contents:  Makefile cards.c cribbage.h deck.h extern.c macro
#   support.c
# Wrapped by billr@saab on Thu Mar 31 13:51:53 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(2563 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Copyright (c) 1987 Regents of the University of California.
X# All rights reserved.
X#
X# Redistribution and use in source and binary forms are permitted
X# provided that this notice is preserved and that due credit is given
X# to the University of California at Berkeley. The name of the University
X# may not be used to endorse or promote products derived from this
X# software without specific prior written permission. This software
X# is provided ``as is'' without express or implied warranty.
X#
X#	@(#)Makefile	5.6 (Berkeley) 3/10/88
X#
XCFLAGS=	-O
XLIBC=	/lib/libc.a
XLIBS=	-lcurses -ltermlib
XHDRS=	cribbage.h deck.h cribcur.h
XSRCS=	extern.c crib.c support.c cards.c score.c io.c
XOBJS=	extern.o crib.o support.o cards.o score.o io.o
XTOBJS=	test.o cards.o score.o io.o extern.o
X
Xall: cribbage crib.instr
X
Xcribbage: ${OBJS} ${LIBC}
X	${CC} -o $@ ${CFLAGS} ${OBJS} ${LIBS}
X
Xtest: ${TOBJS} ${LIBC}
X	${CC} -o $@ ${CFLAGS} ${TOBJS} ${LIBS}
X
Xcrib.instr: cribbage.n macro
X	nroff cribbage.n > crib.instr
X
Xclean: FRC
X	rm -f ${OBJS} core crib.instr cribbage test
X
Xdepend: FRC
X	mkdep ${CFLAGS} ${SRCS}
X
Xinstall: FRC
X	install -o games -g bin -m 400 crib.instr ${DESTDIR}/usr/games/lib/crib.instr
X	install -s -o games -g bin -m 4700 cribbage ${DESTDIR}/usr/games/hide
X	(cd ${DESTDIR}/usr/games; rm -f cribbage; ln -s dm cribbage; chown games.bin cribbage)
X
Xlint: FRC
X	lint ${CFLAGS} ${SRCS}
X
Xtags: FRC
X	ctags ${SRCS}
X
XFRC:
X
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
X
Xextern.o: extern.c /usr/include/curses.h /usr/include/stdio.h
Xextern.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h
Xextern.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h deck.h
Xextern.o: cribbage.h
Xcrib.o: crib.c /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h
Xcrib.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h
Xcrib.o: /usr/include/sys/ttydev.h /usr/include/signal.h deck.h cribbage.h
Xcrib.o: cribcur.h
Xsupport.o: support.c /usr/include/curses.h /usr/include/stdio.h
Xsupport.o: /usr/include/sgtty.h /usr/include/sys/ioctl.h
Xsupport.o: /usr/include/sys/ttychars.h /usr/include/sys/ttydev.h deck.h
Xsupport.o: cribbage.h cribcur.h
Xcards.o: cards.c /usr/include/stdio.h deck.h
Xscore.o: score.c /usr/include/stdio.h deck.h cribbage.h
Xio.o: io.c /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h
Xio.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h
Xio.o: /usr/include/sys/ttydev.h /usr/include/ctype.h /usr/include/signal.h
Xio.o: deck.h cribbage.h cribcur.h
X
X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
END_OF_Makefile
if test 2563 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f cards.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"cards.c\"
else
echo shar: Extracting \"cards.c\" \(2337 characters\)
sed "s/^X//" >cards.c <<'END_OF_cards.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)cards.c	5.2 (Berkeley) 3/10/88";
X#endif /* not lint */
X
X#include	<stdio.h>
X#include	"deck.h"
X
X
X/*
X * initialize a deck of cards to contain one of each type
X */
X
Xmakedeck( d )
X
X    CARD	d[];
X{
X	register  int		i, j, k;
X	long			time();
X
X	i = time( (long *) 0 );
X	i = ( (i&0xff) << 8 ) | ( (i >> 8)&0xff ) | 1;
X	srand( i );
X	k = 0;
X	for( i = 0; i < RANKS; i++ )  {
X	    for( j = 0; j < SUITS; j++ )  {
X		d[k].suit = j;
X		d[k++].rank = i;
X	    }
X	}
X}
X
X
X
X/*
X * given a deck of cards, shuffle it -- i.e. randomize it
X * see Knuth, vol. 2, page 125
X */
X
Xshuffle( d )
X
X    CARD	d[];
X{
X	register  int		j, k;
X	CARD			c;
X
X	for( j = CARDS; j > 0; --j )  {
X	    k = ( rand() >> 4 ) % j;		/* random 0 <= k < j */
X	    c = d[j - 1];			/* exchange (j - 1) and k */
X	    d[j - 1] = d[k];
X	    d[k] = c;
X	}
X}
X
X
X
X/*
X * return true if the two cards are equal...
X */
X
Xeq( a, b )
X
X    CARD		a, b;
X{
X	return(  ( a.rank == b.rank )  &&  ( a.suit == b.suit )  );
X}
X
X
X
X/*
X * isone returns TRUE if a is in the set of cards b
X */
X
Xisone( a, b, n )
X
X    CARD		a, b[];
X    int			n;
X{
X	register  int		i;
X
X	for( i = 0; i < n; i++ )  {
X	    if(  eq( a, b[i] )   )  return( TRUE );
X	}
X	return( FALSE );
X}
X
X
X
X/*
X * remove the card a from the deck d of n cards
X */
X
Xremove( a, d, n )
X
X    CARD		a, d[];
X    int			n;
X{
X	register  int		i, j;
X
X	j = 0;
X	for( i = 0; i < n; i++ )  {
X	    if(  !eq( a, d[i] )  )  d[j++] = d[i];
X	}
X	if(  j < n  )  d[j].suit = d[j].rank = EMPTY;
X}
X
X
X
X/*
X * sorthand:
X *	Sort a hand of n cards
X */
Xsorthand(h, n)
Xregister CARD		h[];
Xint			n;
X{
X	register CARD		*cp, *endp;
X	CARD			c;
X
X	for (endp = &h[n]; h < endp - 1; h++)
X	    for (cp = h + 1; cp < endp; cp++)
X		if ((cp->rank < h->rank) ||
X		     (cp->rank == h->rank && cp->suit < h->suit)) {
X		    c = *h;
X		    *h = *cp;
X		    *cp = c;
X		}
X}
X
END_OF_cards.c
if test 2337 -ne `wc -c <cards.c`; then
    echo shar: \"cards.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f cribbage.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"cribbage.h\"
else
echo shar: Extracting \"cribbage.h\" \(1557 characters\)
sed "s/^X//" >cribbage.h <<'END_OF_cribbage.h'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X *
X *	@(#)cribbage.h	5.2 (Berkeley) 3/10/88
X */
X
Xextern  CARD		deck[ CARDS ];		/* a deck */
Xextern  CARD		phand[ FULLHAND ];	/* player's hand */
Xextern  CARD		chand[ FULLHAND ];	/* computer's hand */
Xextern  CARD		crib[ CINHAND ];	/* the crib */
Xextern  CARD		turnover;		/* the starter */
X
Xextern  CARD		known[ CARDS ];		/* cards we have seen */
Xextern  int		knownum;		/* # of cards we know */
X
Xextern  int		pscore;			/* player's score */
Xextern  int		cscore;			/* comp's score */
Xextern  int		glimit;			/* points to win game */
X
Xextern  int		pgames;			/* player's games won */
Xextern  int		cgames;			/* comp's games won */
Xextern  int		gamecount;		/* # games played */
Xextern	int		Lastscore[2];		/* previous score for each */
X
Xextern  BOOLEAN		iwon;			/* if comp won last */
Xextern  BOOLEAN		explain;		/* player mistakes explained */
Xextern  BOOLEAN		rflag;			/* if all cuts random */
Xextern  BOOLEAN		quiet;			/* if suppress random mess */
Xextern	BOOLEAN		playing;		/* currently playing game */
X
Xextern  char		expl[];			/* string for explanation */
X
END_OF_cribbage.h
if test 1557 -ne `wc -c <cribbage.h`; then
    echo shar: \"cribbage.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f deck.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"deck.h\"
else
echo shar: Extracting \"deck.h\" \(1549 characters\)
sed "s/^X//" >deck.h <<'END_OF_deck.h'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X *
X *	@(#)deck.h	5.2 (Berkeley) 3/10/88
X */
X
X/*
X * define structure of a deck of cards and other related things
X */
X
X
X#define		CARDS		52		/* number cards in deck */
X#define		RANKS		13		/* number ranks in deck */
X#define		SUITS		4		/* number suits in deck */
X
X#define		CINHAND		4		/* # cards in cribbage hand */
X#define		FULLHAND	6		/* # cards in dealt hand */
X
X#define		LGAME		121		/* number points in a game */
X#define		SGAME		61		/* # points in a short game */
X
X#define		SPADES		0		/* value of each suit */
X#define		HEARTS		1
X#define		DIAMONDS	2
X#define		CLUBS		3
X
X#define		ACE		0		/* value of each rank */
X#define		TWO		1
X#define		THREE		2
X#define		FOUR		3
X#define		FIVE		4
X#define		SIX		5
X#define		SEVEN		6
X#define		EIGHT		7
X#define		NINE		8
X#define		TEN		9
X#define		JACK		10
X#define		QUEEN		11
X#define		KING		12
X#define		EMPTY		13
X
X#define		VAL(c)		( (c) < 9 ? (c)+1 : 10 )    /* val of rank */
X
X
X#ifndef TRUE
X#	define		TRUE		1
X#	define		FALSE		0
X#endif
X
Xtypedef		struct  {
X			int		rank;
X			int		suit;
X		}		CARD;
X
Xtypedef		char		BOOLEAN;
X
END_OF_deck.h
if test 1549 -ne `wc -c <deck.h`; then
    echo shar: \"deck.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f extern.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"extern.c\"
else
echo shar: Extracting \"extern.c\" \(1667 characters\)
sed "s/^X//" >extern.c <<'END_OF_extern.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)extern.c	5.2 (Berkeley) 3/10/88";
X#endif /* not lint */
X
X# include	<curses.h>
X# include	"deck.h"
X# include	"cribbage.h"
X
Xbool	explain		= FALSE;	/* player mistakes explained */
Xbool	iwon		= FALSE;	/* if comp won last game */
Xbool	quiet		= FALSE;	/* if suppress random mess */
Xbool	rflag		= FALSE;	/* if all cuts random */
X
Xchar	expl[128];			/* explanation */
X
Xint	cgames		= 0;		/* number games comp won */
Xint	cscore		= 0;		/* comp score in this game */
Xint	gamecount	= 0;		/* number games played */
Xint	glimit		= LGAME;	/* game playe to glimit */
Xint	knownum		= 0;		/* number of cards we know */
Xint	pgames		= 0;		/* number games player won */
Xint	pscore		= 0;		/* player score in this game */
X
XCARD	chand[FULLHAND];		/* computer's hand */
XCARD	crib[CINHAND];			/* the crib */
XCARD	deck[CARDS];			/* a deck */
XCARD	known[CARDS];			/* cards we have seen */
XCARD	phand[FULLHAND];		/* player's hand */
XCARD	turnover;			/* the starter */
X
XWINDOW	*Compwin;			/* computer's hand window */
XWINDOW	*Msgwin;			/* messages for the player */
XWINDOW	*Playwin;			/* player's hand window */
XWINDOW	*Tablewin;			/* table window */
END_OF_extern.c
if test 1667 -ne `wc -c <extern.c`; then
    echo shar: \"extern.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f macro -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"macro\"
else
echo shar: Extracting \"macro\" \(2028 characters\)
sed "s/^X//" >macro <<'END_OF_macro'
X.\" Copyright (c) 1980 Regents of the University of California.
X.\" All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms are permitted
X.\" provided that this notice is preserved and that due credit is given
X.\" to the University of California at Berkeley. The name of the University
X.\" may not be used to endorse or promote products derived from this
X.\" software without specific prior written permission. This software
X.\" is provided ``as is'' without express or implied warranty.
X.\"
X.\"	@(#)macro	5.2 (Berkeley) 3/10/88
X.\"
X.nr  TX  2	\" default line space for text is 2
X.nr  PG  8	\" default paragraph indentation in PG is 8
X.nr  QI  8	\" default indentation for quotes is 8
X.nr  IP  4	\" default indentation for indented paragraph is 4
X.de  TX		\" define text settings
X.ls \\n(TX
X.fi
X..
X.de  NT		\" define non-text setings
X.nf
X.ls 1
X..
X.de  PG		\" define paragraph starter
X.sp
X.ti +\\n(PG
X..
X.de  HD		\" define page header
X'sp 1i
X..
X.de  FO		\" define page footer
X.if \\n%>1 \{\
X'sp 2
X.tl ""- % -""     \}
X'bp
X..
X.wh 0 HD	\" trap invocation of header
X.wh -1i FO	\" trap invocation of footer
X.de  pH		\" define page header
X.ce
X.ul
X\\$1
X.sp 1
X..
X.de  PF		\" define Page header for first page -- no .bp
X.ce
X.ul
X\\$1
X.sp 1
X..
X.de  PH		\" define Page header
X.ce
X.ul
X\\$1
X.sp 1
X..
X.de  HP		\" define paragraph header
X.sp 2
X.ne 4
X.ul
X\\$1
X.PG
X..
X.de  TP		\" define title page
X.ls  1
X.sp 3.5i
X.ce
X.ul
X\\$1
X.sp +3i
X.ti +50
X\\$2
X.br
X.ti +50
X\\$3
X.br
X.ti +50
X\\n(mo / \\n(dy  / \\n(yr
X.nr  %  0
X.ls
X..
X.de  KS
X.br
X.di  KB
X..
X.de  KE
X.br
X.di
X.ne  \\n(dnu
X.KB
X..
X.de  QI		\" define indented quote macro
X.sp
X.in +\\n(QI
X.ll -\\n(QI
X.ls 1
X..
X.de  EQ		\" define end quote macro
X.ls
X.sp
X.ll +\\n(QI
X.in -\\n(QI
X..
X.de  IP		\" define indented paragraph macro
X.in +\\n(IP
X.ll -\\n(IP
X.PG
X..
X.de  EP		\" define end indented paragraph macro
X.ll +\\n(IP
X.in -\\n(IP
X..
X.de  IH		\" define indented paragraph header
X.in +\\n(IP
X.ll -\\n(IP
X.sp 2
X.ne 4
X.ul
X\\$1
X.PG
X..
X.de IN
X.in +8
X.br
X.ti -4
X\\$1
X..
X.de NE
X.in -8
X..
END_OF_macro
if test 2028 -ne `wc -c <macro`; then
    echo shar: \"macro\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f support.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"support.c\"
else
echo shar: Extracting \"support.c\" \(6894 characters\)
sed "s/^X//" >support.c <<'END_OF_support.c'
X/*
X * Copyright (c) 1980 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that this notice is preserved and that due credit is given
X * to the University of California at Berkeley. The name of the University
X * may not be used to endorse or promote products derived from this
X * software without specific prior written permission. This software
X * is provided ``as is'' without express or implied warranty.
X */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)support.c	5.3 (Berkeley) 3/10/88";
X#endif /* not lint */
X
X#include	<curses.h>
X#include	"deck.h"
X#include	"cribbage.h"
X#include	"cribcur.h"
X
X
X#define		NTV		10		/* number scores to test */
X
X/* score to test reachability of, and order to test them in */
Xint		tv[ NTV ]	= { 8, 7, 9, 6, 11, 12, 13, 14, 10, 5 };
X
X
X/*
X * computer chooses what to play in pegging...
X * only called if no playable card will score points
X */
X
Xcchose( h, n, s )
X
X    CARD		h[];
X    int			n;
X    int			s;
X{
X	register  int		i, j, l;
X
X	if(  n <= 1  )  return( 0 );
X	if(  s < 4  )  {		/* try for good value */
X	    if(  ( j = anysumto(h, n, s, 4) )  >=  0  )  return( j );
X	    if(  ( j = anysumto(h, n, s, 3) ) >= 0  &&  s == 0  )
X								return( j );
X	}
X	if(  s > 0  &&  s < 20  )  {
X	    for( i = 1; i <= 10; i++ )  {	/* try for retaliation to 31 */
X		if(  ( j = anysumto(h, n, s, 21-i) )  >=  0  )  {
X		    if(  ( l = numofval(h, n, i) )  >  0  )  {
X			if(  l > 1  ||  VAL( h[j].rank ) != i  )  return( j );
X		    }
X		}
X	    }
X	}
X	if(  s < 15  )  {
X	    for( i = 0; i < NTV; i++ )  {	/* for retaliation after 15 */
X		if(  ( j = anysumto(h, n, s, tv[i]) )  >=  0  )  {
X		    if(  ( l = numofval(h, n, 15-tv[i]) )  >  0  )  {
X			if(  l > 1  ||  VAL( h[j].rank ) != 15-tv[i]  )  return( j );
X		    }
X		}
X	    }
X	}
X	j = -1;
X	for( i = n - 1; i >= 0; --i )  {	/* remember: h is sorted */
X	    l = s + VAL( h[i].rank );
X	    if(  l > 31  )  continue;
X	    if(  l != 5  &&  l != 10  &&  l != 21  )  {
X		j = i;
X		break;
X	    }
X	}
X	if(  j >= 0  )  return( j );
X	for( i = n - 1; i >= 0; --i )  {
X	    l = s + VAL( h[i].rank );
X	    if(  l > 31  )  continue;
X	    if(  j < 0  )  j = i;
X	    if(  l != 5  &&  l != 21  )  {
X		j = i;
X		break;
X	    }
X	}
X	return( j );
X}
X
X
X
X/*
X * plyrhand:
X *	Evaluate and score a player hand or crib
X */
Xplyrhand(hand, s)
XCARD		hand[];
Xchar		*s;
X{
X    register int	i, j;
X    register BOOLEAN	win;
X    static char		prompt[BUFSIZ];
X
X    prhand(hand, CINHAND, Playwin, FALSE);
X    (void)sprintf(prompt, "Your %s scores ", s);
X    i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain);
X    if ((j = number(0, 29, prompt)) == 19)
X	j = 0;
X    if (i != j) {
X	if (i < j) {
X	    win = chkscr(&pscore, i);
X	    msg("It's really only %d points; I get %d", i, 2);
X	    if (!win)
X		win = chkscr(&cscore, 2);
X	}
X	else {
X	    win = chkscr(&pscore, j);
X	    msg("You should have taken %d, not %d!", i, j);
X	}
X	if (explain)
X	    msg("Explanation: %s", expl);
X	do_wait();
X    }
X    else
X	win = chkscr(&pscore, i);
X    return win;
X}
X
X/*
X * comphand:
X *	Handle scoring and displaying the computers hand
X */
Xcomphand(h, s)
XCARD		h[];
Xchar		*s;
X{
X	register int		j;
X
X	j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, FALSE);
X	prhand(h, CINHAND, Compwin, FALSE);
X	msg("My %s scores %d", s, (j == 0 ? 19 : j));
X	return chkscr(&cscore, j);
X}
X
X/*
X * chkscr:
X *	Add inc to scr and test for > glimit, printing on the scoring
X *	board while we're at it.
X */
X
Xint	Lastscore[2] = {-1, -1};
X
Xchkscr(scr, inc)
Xint		*scr, inc;
X{
X	BOOLEAN		myturn;
X
X	myturn = (scr == &cscore);
X	if (inc != 0) {
X		prpeg(Lastscore[myturn], '.', myturn);
X		Lastscore[myturn] = *scr;
X		*scr += inc;
X		prpeg(*scr, PEG, myturn);
X		refresh();
X	}
X	return (*scr >= glimit);
X}
X
X/*
X * prpeg:
X *	Put out the peg character on the score board and put the
X *	score up on the board.
X */
Xprpeg(score, peg, myturn)
Xregister int	score;
Xchar		peg;
XBOOLEAN		myturn;
X{
X	register int	y, x;
X
X	if (!myturn)
X		y = SCORE_Y + 2;
X	else
X		y = SCORE_Y + 5;
X
X	if (score <= 0 || score >= glimit) {
X		if (peg == '.')
X			peg = ' ';
X		if (score == 0)
X			x = SCORE_X + 2;
X		else {
X			x = SCORE_X + 2;
X			y++;
X		}
X	}
X	else {
X		x = (score - 1) % 30;
X		if (score > 90 || (score > 30 && score <= 60)) {
X			y++;
X			x = 29 - x;
X		}
X		x += x / 5;
X		x += SCORE_X + 3;
X	}
X	mvaddch(y, x, peg);
X	mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", score);
X}
X
X/*
X * cdiscard -- the computer figures out what is the best discard for
X * the crib and puts the best two cards at the end
X */
X
Xcdiscard( mycrib )
X
X    BOOLEAN		mycrib;
X{
X	CARD			d[ CARDS ],  h[ FULLHAND ],  cb[ 2 ];
X	register  int		i, j, k;
X	int			nc, ns;
X	long			sums[ 15 ];
X	static  int		undo1[15]   = {0,0,0,0,0,1,1,1,1,2,2,2,3,3,4};
X	static  int		undo2[15]   = {1,2,3,4,5,2,3,4,5,3,4,5,4,5,5};
X
X	makedeck( d );
X	nc = CARDS;
X	for( i = 0; i < knownum; i++ )  {	/* get all other cards */
X	    remove( known[i], d, nc-- );
X	}
X	for( i = 0; i < 15; i++ )  sums[i] = 0L;
X	ns = 0;
X	for( i = 0; i < (FULLHAND - 1); i++ )  {
X	    cb[0] = chand[i];
X	    for( j = i + 1; j < FULLHAND; j++ )  {
X		cb[1] = chand[j];
X		for( k = 0; k < FULLHAND; k++ )  h[k] = chand[k];
X		remove( chand[i], h, FULLHAND );
X		remove( chand[j], h, FULLHAND - 1 );
X		for( k = 0; k < nc; k++ )  {
X		    sums[ns] += scorehand( h, d[k], CINHAND, TRUE, FALSE );
X		    if( mycrib )  sums[ns] += adjust( cb, d[k] );
X		    else	  sums[ns] -= adjust( cb, d[k] );
X		}
X		++ns;
X	    }
X	}
X	j = 0;
X	for( i = 1; i < 15; i++ )  if(  sums[i] > sums[j]  )  j = i;
X	for( k = 0; k < FULLHAND; k++ )  h[k] = chand[k];
X	remove( h[ undo1[j] ], chand, FULLHAND );
X	remove( h[ undo2[j] ], chand, FULLHAND - 1 );
X	chand[4] = h[ undo1[j] ];
X	chand[5] = h[ undo2[j] ];
X}
X
X
X
X/*
X * returns true if some card in hand can be played without exceeding 31
X */
X
Xanymove( hand, n, sum )
X
X    CARD		hand[];
X    int			n;
X    int			sum;
X{
X	register  int		i, j;
X
X	if(  n < 1  )  return( FALSE );
X	j = hand[0].rank;
X	for( i = 1; i < n; i++ )  {
X	    if(  hand[i].rank < j  )  j = hand[i].rank;
X	}
X	return(  sum + VAL( j )  <=  31  );
X}
X
X
X
X/*
X * anysumto returns the index (0 <= i < n) of the card in hand that brings
X * the s up to t, or -1 if there is none
X */
X
Xanysumto( hand, n, s, t )
X
X    CARD		hand[];
X    int			n;
X    int			s,  t;
X{
X	register  int		i;
X
X	for( i = 0; i < n; i++ )  {
X	    if(  s + VAL( hand[i].rank )  ==  t  )  return( i );
X	}
X	return( -1 );
X}
X
X
X
X
X/*
X * return the number of cards in h having the given rank value
X */
X
Xnumofval( h, n, v )
X
X    CARD		h[];
X    int			n;
X    int			v;
X{
X	register  int		i, j;
X
X	j = 0;
X	for( i = 0; i < n; i++ )  {
X	    if(  VAL( h[i].rank )  ==  v  )  ++j;
X	}
X	return( j );
X}
X
X
X
X/*
X * makeknown remembers all n cards in h for future recall
X */
X
Xmakeknown( h, n )
X
X    CARD		h[];
X    int			n;
X{
X	register  int		i;
X
X	for( i = 0; i < n; i++ )  {
X	    known[ knownum++ ] = h[i];
X	}
X}
X
END_OF_support.c
if test 6894 -ne `wc -c <support.c`; then
    echo shar: \"support.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0