X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/462fca95471224f85b85be911e72faee16cd1597..c8f75ed90de51b0cc71da2c6c9d5fc42192076f8:/mille/comp.c diff --git a/mille/comp.c b/mille/comp.c index 8dbffb98..b184e6bb 100644 --- a/mille/comp.c +++ b/mille/comp.c @@ -1,6 +1,8 @@ +/* $NetBSD: comp.c,v 1.8 1999/09/30 18:01:32 jsm Exp $ */ + /* - * Copyright (c) 1982 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1982, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,9 +33,13 @@ * SUCH DAMAGE. */ +#include #ifndef lint -/*static char sccsid[] = "from: @(#)comp.c 5.4 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: comp.c,v 1.2 1993/08/01 18:54:05 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)comp.c 8.1 (Berkeley) 5/31/93"; +#else +__RCSID("$NetBSD: comp.c,v 1.8 1999/09/30 18:01:32 jsm Exp $"); +#endif #endif /* not lint */ # include "mille.h" @@ -44,17 +50,18 @@ static char rcsid[] = "$Id: comp.c,v 1.2 1993/08/01 18:54:05 mycroft Exp $"; # define V_VALUABLE 40 +void calcmove() { - register CARD card; - register int *value; - register PLAY *pp, *op; - register bool foundend, cango, canstop, foundlow; - register unsgn int i, count200, badcount, nummin, nummax, diff; - register int curmin, curmax; - register CARD safe, oppos; - int valbuf[HAND_SZ], count[NUM_CARDS]; - bool playit[HAND_SZ]; + CARD card; + int *value; + PLAY *pp, *op; + bool foundend, cango, canstop, foundlow; + unsgn int i, count200, badcount, nummin, nummax, diff; + int curmin, curmax; + CARD safe, oppos; + int valbuf[HAND_SZ], count[NUM_CARDS]; + bool playit[HAND_SZ]; wmove(Score, ERR_Y, ERR_X); /* get rid of error messages */ wclrtoeol(Score); @@ -64,6 +71,8 @@ calcmove() cango = 0; canstop = FALSE; foundend = FALSE; + + /* Try for a Coup Forre, and see what we have. */ for (i = 0; i < NUM_CARDS; i++) count[i] = 0; for (i = 0; i < HAND_SZ; i++) { @@ -71,7 +80,7 @@ calcmove() switch (card) { case C_STOP: case C_CRASH: case C_FLAT: case C_EMPTY: - if (playit[i] = canplay(pp, op, card)) + if ((playit[i] = canplay(pp, op, card)) != 0) canstop = TRUE; goto norm; case C_LIMIT: @@ -104,12 +113,16 @@ norm: playit[i] = TRUE; break; } - ++count[card]; + if (card >= 0) + ++count[card]; } + + /* No Coup Forre. Draw to fill hand, then restart, as needed. */ if (pp->hand[0] == C_INIT && Topcard > Deck) { Movetype = M_DRAW; return; } + #ifdef DEBUG if (Debug) fprintf(outf, "CALCMOVE: cango = %d, canstop = %d, safe = %d\n", @@ -118,7 +131,7 @@ norm: if (foundend) foundend = !check_ext(TRUE); for (i = 0; safe && i < HAND_SZ; i++) { - if (issafety(pp->hand[i])) { + if (is_safety(pp->hand[i])) { if (onecard(op) || (foundend && cango && !canstop)) { #ifdef DEBUG if (Debug) @@ -154,7 +167,7 @@ playsafe: playit[i] = cango; } } - if (!pp->can_go && !isrepair(pp->battle)) + if (!pp->can_go && !is_repair(pp->battle)) Numneed[opposite(pp->battle)]++; redoit: foundlow = (cango || count[C_END_LIMIT] != 0 @@ -170,7 +183,7 @@ redoit: value = valbuf; for (i = 0; i < HAND_SZ; i++) { card = pp->hand[i]; - if (issafety(card) || playit[i] == (cango != 0)) { + if (is_safety(card) || playit[i] == (cango != 0)) { #ifdef DEBUG if (Debug) fprintf(outf, "CALCMOVE: switch(\"%s\")\n", @@ -181,7 +194,7 @@ redoit: diff = End - pp->mileage; /* avoid getting too close */ if (Topcard > Deck && cango && diff <= 100 - && diff / Value[card] > count[card] + && (int)diff / Value[card] > count[card] && (card == C_25 || diff % 50 == 0)) { if (card == C_50 && diff - 50 == 25 && count[C_25] > 0) @@ -370,53 +383,41 @@ normbad: #endif value++; } - if (!pp->can_go && !isrepair(pp->battle)) + if (!pp->can_go && !is_repair(pp->battle)) Numneed[opposite(pp->battle)]++; if (cango) { play_it: mvaddstr(MOVE_Y + 1, MOVE_X, "PLAY\n"); -#ifdef DEBUG - if (Debug) - getmove(); - if (!Debug || Movetype == M_DRAW) { -#else - if (Movetype == M_DRAW) { -#endif - Movetype = M_PLAY; - Card_no = nummax; - } + Movetype = M_PLAY; + Card_no = nummax; } else { - if (issafety(pp->hand[nummin])) { /* NEVER discard a safety */ + if (is_safety(pp->hand[nummin])) { /* NEVER discard a safety */ nummax = nummin; goto play_it; } mvaddstr(MOVE_Y + 1, MOVE_X, "DISCARD\n"); -#ifdef DEBUG - if (Debug) - getmove(); - if (!Debug || Movetype == M_DRAW) { -#else - if (Movetype == M_DRAW) { -#endif - Movetype = M_DISCARD; - Card_no = nummin; - } + Movetype = M_DISCARD; + Card_no = nummin; } mvprintw(MOVE_Y + 2, MOVE_X, "%16s", C_name[pp->hand[Card_no]]); } +/* + * Return true if the given player could conceivably win with his next card. + */ +int onecard(pp) -register PLAY *pp; + const PLAY *pp; { - register CARD bat, spd, card; + CARD bat, spd, card; bat = pp->battle; spd = pp->speed; card = -1; - if (pp->can_go || ((isrepair(bat) || bat == C_STOP || spd == C_LIMIT) && + if (pp->can_go || ((is_repair(bat) || bat == C_STOP || spd == C_LIMIT) && Numseen[S_RIGHT_WAY] != 0) || - Numseen[safety(bat)] != 0) + (bat >= 0 && Numseen[safety(bat)] != 0)) switch (End - pp->mileage) { case 200: if (pp->nummiles[C_200] == 2) @@ -438,9 +439,10 @@ register PLAY *pp; return FALSE; } +int canplay(pp, op, card) -register PLAY *pp, *op; -register CARD card; + const PLAY *pp, *op; + CARD card; { switch (card) { case C_200: @@ -476,7 +478,7 @@ register CARD card; break; case C_GO: if (!pp->can_go && - (isrepair(pp->battle) || pp->battle == C_STOP)) + (is_repair(pp->battle) || pp->battle == C_STOP)) return TRUE; break; case C_END_LIMIT: