-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriterion.c
230 lines (169 loc) · 5.36 KB
/
criterion.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* $Id: criterion.c,v 39.1 1995/04/25 01:49:12 mbayne Exp $
*
* The information in this file was created by Michael D. Bayne. This
* information is in the public domain. You are permitted to reuse, rewrite,
* bend, fold and mutilate this information. When it comes down to it, all
* this distribution information is pretty much crap anyway and I maintain
* exclusive rights to everything you see here, but go ahead and use it
* anyway. I'm too busy doing cool stuff to sue anyone.
*
* $Log: criterion.c,v $
* Revision 39.1 1995/04/25 01:49:12 mbayne
* Initial revision.
*
*/
#include <exec/types.h>
#include "board.h"
#include "criterion.h"
/* Sp He Cl Di */
long SuitMatrix[][] = {{ FALSE, TRUE, FALSE, TRUE }, /* Sp */
{ TRUE, FALSE, TRUE, FALSE }, /* He */
{ FALSE, TRUE, FALSE, TRUE }, /* Cl */
{ TRUE, FALSE, TRUE, FALSE }}; /* Di */
int EmptyStackTried;
int NonEmptyTemp( Stack *theStack )
{
if( theStack->st_ClassIdx != SC_TEMP )
return FALSE;
if( !stackTopCard( theStack ))
return FALSE;
return TRUE;
}
int OwnNonEmptySource( Stack *theStack )
{
Card aCard;
if(( theStack->st_ClassIdx != SC_SOURCE )&&
( theStack->st_ClassIdx != SC_DISCARD ))
return FALSE;
if( theStack->st_Owner != PlNo )
return FALSE;
aCard = stackTopCard( theStack );
if( !aCard || !cardFaceUp( aCard ))
return FALSE;
return TRUE;
}
int LegalSource( Stack *theStack )
{
Card aCard;
if( theStack->st_Owner == (1-PlNo))
return FALSE;
if( theStack->st_ClassIdx == SC_DEST )
return FALSE;
aCard = stackTopCard( theStack );
if( !aCard || !cardFaceUp( aCard ))
return FALSE;
return TRUE;
}
int LegalSourceUniq( Stack *theStack )
{
Card aCard;
EmptyStackTried = FALSE;
if( theStack->st_Owner == (1-PlNo))
return FALSE;
if( theStack->st_ClassIdx == SC_DEST )
return FALSE;
aCard = stackTopCard( theStack );
if( !aCard || !cardFaceUp( aCard ))
return FALSE;
return TRUE;
}
int SuccSame( Stack *theSrcStack, Stack *theDestStack )
{
Card theSrcCard, theDestCard;
if( theDestStack->st_ClassIdx != SC_DEST )
return FALSE;
theSrcCard = stackTopCard( theSrcStack );
theDestCard = stackTopCard( theDestStack );
if( cardSuit( theSrcCard ) != theDestStack->st_Suit )
return FALSE;
if( !theDestCard &&( cardRank( theSrcCard ) == ACE ))
return TRUE;
if( cardRank( theSrcCard ) != cardRank( theDestCard )+1 )
return FALSE;
return TRUE;
}
int PredAlt( Stack *theSrcStack, Stack *theDestStack )
{
Card theSrcCard, theDestCard;
if( theDestStack->st_ClassIdx != SC_TEMP )
return FALSE;
theDestCard = stackTopCard( theDestStack );
if( !theDestCard )
return ( theSrcStack->st_ClassIdx != SC_TEMP )? TRUE :
stackEntries( theSrcStack )-1;
theSrcCard = stackTopCard( theSrcStack );
if( !SuitMatrix[cardSuit( theSrcCard )][cardSuit( theDestCard )] )
return FALSE;
if( cardRank( theSrcCard ) != cardRank( theDestCard )-1 )
return FALSE;
return TRUE;
}
int PredAltUniq( Stack *theSrcStack, Stack *theDestStack )
{
Card theSrcCard, theDestCard;
if( theDestStack->st_ClassIdx != SC_TEMP )
return FALSE;
theDestCard = stackTopCard( theDestStack );
if( !theDestCard )
{
if( !EmptyStackTried )
{
EmptyStackTried = TRUE;
return ( theSrcStack->st_ClassIdx != SC_TEMP )? TRUE :
stackEntries( theSrcStack )-1;
}
return FALSE;
}
theSrcCard = stackTopCard( theSrcStack );
if( !SuitMatrix[cardSuit( theSrcCard )][cardSuit( theDestCard )] )
return FALSE;
if( cardRank( theSrcCard ) != cardRank( theDestCard )-1 )
return FALSE;
return TRUE;
}
int UnidirSame( Stack *theSrcStack, Stack *theDestStack )
{
Card theSrcCard, theDestCard, theUnderCard;
long Difference;
if( theDestStack->st_Owner != (1-PlNo))
return FALSE;
if(( theDestStack->st_ClassIdx != SC_SOURCE )&&
( theDestStack->st_ClassIdx != SC_DISCARD ))
return FALSE;
theDestCard = stackTopCard( theDestStack );
if( !theDestCard || !cardFaceUp( theDestCard ))
return FALSE;
theSrcCard = stackTopCard( theSrcStack );
if( cardSuit( theSrcCard ) != cardSuit( theDestCard ))
return FALSE;
if( stackEntries( theDestStack ) > 1 )
{
theUnderCard = stackGetCard( theDestStack, 1 );
if(( cardFaceUp( theUnderCard ))&&
( cardRank( theSrcCard ) == cardRank( theUnderCard ))&&
( cardSuit( theSrcCard ) == cardSuit( theUnderCard )))
return FALSE;
}
Difference = cardRank( theSrcCard ) - cardRank( theDestCard );
if( Difference*Difference != 1 )
return FALSE;
return TRUE;
}
int ValidStack( Stack *theStack )
{
if( !theStack )
return FALSE;
if( theStack->st_ClassIdx == SC_DEST )
return FALSE;
if( theStack->st_Owner == ( 1 - PlNo ))
return FALSE;
return TRUE;
}
int EndingMove( Stack *theSourceStack, Stack *theDestStack )
{
if( theSourceStack != MainSource[PlNo] )
return FALSE;
if( theDestStack != Discard[PlNo] )
return FALSE;
return TRUE;
}