add primes
[unix-history] / usr / src / games / cribbage / test.c
CommitLineData
6cca9b39
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
bf870064
KB
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.
6cca9b39
KM
11 */
12
13#ifndef lint
14char copyright[] =
15"@(#) Copyright (c) 1980 Regents of the University of California.\n\
16 All rights reserved.\n";
bf870064 17#endif /* not lint */
6cca9b39
KM
18
19#ifndef lint
bf870064
KB
20static char sccsid[] = "@(#)test.c 5.2 (Berkeley) %G%";
21#endif /* not lint */
b91b0f59
KA
22
23#include <stdio.h>
24#include "deck.h"
25
26
27CARD known[ CARDS ]; /* a deck */
28CARD deck[ CARDS ]; /* a deck */
29CARD hand[ 4 ]; /* a hand */
30
31int knownum;
32
33
34main( argc, argv )
35
36 int argc;
37 char *argv[];
38{
39 register int k, l, m;
cefea9eb 40 int i, j, is, n, sum, sum2;
b91b0f59
KA
41 CARD ic, jc;
42 CARD d[ CARDS];
cefea9eb 43 extern char expl[];
b91b0f59
KA
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 );
cefea9eb 51# if 0
b91b0f59
KA
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++ ) {
cefea9eb
KA
57 printf( "%d %d: sum = %d\n", i, j, -10000000 );
58 printf( "%d %d: sum2 = %d\n", i, j, -10000000 );
b91b0f59
KA
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;
cefea9eb 69 sum2 = 0;
b91b0f59
KA
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 )
cefea9eb
KA
76 sum += scorehand(hand, d[m], 4, FALSE, FALSE);
77 sum2 += scorehand(hand, d[m], 4, TRUE, FALSE);
b91b0f59
KA
78 }
79 }
80 }
cefea9eb
KA
81 printf( "%d %d: sum = %d\n", i, j, sum );
82 printf( "%d %d: sum2 = %d\n", i, j, sum2 );
b91b0f59
KA
83 fflush( stdout );
84 }
85 }
86 printf( "\nthe hand scores %d\n", i );
cefea9eb
KA
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
b91b0f59 137}