xref: /original-bsd/games/cribbage/test.c (revision 2301fdfb)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 char copyright[] =
15 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
16  All rights reserved.\n";
17 #endif /* not lint */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)test.c	5.2 (Berkeley) 03/10/88";
21 #endif /* not lint */
22 
23 #include	<stdio.h>
24 #include	"deck.h"
25 
26 
27 CARD		known[ CARDS ];			/* a deck */
28 CARD		deck[ CARDS ];			/* a deck */
29 CARD		hand[ 4 ];			/* a hand */
30 
31 int		knownum;
32 
33 
34 main( argc, argv )
35 
36     int		argc;
37     char	*argv[];
38 {
39 	register  int		k, l, m;
40 	int			i, j, is, n, sum, sum2;
41 	CARD			ic, jc;
42 	CARD			d[ CARDS];
43 	extern char		expl[];
44 
45 	printf( "Assuming cards are same suit\n" );
46 	if(  argc == 2  )  {
47 	    is = atoi( *++argv );
48 	    printf( "Starting at i = %d\n", is );
49 	}
50 	makedeck( deck );
51 # if 0
52 	for( i = is; i < RANKS; i++ )  {		/* first card */
53 	    ic.rank = i;
54 	    ic.suit = 0;
55 	    hand[0] = ic;
56 	    for( j = 0; j <= i; j++ )  {
57 		printf( "%d %d: sum  = %d\n", i, j, -10000000 );
58 		printf( "%d %d: sum2 = %d\n", i, j, -10000000 );
59 	    }
60 	    for( j = i + 1; j < RANKS; j++ )  {		/* second card */
61 		jc.rank = j;
62 		jc.suit = 0;
63 		hand[1] = jc;
64 		for( k = 0; k < CARDS; k++ )  d[k] = deck[k];
65 		n = CARDS;
66 		remove( ic, d, n-- );
67 		remove( jc, d, n-- );
68 		sum = 0;
69 		sum2 = 0;
70 		for( k = 0; k < n - 1; k++ )  {			/* 3rd card */
71 		    hand[2] = d[k];
72 		    for( l = k + 1; l < n; l++ )  {		/* 4th card */
73 			hand[3] = d[l];
74 			for( m = 0; m < n; m++ )  {		/* cut card */
75 			    if(  m != l  &&  m != k  )
76 					    sum += scorehand(hand, d[m], 4, FALSE, FALSE);
77 					    sum2 += scorehand(hand, d[m], 4, TRUE, FALSE);
78 			}
79 		    }
80 		}
81 		printf( "%d %d: sum  = %d\n", i, j, sum );
82 		printf( "%d %d: sum2 = %d\n", i, j, sum2 );
83 		fflush( stdout );
84 	    }
85 	}
86 	printf( "\nthe hand scores %d\n", i );
87 # else
88 	hand[0].rank = 0;
89 	hand[1].rank = 1;
90 	hand[2].rank = 2;
91 	hand[3].rank = 3;
92 	hand[4].rank = 4;
93 	hand[0].suit = 0;
94 	hand[1].suit = 0;
95 	hand[2].suit = 0;
96 	hand[3].suit = 0;
97 	hand[4].suit = 0;
98 	printf("scorehand of hand = %d\n", scorehand(hand, hand[4], CINHAND, FALSE, TRUE));
99 	printf("\t%s\n", expl);
100 	hand[0].rank = 0;
101 	hand[1].rank = 1;
102 	hand[2].rank = 2;
103 	hand[3].rank = 3;
104 	hand[4].rank = 4;
105 	hand[0].suit = 0;
106 	hand[1].suit = 0;
107 	hand[2].suit = 0;
108 	hand[3].suit = 0;
109 	hand[4].suit = 0;
110 	printf("scorehand of crib = %d\n", scorehand(hand, hand[4], CINHAND, TRUE, TRUE));
111 	printf("\t%s\n", expl);
112 	hand[0].rank = 0;
113 	hand[1].rank = 1;
114 	hand[2].rank = 2;
115 	hand[3].rank = 3;
116 	hand[4].rank = 4;
117 	hand[0].suit = 0;
118 	hand[1].suit = 0;
119 	hand[2].suit = 0;
120 	hand[3].suit = 0;
121 	hand[4].suit = 1;
122 	printf("scorehand of hand = %d\n", scorehand(hand, hand[4], CINHAND, FALSE, TRUE));
123 	printf("\t%s\n", expl);
124 	hand[0].rank = 0;
125 	hand[1].rank = 1;
126 	hand[2].rank = 2;
127 	hand[3].rank = 3;
128 	hand[4].rank = 4;
129 	hand[0].suit = 0;
130 	hand[1].suit = 0;
131 	hand[2].suit = 0;
132 	hand[3].suit = 0;
133 	hand[4].suit = 1;
134 	printf("scorehand of crib = %d\n", scorehand(hand, hand[4], CINHAND, TRUE, TRUE));
135 	printf("\t%s\n", expl);
136 # endif
137 }
138