]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/comp.c
2 * Copyright (c) 1982 Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /*static char sccsid[] = "from: @(#)comp.c 5.4 (Berkeley) 6/1/90";*/
36 static char rcsid
[] = "$Id: comp.c,v 1.2 1993/08/01 18:54:05 mycroft Exp $";
42 * @(#)comp.c 1.1 (Berkeley) 4/1/82
45 # define V_VALUABLE 40
51 register PLAY
*pp
, *op
;
52 register bool foundend
, cango
, canstop
, foundlow
;
53 register unsgn
int i
, count200
, badcount
, nummin
, nummax
, diff
;
54 register int curmin
, curmax
;
55 register CARD safe
, oppos
;
56 int valbuf
[HAND_SZ
], count
[NUM_CARDS
];
59 wmove(Score
, ERR_Y
, ERR_X
); /* get rid of error messages */
67 for (i
= 0; i
< NUM_CARDS
; i
++)
69 for (i
= 0; i
< HAND_SZ
; i
++) {
72 case C_STOP
: case C_CRASH
:
73 case C_FLAT
: case C_EMPTY
:
74 if (playit
[i
] = canplay(pp
, op
, card
))
78 if ((playit
[i
] = canplay(pp
, op
, card
))
79 && Numseen
[C_25
] == Numcards
[C_25
]
80 && Numseen
[C_50
] == Numcards
[C_50
])
83 case C_25
: case C_50
: case C_75
:
84 case C_100
: case C_200
:
85 if ((playit
[i
] = canplay(pp
, op
, card
))
86 && pp
->mileage
+ Value
[card
] == End
)
90 playit
[i
] = canplay(pp
, op
, card
);
95 case C_GAS_SAFE
: case C_DRIVE_SAFE
:
96 case C_SPARE_SAFE
: case C_RIGHT_WAY
:
97 if (pp
->battle
== opposite(card
) ||
98 (pp
->speed
== C_LIMIT
&& card
== C_RIGHT_WAY
)) {
109 if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
) {
115 fprintf(outf
, "CALCMOVE: cango = %d, canstop = %d, safe = %d\n",
116 cango
, canstop
, safe
);
119 foundend
= !check_ext(TRUE
);
120 for (i
= 0; safe
&& i
< HAND_SZ
; i
++) {
121 if (issafety(pp
->hand
[i
])) {
122 if (onecard(op
) || (foundend
&& cango
&& !canstop
)) {
126 "CALCMOVE: onecard(op) = %d, foundend = %d\n",
127 onecard(op
), foundend
);
134 oppos
= opposite(pp
->hand
[i
]);
135 if (Numseen
[oppos
] == Numcards
[oppos
] &&
136 !(pp
->hand
[i
] == C_RIGHT_WAY
&&
137 Numseen
[C_LIMIT
] != Numcards
[C_LIMIT
]))
140 && (op
->can_go
|| !pp
->can_go
|| Topcard
< Deck
)) {
141 card
= (Topcard
- Deck
) - roll(1, 10);
142 if ((!pp
->mileage
) != (!op
->mileage
))
147 "CALCMOVE: card = %d, DECK_SZ / 4 = %d\n",
150 if (card
< DECK_SZ
/ 4)
157 if (!pp
->can_go
&& !isrepair(pp
->battle
))
158 Numneed
[opposite(pp
->battle
)]++;
160 foundlow
= (cango
|| count
[C_END_LIMIT
] != 0
161 || Numseen
[C_LIMIT
] == Numcards
[C_LIMIT
]
162 || pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
);
164 count200
= pp
->nummiles
[C_200
];
171 for (i
= 0; i
< HAND_SZ
; i
++) {
173 if (issafety(card
) || playit
[i
] == (cango
!= 0)) {
176 fprintf(outf
, "CALCMOVE: switch(\"%s\")\n",
180 case C_25
: case C_50
:
181 diff
= End
- pp
->mileage
;
182 /* avoid getting too close */
183 if (Topcard
> Deck
&& cango
&& diff
<= 100
184 && diff
/ Value
[card
] > count
[card
]
185 && (card
== C_25
|| diff
% 50 == 0)) {
186 if (card
== C_50
&& diff
- 50 == 25
195 *value
= (Value
[card
] >> 3);
196 if (pp
->speed
== C_LIMIT
)
201 && (card
== C_50
|| count
[C_50
] == 0)) {
202 *value
= (pp
->mileage
? 10 : 20);
207 if (++count200
> 2) {
211 case C_75
: case C_100
:
212 *value
= (Value
[card
] >> 3);
213 if (pp
->speed
== C_LIMIT
)
218 if (pp
->mileage
+ Value
[card
] > End
)
219 *value
= (End
== 700 ? card
: 0);
220 else if (pp
->mileage
+ Value
[card
] == End
) {
221 *value
= (foundend
? card
: V_VALUABLE
);
226 if (pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
)
227 *value
= (pp
->safety
[S_RIGHT_WAY
] ==
229 else if (pp
->speed
== C_LIMIT
&&
230 End
- pp
->mileage
<= 50)
232 else if (pp
->speed
== C_LIMIT
233 || Numseen
[C_LIMIT
] != Numcards
[C_LIMIT
]) {
240 --count
[C_END_LIMIT
];
243 case C_REPAIRS
: case C_SPARE
: case C_GAS
:
244 safe
= safety(card
) - S_CONV
;
245 oppos
= opposite(card
);
246 if (pp
->safety
[safe
] != S_UNKNOWN
)
247 *value
= (pp
->safety
[safe
] ==
249 else if (pp
->battle
!= oppos
250 && (Numseen
[oppos
] == Numcards
[oppos
] ||
251 Numseen
[oppos
] + count
[card
] >
258 *value
= Numcards
[oppos
] * 6;
259 *value
+= Numseen
[card
] -
262 *value
/= (count
[card
]*count
[card
]);
267 if (pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
)
268 *value
= (pp
->safety
[S_RIGHT_WAY
] ==
271 && Numgos
+ count
[C_GO
] == Numneed
[C_GO
]) {
276 *value
= Numneed
[C_GO
] * 3;
277 *value
+= (Numseen
[C_GO
] - Numgos
);
278 *value
/= (count
[C_GO
] * count
[C_GO
]);
283 if (op
->mileage
+ 50 >= End
) {
284 *value
= (End
== 700 && !cango
);
287 if (canstop
|| (cango
&& !op
->can_go
))
290 *value
= (pp
->safety
[S_RIGHT_WAY
] !=
297 case C_CRASH
: case C_EMPTY
: case C_FLAT
:
298 safe
= safety(card
) - S_CONV
;
299 oppos
= opposite(card
);
300 *value
= (pp
->safety
[safe
]!=S_UNKNOWN
? 3 : 4);
302 if (op
->safety
[safe
] == S_PLAYED
)
305 *value
*= Numneed
[oppos
] +
307 if (!pp
->mileage
|| foundend
||
310 if (op
->mileage
== 0 || onecard(op
))
312 if (op
->speed
== C_LIMIT
)
315 pp
->safety
[safe
] != S_UNKNOWN
)
318 *value
/= ++badcount
;
322 if (op
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
325 *value
= (pp
->safety
[S_RIGHT_WAY
] !=
327 *value
*= Numcards
[C_STOP
] +
329 if (!pp
->mileage
|| foundend
||
333 *value
/= ++badcount
;
334 if (op
->mileage
== 0)
336 if ((card
== C_LIMIT
&&
337 op
->speed
== C_LIMIT
) ||
340 if (cango
&& pp
->safety
[S_RIGHT_WAY
] !=
345 case C_GAS_SAFE
: case C_DRIVE_SAFE
:
346 case C_SPARE_SAFE
: case C_RIGHT_WAY
:
347 *value
= cango
? 0 : 101;
355 *value
= cango
? 0 : 101;
356 if (card
!= C_INIT
) {
357 if (*value
>= curmax
) {
361 if (*value
<= curmin
) {
368 mvprintw(i
+ 6, 2, "%3d %-14s", *value
,
369 C_name
[pp
->hand
[i
]]);
373 if (!pp
->can_go
&& !isrepair(pp
->battle
))
374 Numneed
[opposite(pp
->battle
)]++;
377 mvaddstr(MOVE_Y
+ 1, MOVE_X
, "PLAY\n");
381 if (!Debug
|| Movetype
== M_DRAW
) {
383 if (Movetype
== M_DRAW
) {
390 if (issafety(pp
->hand
[nummin
])) { /* NEVER discard a safety */
394 mvaddstr(MOVE_Y
+ 1, MOVE_X
, "DISCARD\n");
398 if (!Debug
|| Movetype
== M_DRAW
) {
400 if (Movetype
== M_DRAW
) {
402 Movetype
= M_DISCARD
;
406 mvprintw(MOVE_Y
+ 2, MOVE_X
, "%16s", C_name
[pp
->hand
[Card_no
]]);
412 register CARD bat
, spd
, card
;
417 if (pp
->can_go
|| ((isrepair(bat
) || bat
== C_STOP
|| spd
== C_LIMIT
) &&
418 Numseen
[S_RIGHT_WAY
] != 0) ||
419 Numseen
[safety(bat
)] != 0)
420 switch (End
- pp
->mileage
) {
422 if (pp
->nummiles
[C_200
] == 2)
429 card
= (End
- pp
->mileage
== 75 ? C_75
: C_100
);
431 return Numseen
[S_RIGHT_WAY
] == 0;
435 card
= (End
- pp
->mileage
== 25 ? C_25
: C_50
);
436 return Numseen
[card
] != Numcards
[card
];
441 canplay(pp
, op
, card
)
442 register PLAY
*pp
, *op
;
447 if (pp
->nummiles
[C_200
] == 2)
450 case C_75
: case C_100
:
451 if (pp
->speed
== C_LIMIT
)
455 if (pp
->mileage
+ Value
[card
] > End
)
462 case C_EMPTY
: case C_FLAT
: case C_CRASH
:
464 if (op
->can_go
&& op
->safety
[safety(card
) - S_CONV
] != S_PLAYED
)
468 if (op
->speed
!= C_LIMIT
&&
469 op
->safety
[S_RIGHT_WAY
] != S_PLAYED
&&
470 op
->mileage
+ 50 < End
)
473 case C_GAS
: case C_SPARE
: case C_REPAIRS
:
474 if (pp
->battle
== opposite(card
))
479 (isrepair(pp
->battle
) || pp
->battle
== C_STOP
))
483 if (pp
->speed
== C_LIMIT
)