-/* $NetBSD: move.c,v 1.6 1997/05/23 23:09:41 jtc Exp $ */
+/* $NetBSD: move.c,v 1.15 2004/11/05 21:30:32 dsl Exp $ */
/*
* Copyright (c) 1983, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: move.c,v 1.6 1997/05/23 23:09:41 jtc Exp $";
+__RCSID("$NetBSD: move.c,v 1.15 2004/11/05 21:30:32 dsl Exp $");
#endif
#endif /* not lint */
#include <termios.h>
+#ifdef DEBUG
+#include <sys/param.h>
+#endif
+
#include "mille.h"
#ifndef unctrl
#include "unctrl.h"
#endif
-# ifdef attron
-# include <term.h>
-# endif attron
-
/*
* @(#)move.c 1.2 (Berkeley) 3/28/83
*/
#undef CTRL
#define CTRL(c) (c - 'A' + 1)
-char *Movenames[] = {
- "M_DISCARD", "M_DRAW", "M_PLAY", "M_ORDER"
- };
-
+void
domove()
{
- register PLAY *pp;
- register int i, j;
- register bool goodplay;
+ PLAY *pp;
+ int i, j;
+ bool goodplay;
pp = &Player[Play];
+ for (i = 0, j = 0; i < HAND_SZ; i++)
+ if (pp->hand[i] != -1)
+ j++;
+ if (!j) {
+ nextplay();
+ return;
+ }
if (Play == PLAYER)
getmove();
else
else
error("no card there");
else {
- if (issafety(pp->hand[Card_no])) {
+ if (is_safety(pp->hand[Card_no])) {
error("discard a safety?");
goodplay = FALSE;
break;
acc:
if (Play == COMP) {
account(*Topcard);
- if (issafety(*Topcard))
+ if (is_safety(*Topcard))
pp->safety[*Topcard-S_CONV] = S_IN_HAND;
}
if (pp->hand[1] == C_INIT && Topcard > Deck) {
* Check and see if either side can go. If they cannot,
* the game is over
*/
-check_go() {
-
- register CARD card;
- register PLAY *pp, *op;
- register int i;
+void
+check_go()
+{
+ CARD card;
+ PLAY *pp, *op;
+ int i;
for (pp = Player; pp < &Player[2]; pp++) {
op = (pp == &Player[COMP] ? &Player[PLAYER] : &Player[COMP]);
for (i = 0; i < HAND_SZ; i++) {
card = pp->hand[i];
- if (issafety(card) || canplay(pp, op, card)) {
+ if (is_safety(card) || canplay(pp, op, card)) {
#ifdef DEBUG
if (Debug) {
fprintf(outf, "CHECK_GO: can play %s (%d), ", C_name[card], card);
- fprintf(outf, "issafety(card) = %d, ", issafety(card));
+ fprintf(outf, "is_safety(card) = %d, ", is_safety(card));
fprintf(outf, "canplay(pp, op, card) = %d\n", canplay(pp, op, card));
}
#endif
Finished = TRUE;
}
+int
playcard(pp)
-register PLAY *pp;
+ PLAY *pp;
{
- register int v;
- register CARD card;
+ int v;
+ CARD card;
/*
* check and see if player has picked
case C_GO:
if (pp->battle != C_INIT && pp->battle != C_STOP
- && !isrepair(pp->battle))
+ && !is_repair(pp->battle))
return error("cannot play \"Go\" on a \"%s\"",
C_name[pp->battle]);
pp->battle = C_GO;
case C_DRIVE_SAFE: case C_RIGHT_WAY:
if (pp->battle == opposite(card)
|| (card == C_RIGHT_WAY && pp->speed == C_LIMIT)) {
- if (!(card == C_RIGHT_WAY && !isrepair(pp->battle))) {
+ if (!(card == C_RIGHT_WAY && !is_repair(pp->battle))) {
pp->battle = C_GO;
pp->can_go = TRUE;
}
pp->can_go = TRUE;
pp->battle = C_INIT;
}
- if (!pp->can_go && isrepair(pp->battle))
+ if (!pp->can_go && is_repair(pp->battle))
pp->can_go = TRUE;
}
Next = -1;
return TRUE;
}
+void
getmove()
{
- register char c, *sp;
+ char c;
#ifdef EXTRAP
static bool last_ex = FALSE; /* set if last command was E */
refresh();
while ((c = readch()) == killchar() || c == erasechar())
continue;
- if (islower(c))
- c = toupper(c);
- if (isprint(c) && !isspace(c)) {
+ if (islower((unsigned char)c))
+ c = toupper((unsigned char)c);
+ if (isprint((unsigned char)c) && !isspace((unsigned char)c)) {
addch(c);
refresh();
}
Movetype = M_ORDER;
goto ret;
case 'Q': /* Quit */
- rub(); /* Same as a rubout */
+ rub(0); /* Same as a rubout */
break;
case 'W': /* Window toggle */
Window = nextwin(Window);
case 'Z': /* Debug code */
if (!Debug && outf == NULL) {
char buf[MAXPATHLEN];
+ char *sp;
prompt(FILEPROMPT);
leaveok(Board, FALSE);
refresh();
+over:
sp = buf;
while ((*sp = readch()) != '\n') {
if (*sp == killchar())
*sp = '\0';
leaveok(Board, TRUE);
if ((outf = fopen(buf, "w")) == NULL)
- perror(buf);
+ warn("%s", buf);
setbuf(outf, (char *)NULL);
}
Debug = !Debug;
ret:
leaveok(Board, TRUE);
}
+
/*
* return whether or not the player has picked
*/
+int
haspicked(pp)
-register PLAY *pp;
+ const PLAY *pp;
{
- register int card;
+ int card;
if (Topcard <= Deck)
return TRUE;
return (pp->hand[card] != C_INIT);
}
+void
account(card)
-register CARD card;
+ CARD card;
{
- register CARD oppos;
+ CARD oppos;
if (card == C_INIT)
return;
}
}
+void
prompt(promptno)
-int promptno;
+ int promptno;
{
- static char *names[] = {
+ static const char *const names[] = {
">>:Move:",
"Really?",
"Another hand?",
clrtoeol();
}
+void
sort(hand)
-register CARD *hand;
+ CARD *hand;
{
- register CARD *cp, *tp;
- register CARD temp;
+ CARD *cp, *tp;
+ CARD temp;
cp = hand;
hand += HAND_SZ;
*tp = temp;
}
}
-