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