Home | History | Annotate | Line # | Download | only in mille
comp.c revision 1.1.1.2
      1      1.1  cgd /*
      2  1.1.1.2  jtc  * Copyright (c) 1982, 1993
      3  1.1.1.2  jtc  *	The Regents of the University of California.  All rights reserved.
      4      1.1  cgd  *
      5      1.1  cgd  * Redistribution and use in source and binary forms, with or without
      6      1.1  cgd  * modification, are permitted provided that the following conditions
      7      1.1  cgd  * are met:
      8      1.1  cgd  * 1. Redistributions of source code must retain the above copyright
      9      1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     10      1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11      1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     12      1.1  cgd  *    documentation and/or other materials provided with the distribution.
     13      1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     14      1.1  cgd  *    must display the following acknowledgement:
     15      1.1  cgd  *	This product includes software developed by the University of
     16      1.1  cgd  *	California, Berkeley and its contributors.
     17      1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     18      1.1  cgd  *    may be used to endorse or promote products derived from this software
     19      1.1  cgd  *    without specific prior written permission.
     20      1.1  cgd  *
     21      1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22      1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23      1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24      1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25      1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26      1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27      1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28      1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29      1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30      1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31      1.1  cgd  * SUCH DAMAGE.
     32      1.1  cgd  */
     33      1.1  cgd 
     34      1.1  cgd #ifndef lint
     35  1.1.1.2  jtc static char sccsid[] = "@(#)comp.c	8.1 (Berkeley) 5/31/93";
     36      1.1  cgd #endif /* not lint */
     37      1.1  cgd 
     38      1.1  cgd # include	"mille.h"
     39      1.1  cgd 
     40      1.1  cgd /*
     41      1.1  cgd  * @(#)comp.c	1.1 (Berkeley) 4/1/82
     42      1.1  cgd  */
     43      1.1  cgd 
     44      1.1  cgd # define	V_VALUABLE	40
     45      1.1  cgd 
     46      1.1  cgd calcmove()
     47      1.1  cgd {
     48      1.1  cgd 	register CARD		card;
     49      1.1  cgd 	register int		*value;
     50      1.1  cgd 	register PLAY		*pp, *op;
     51      1.1  cgd 	register bool		foundend, cango, canstop, foundlow;
     52      1.1  cgd 	register unsgn int	i, count200, badcount, nummin, nummax, diff;
     53      1.1  cgd 	register int		curmin, curmax;
     54      1.1  cgd 	register CARD		safe, oppos;
     55      1.1  cgd 	int			valbuf[HAND_SZ], count[NUM_CARDS];
     56      1.1  cgd 	bool			playit[HAND_SZ];
     57      1.1  cgd 
     58      1.1  cgd 	wmove(Score, ERR_Y, ERR_X);	/* get rid of error messages	*/
     59      1.1  cgd 	wclrtoeol(Score);
     60      1.1  cgd 	pp = &Player[COMP];
     61      1.1  cgd 	op = &Player[PLAYER];
     62      1.1  cgd 	safe = 0;
     63      1.1  cgd 	cango = 0;
     64      1.1  cgd 	canstop = FALSE;
     65      1.1  cgd 	foundend = FALSE;
     66  1.1.1.2  jtc 
     67  1.1.1.2  jtc 	/* Try for a Coup Forre, and see what we have. */
     68      1.1  cgd 	for (i = 0; i < NUM_CARDS; i++)
     69      1.1  cgd 		count[i] = 0;
     70      1.1  cgd 	for (i = 0; i < HAND_SZ; i++) {
     71      1.1  cgd 		card = pp->hand[i];
     72      1.1  cgd 		switch (card) {
     73      1.1  cgd 		  case C_STOP:	case C_CRASH:
     74      1.1  cgd 		  case C_FLAT:	case C_EMPTY:
     75      1.1  cgd 			if (playit[i] = canplay(pp, op, card))
     76      1.1  cgd 				canstop = TRUE;
     77      1.1  cgd 			goto norm;
     78      1.1  cgd 		  case C_LIMIT:
     79      1.1  cgd 			if ((playit[i] = canplay(pp, op, card))
     80      1.1  cgd 			    && Numseen[C_25] == Numcards[C_25]
     81      1.1  cgd 			    && Numseen[C_50] == Numcards[C_50])
     82      1.1  cgd 				canstop = TRUE;
     83      1.1  cgd 			goto norm;
     84      1.1  cgd 		  case C_25:	case C_50:	case C_75:
     85      1.1  cgd 		  case C_100:	case C_200:
     86      1.1  cgd 			if ((playit[i] = canplay(pp, op, card))
     87      1.1  cgd 			    && pp->mileage + Value[card] == End)
     88      1.1  cgd 				foundend = TRUE;
     89      1.1  cgd 			goto norm;
     90      1.1  cgd 		  default:
     91      1.1  cgd 			playit[i] = canplay(pp, op, card);
     92      1.1  cgd norm:
     93      1.1  cgd 			if (playit[i])
     94      1.1  cgd 				++cango;
     95      1.1  cgd 			break;
     96      1.1  cgd 		  case C_GAS_SAFE:	case C_DRIVE_SAFE:
     97      1.1  cgd 		  case C_SPARE_SAFE:	case C_RIGHT_WAY:
     98      1.1  cgd 			if (pp->battle == opposite(card) ||
     99      1.1  cgd 			    (pp->speed == C_LIMIT && card == C_RIGHT_WAY)) {
    100      1.1  cgd 				Movetype = M_PLAY;
    101      1.1  cgd 				Card_no = i;
    102      1.1  cgd 				return;
    103      1.1  cgd 			}
    104      1.1  cgd 			++safe;
    105      1.1  cgd 			playit[i] = TRUE;
    106      1.1  cgd 			break;
    107      1.1  cgd 		}
    108  1.1.1.2  jtc 		if (card >= 0)
    109  1.1.1.2  jtc 			++count[card];
    110      1.1  cgd 	}
    111  1.1.1.2  jtc 
    112  1.1.1.2  jtc 	/* No Coup Forre.  Draw to fill hand, then restart, as needed. */
    113      1.1  cgd 	if (pp->hand[0] == C_INIT && Topcard > Deck) {
    114      1.1  cgd 		Movetype = M_DRAW;
    115      1.1  cgd 		return;
    116      1.1  cgd 	}
    117  1.1.1.2  jtc 
    118      1.1  cgd #ifdef DEBUG
    119      1.1  cgd 	if (Debug)
    120      1.1  cgd 		fprintf(outf, "CALCMOVE: cango = %d, canstop = %d, safe = %d\n",
    121      1.1  cgd 			cango, canstop, safe);
    122      1.1  cgd #endif
    123      1.1  cgd 	if (foundend)
    124      1.1  cgd 		foundend = !check_ext(TRUE);
    125      1.1  cgd 	for (i = 0; safe && i < HAND_SZ; i++) {
    126      1.1  cgd 		if (issafety(pp->hand[i])) {
    127      1.1  cgd 			if (onecard(op) || (foundend && cango && !canstop)) {
    128      1.1  cgd #ifdef DEBUG
    129      1.1  cgd 				if (Debug)
    130      1.1  cgd 					fprintf(outf,
    131      1.1  cgd 						"CALCMOVE: onecard(op) = %d, foundend = %d\n",
    132      1.1  cgd 						onecard(op), foundend);
    133      1.1  cgd #endif
    134      1.1  cgd playsafe:
    135      1.1  cgd 				Movetype = M_PLAY;
    136      1.1  cgd 				Card_no = i;
    137      1.1  cgd 				return;
    138      1.1  cgd 			}
    139      1.1  cgd 			oppos = opposite(pp->hand[i]);
    140      1.1  cgd 			if (Numseen[oppos] == Numcards[oppos] &&
    141      1.1  cgd 			    !(pp->hand[i] == C_RIGHT_WAY &&
    142      1.1  cgd 			      Numseen[C_LIMIT] != Numcards[C_LIMIT]))
    143      1.1  cgd 				goto playsafe;
    144      1.1  cgd 			else if (!cango
    145      1.1  cgd 			    && (op->can_go || !pp->can_go || Topcard < Deck)) {
    146      1.1  cgd 				card = (Topcard - Deck) - roll(1, 10);
    147      1.1  cgd 				if ((!pp->mileage) != (!op->mileage))
    148      1.1  cgd 					card -= 7;
    149      1.1  cgd #ifdef DEBUG
    150      1.1  cgd 				if (Debug)
    151      1.1  cgd 					fprintf(outf,
    152      1.1  cgd 						"CALCMOVE: card = %d, DECK_SZ / 4 = %d\n",
    153      1.1  cgd 						card, DECK_SZ / 4);
    154      1.1  cgd #endif
    155      1.1  cgd 				if (card < DECK_SZ / 4)
    156      1.1  cgd 					goto playsafe;
    157      1.1  cgd 			}
    158      1.1  cgd 			safe--;
    159      1.1  cgd 			playit[i] = cango;
    160      1.1  cgd 		}
    161      1.1  cgd 	}
    162      1.1  cgd 	if (!pp->can_go && !isrepair(pp->battle))
    163      1.1  cgd 		Numneed[opposite(pp->battle)]++;
    164      1.1  cgd redoit:
    165      1.1  cgd 	foundlow = (cango || count[C_END_LIMIT] != 0
    166      1.1  cgd 			  || Numseen[C_LIMIT] == Numcards[C_LIMIT]
    167      1.1  cgd 			  || pp->safety[S_RIGHT_WAY] != S_UNKNOWN);
    168      1.1  cgd 	foundend = FALSE;
    169      1.1  cgd 	count200 = pp->nummiles[C_200];
    170      1.1  cgd 	badcount = 0;
    171      1.1  cgd 	curmax = -1;
    172      1.1  cgd 	curmin = 101;
    173      1.1  cgd 	nummin = -1;
    174      1.1  cgd 	nummax = -1;
    175      1.1  cgd 	value = valbuf;
    176      1.1  cgd 	for (i = 0; i < HAND_SZ; i++) {
    177      1.1  cgd 		card = pp->hand[i];
    178      1.1  cgd 		if (issafety(card) || playit[i] == (cango != 0)) {
    179      1.1  cgd #ifdef DEBUG
    180      1.1  cgd 			if (Debug)
    181      1.1  cgd 				fprintf(outf, "CALCMOVE: switch(\"%s\")\n",
    182      1.1  cgd 					C_name[card]);
    183      1.1  cgd #endif
    184      1.1  cgd 			switch (card) {
    185      1.1  cgd 			  case C_25:	case C_50:
    186      1.1  cgd 				diff = End - pp->mileage;
    187      1.1  cgd 				/* avoid getting too close */
    188      1.1  cgd 				if (Topcard > Deck && cango && diff <= 100
    189      1.1  cgd 				    && diff / Value[card] > count[card]
    190      1.1  cgd 				    && (card == C_25 || diff % 50 == 0)) {
    191      1.1  cgd 					if (card == C_50 && diff - 50 == 25
    192      1.1  cgd 					    && count[C_25] > 0)
    193      1.1  cgd 						goto okay;
    194      1.1  cgd 					*value = 0;
    195      1.1  cgd 					if (--cango <= 0)
    196      1.1  cgd 						goto redoit;
    197      1.1  cgd 					break;
    198      1.1  cgd 				}
    199      1.1  cgd okay:
    200      1.1  cgd 				*value = (Value[card] >> 3);
    201      1.1  cgd 				if (pp->speed == C_LIMIT)
    202      1.1  cgd 					++*value;
    203      1.1  cgd 				else
    204      1.1  cgd 					--*value;
    205      1.1  cgd 				if (!foundlow
    206      1.1  cgd 				   && (card == C_50 || count[C_50] == 0)) {
    207      1.1  cgd 					*value = (pp->mileage ? 10 : 20);
    208      1.1  cgd 					foundlow = TRUE;
    209      1.1  cgd 				}
    210      1.1  cgd 				goto miles;
    211      1.1  cgd 			  case C_200:
    212      1.1  cgd 				if (++count200 > 2) {
    213      1.1  cgd 					*value = 0;
    214      1.1  cgd 					break;
    215      1.1  cgd 				}
    216      1.1  cgd 			  case C_75:	case C_100:
    217      1.1  cgd 				*value = (Value[card] >> 3);
    218      1.1  cgd 				if (pp->speed == C_LIMIT)
    219      1.1  cgd 					--*value;
    220      1.1  cgd 				else
    221      1.1  cgd 					++*value;
    222      1.1  cgd miles:
    223      1.1  cgd 				if (pp->mileage + Value[card] > End)
    224      1.1  cgd 					*value = (End == 700 ? card : 0);
    225      1.1  cgd 				else if (pp->mileage + Value[card] == End) {
    226      1.1  cgd 					*value = (foundend ? card : V_VALUABLE);
    227      1.1  cgd 					foundend = TRUE;
    228      1.1  cgd 				}
    229      1.1  cgd 				break;
    230      1.1  cgd 			  case C_END_LIMIT:
    231      1.1  cgd 				if (pp->safety[S_RIGHT_WAY] != S_UNKNOWN)
    232      1.1  cgd 					*value = (pp->safety[S_RIGHT_WAY] ==
    233      1.1  cgd 						  S_PLAYED ? -1 : 1);
    234      1.1  cgd 				else if (pp->speed == C_LIMIT &&
    235      1.1  cgd 					 End - pp->mileage <= 50)
    236      1.1  cgd 					*value = 1;
    237      1.1  cgd 				else if (pp->speed == C_LIMIT
    238      1.1  cgd 				    || Numseen[C_LIMIT] != Numcards[C_LIMIT]) {
    239      1.1  cgd 					safe = S_RIGHT_WAY;
    240      1.1  cgd 					oppos = C_LIMIT;
    241      1.1  cgd 					goto repair;
    242      1.1  cgd 				}
    243      1.1  cgd 				else {
    244      1.1  cgd 					*value = 0;
    245      1.1  cgd 					--count[C_END_LIMIT];
    246      1.1  cgd 				}
    247      1.1  cgd 				break;
    248      1.1  cgd 			  case C_REPAIRS:	case C_SPARE:	case C_GAS:
    249      1.1  cgd 				safe = safety(card) - S_CONV;
    250      1.1  cgd 				oppos = opposite(card);
    251      1.1  cgd 				if (pp->safety[safe] != S_UNKNOWN)
    252      1.1  cgd 					*value = (pp->safety[safe] ==
    253      1.1  cgd 						  S_PLAYED ? -1 : 1);
    254      1.1  cgd 				else if (pp->battle != oppos
    255      1.1  cgd 				    && (Numseen[oppos] == Numcards[oppos] ||
    256      1.1  cgd 					Numseen[oppos] + count[card] >
    257      1.1  cgd 					Numcards[oppos])) {
    258      1.1  cgd 					*value = 0;
    259      1.1  cgd 					--count[card];
    260      1.1  cgd 				}
    261      1.1  cgd 				else {
    262      1.1  cgd repair:
    263      1.1  cgd 					*value = Numcards[oppos] * 6;
    264      1.1  cgd 					*value += Numseen[card] -
    265      1.1  cgd 						  Numseen[oppos];
    266      1.1  cgd 					if (!cango)
    267      1.1  cgd 					    *value /= (count[card]*count[card]);
    268      1.1  cgd 					count[card]--;
    269      1.1  cgd 				}
    270      1.1  cgd 				break;
    271      1.1  cgd 			  case C_GO:
    272      1.1  cgd 				if (pp->safety[S_RIGHT_WAY] != S_UNKNOWN)
    273      1.1  cgd 					*value = (pp->safety[S_RIGHT_WAY] ==
    274      1.1  cgd 						  S_PLAYED ? -1 : 2);
    275      1.1  cgd 				else if (pp->can_go
    276      1.1  cgd 				 && Numgos + count[C_GO] == Numneed[C_GO]) {
    277      1.1  cgd 					*value = 0;
    278      1.1  cgd 					--count[C_GO];
    279      1.1  cgd 				}
    280      1.1  cgd 				else {
    281      1.1  cgd 					*value = Numneed[C_GO] * 3;
    282      1.1  cgd 					*value += (Numseen[C_GO] - Numgos);
    283      1.1  cgd 					*value /= (count[C_GO] * count[C_GO]);
    284      1.1  cgd 					count[C_GO]--;
    285      1.1  cgd 				}
    286      1.1  cgd 				break;
    287      1.1  cgd 			  case C_LIMIT:
    288      1.1  cgd 				if (op->mileage + 50 >= End) {
    289      1.1  cgd 					*value = (End == 700 && !cango);
    290      1.1  cgd 					break;
    291      1.1  cgd 				}
    292      1.1  cgd 				if (canstop || (cango && !op->can_go))
    293      1.1  cgd 					*value = 1;
    294      1.1  cgd 				else {
    295      1.1  cgd 					*value = (pp->safety[S_RIGHT_WAY] !=
    296      1.1  cgd 						  S_UNKNOWN ? 2 : 3);
    297      1.1  cgd 					safe = S_RIGHT_WAY;
    298      1.1  cgd 					oppos = C_END_LIMIT;
    299      1.1  cgd 					goto normbad;
    300      1.1  cgd 				}
    301      1.1  cgd 				break;
    302      1.1  cgd 			  case C_CRASH:	case C_EMPTY:	case C_FLAT:
    303      1.1  cgd 				safe = safety(card) - S_CONV;
    304      1.1  cgd 				oppos = opposite(card);
    305      1.1  cgd 				*value = (pp->safety[safe]!=S_UNKNOWN ? 3 : 4);
    306      1.1  cgd normbad:
    307      1.1  cgd 				if (op->safety[safe] == S_PLAYED)
    308      1.1  cgd 					*value = -1;
    309      1.1  cgd 				else {
    310      1.1  cgd 					*value *= Numneed[oppos] +
    311      1.1  cgd 						  Numseen[oppos] + 2;
    312      1.1  cgd 					if (!pp->mileage || foundend ||
    313      1.1  cgd 					    onecard(op))
    314      1.1  cgd 						*value += 5;
    315      1.1  cgd 					if (op->mileage == 0 || onecard(op))
    316      1.1  cgd 						*value += 5;
    317      1.1  cgd 					if (op->speed == C_LIMIT)
    318      1.1  cgd 						*value -= 3;
    319      1.1  cgd 					if (cango &&
    320      1.1  cgd 					    pp->safety[safe] != S_UNKNOWN)
    321      1.1  cgd 						*value += 3;
    322      1.1  cgd 					if (!cango)
    323      1.1  cgd 						*value /= ++badcount;
    324      1.1  cgd 				}
    325      1.1  cgd 				break;
    326      1.1  cgd 			  case C_STOP:
    327      1.1  cgd 				if (op->safety[S_RIGHT_WAY] == S_PLAYED)
    328      1.1  cgd 					*value = -1;
    329      1.1  cgd 				else {
    330      1.1  cgd 					*value = (pp->safety[S_RIGHT_WAY] !=
    331      1.1  cgd 						  S_UNKNOWN ? 3 : 4);
    332      1.1  cgd 					*value *= Numcards[C_STOP] +
    333      1.1  cgd 						  Numseen[C_GO];
    334      1.1  cgd 					if (!pp->mileage || foundend ||
    335      1.1  cgd 					    onecard(op))
    336      1.1  cgd 						*value += 5;
    337      1.1  cgd 					if (!cango)
    338      1.1  cgd 						*value /= ++badcount;
    339      1.1  cgd 					if (op->mileage == 0)
    340      1.1  cgd 						*value += 5;
    341      1.1  cgd 					if ((card == C_LIMIT &&
    342      1.1  cgd 					     op->speed == C_LIMIT) ||
    343      1.1  cgd 					    !op->can_go)
    344      1.1  cgd 						*value -= 5;
    345      1.1  cgd 					if (cango && pp->safety[S_RIGHT_WAY] !=
    346      1.1  cgd 						     S_UNKNOWN)
    347      1.1  cgd 						*value += 5;
    348      1.1  cgd 				}
    349      1.1  cgd 				break;
    350      1.1  cgd 			  case C_GAS_SAFE:	case C_DRIVE_SAFE:
    351      1.1  cgd 			  case C_SPARE_SAFE:	case C_RIGHT_WAY:
    352      1.1  cgd 				*value = cango ? 0 : 101;
    353      1.1  cgd 				break;
    354      1.1  cgd 			  case C_INIT:
    355      1.1  cgd 				*value = 0;
    356      1.1  cgd 				break;
    357      1.1  cgd 			}
    358      1.1  cgd 		}
    359      1.1  cgd 		else
    360      1.1  cgd 			*value = cango ? 0 : 101;
    361      1.1  cgd 		if (card != C_INIT) {
    362      1.1  cgd 			if (*value >= curmax) {
    363      1.1  cgd 				nummax = i;
    364      1.1  cgd 				curmax = *value;
    365      1.1  cgd 			}
    366      1.1  cgd 			if (*value <= curmin) {
    367      1.1  cgd 				nummin = i;
    368      1.1  cgd 				curmin = *value;
    369      1.1  cgd 			}
    370      1.1  cgd 		}
    371      1.1  cgd #ifdef DEBUG
    372      1.1  cgd 		if (Debug)
    373      1.1  cgd 			mvprintw(i + 6, 2, "%3d %-14s", *value,
    374      1.1  cgd 				 C_name[pp->hand[i]]);
    375      1.1  cgd #endif
    376      1.1  cgd 		value++;
    377      1.1  cgd 	}
    378      1.1  cgd 	if (!pp->can_go && !isrepair(pp->battle))
    379      1.1  cgd 		Numneed[opposite(pp->battle)]++;
    380      1.1  cgd 	if (cango) {
    381      1.1  cgd play_it:
    382      1.1  cgd 		mvaddstr(MOVE_Y + 1, MOVE_X, "PLAY\n");
    383  1.1.1.2  jtc 		Movetype = M_PLAY;
    384  1.1.1.2  jtc 		Card_no = nummax;
    385      1.1  cgd 	}
    386      1.1  cgd 	else {
    387      1.1  cgd 		if (issafety(pp->hand[nummin])) { /* NEVER discard a safety */
    388      1.1  cgd 			nummax = nummin;
    389      1.1  cgd 			goto play_it;
    390      1.1  cgd 		}
    391      1.1  cgd 		mvaddstr(MOVE_Y + 1, MOVE_X, "DISCARD\n");
    392  1.1.1.2  jtc 		Movetype = M_DISCARD;
    393  1.1.1.2  jtc 		Card_no = nummin;
    394      1.1  cgd 	}
    395      1.1  cgd 	mvprintw(MOVE_Y + 2, MOVE_X, "%16s", C_name[pp->hand[Card_no]]);
    396      1.1  cgd }
    397      1.1  cgd 
    398  1.1.1.2  jtc /*
    399  1.1.1.2  jtc  * Return true if the given player could conceivably win with his next card.
    400  1.1.1.2  jtc  */
    401      1.1  cgd onecard(pp)
    402      1.1  cgd register PLAY	*pp;
    403      1.1  cgd {
    404      1.1  cgd 	register CARD	bat, spd, card;
    405      1.1  cgd 
    406      1.1  cgd 	bat = pp->battle;
    407      1.1  cgd 	spd = pp->speed;
    408      1.1  cgd 	card = -1;
    409      1.1  cgd 	if (pp->can_go || ((isrepair(bat) || bat == C_STOP || spd == C_LIMIT) &&
    410      1.1  cgd 			   Numseen[S_RIGHT_WAY] != 0) ||
    411  1.1.1.2  jtc 	    bat >= 0 && Numseen[safety(bat)] != 0)
    412      1.1  cgd 		switch (End - pp->mileage) {
    413      1.1  cgd 		  case 200:
    414      1.1  cgd 			if (pp->nummiles[C_200] == 2)
    415      1.1  cgd 				return FALSE;
    416      1.1  cgd 			card = C_200;
    417      1.1  cgd 			/* FALLTHROUGH */
    418      1.1  cgd 		  case 100:
    419      1.1  cgd 		  case 75:
    420      1.1  cgd 			if (card == -1)
    421      1.1  cgd 				card = (End - pp->mileage == 75 ? C_75 : C_100);
    422      1.1  cgd 			if (spd == C_LIMIT)
    423      1.1  cgd 				return Numseen[S_RIGHT_WAY] == 0;
    424      1.1  cgd 		  case 50:
    425      1.1  cgd 		  case 25:
    426      1.1  cgd 			if (card == -1)
    427      1.1  cgd 				card = (End - pp->mileage == 25 ? C_25 : C_50);
    428      1.1  cgd 			return Numseen[card] != Numcards[card];
    429      1.1  cgd 		}
    430      1.1  cgd 	return FALSE;
    431      1.1  cgd }
    432      1.1  cgd 
    433      1.1  cgd canplay(pp, op, card)
    434      1.1  cgd register PLAY	*pp, *op;
    435      1.1  cgd register CARD	card;
    436      1.1  cgd {
    437      1.1  cgd 	switch (card) {
    438      1.1  cgd 	  case C_200:
    439      1.1  cgd 		if (pp->nummiles[C_200] == 2)
    440      1.1  cgd 			break;
    441      1.1  cgd 		/* FALLTHROUGH */
    442      1.1  cgd 	  case C_75:	case C_100:
    443      1.1  cgd 		if (pp->speed == C_LIMIT)
    444      1.1  cgd 			break;
    445      1.1  cgd 		/* FALLTHROUGH */
    446      1.1  cgd 	  case C_50:
    447      1.1  cgd 		if (pp->mileage + Value[card] > End)
    448      1.1  cgd 			break;
    449      1.1  cgd 		/* FALLTHROUGH */
    450      1.1  cgd 	  case C_25:
    451      1.1  cgd 		if (pp->can_go)
    452      1.1  cgd 			return TRUE;
    453      1.1  cgd 		break;
    454      1.1  cgd 	  case C_EMPTY:	case C_FLAT:	case C_CRASH:
    455      1.1  cgd 	  case C_STOP:
    456      1.1  cgd 		if (op->can_go && op->safety[safety(card) - S_CONV] != S_PLAYED)
    457      1.1  cgd 			return TRUE;
    458      1.1  cgd 		break;
    459      1.1  cgd 	  case C_LIMIT:
    460      1.1  cgd 		if (op->speed != C_LIMIT &&
    461      1.1  cgd 		    op->safety[S_RIGHT_WAY] != S_PLAYED &&
    462      1.1  cgd 		    op->mileage + 50 < End)
    463      1.1  cgd 			return TRUE;
    464      1.1  cgd 		break;
    465      1.1  cgd 	  case C_GAS:	case C_SPARE:	case C_REPAIRS:
    466      1.1  cgd 		if (pp->battle == opposite(card))
    467      1.1  cgd 			return TRUE;
    468      1.1  cgd 		break;
    469      1.1  cgd 	  case C_GO:
    470      1.1  cgd 		if (!pp->can_go &&
    471      1.1  cgd 		    (isrepair(pp->battle) || pp->battle == C_STOP))
    472      1.1  cgd 			return TRUE;
    473      1.1  cgd 		break;
    474      1.1  cgd 	  case C_END_LIMIT:
    475      1.1  cgd 		if (pp->speed == C_LIMIT)
    476      1.1  cgd 			return TRUE;
    477      1.1  cgd 	}
    478      1.1  cgd 	return FALSE;
    479      1.1  cgd }
    480