* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)move.c 5.1 (Berkeley) %G%";
# define _tty cur_term->Nttyb
* @(#)move.c 1.2 (Berkeley) 3/28/83
#define CTRL(c) (c - 'A' + 1)
"M_DISCARD", "M_DRAW", "M_PLAY", "M_ORDER"
if (pp
->hand
[Card_no
] == C_INIT
)
if (issafety(pp
->hand
[Card_no
])) {
error("discard a safety?");
Discard
= pp
->hand
[Card_no
];
pp
->hand
[Card_no
] = C_INIT
;
error("must pick first");
pp
->hand
[0] = *--Topcard
;
fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
pp
->safety
[*Topcard
-S_CONV
] = S_IN_HAND
;
if (pp
->hand
[1] == C_INIT
&& Topcard
> Deck
) {
pp
->hand
[1] = *--Topcard
;
fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
* move blank card to top by one of two methods. If the
* computer's hand was sorted, the randomness for picking
* between equally valued cards would be lost
if (Order
&& Movetype
!= M_DRAW
&& goodplay
&& pp
== &Player
[PLAYER
])
for (i
= 1; i
< HAND_SZ
; i
++)
if (pp
->hand
[i
] == C_INIT
) {
for (j
= 0; pp
->hand
[j
] == C_INIT
; j
++)
pp
->hand
[i
] = pp
->hand
[j
];
* Check and see if either side can go. If they cannot,
for (pp
= Player
; pp
< &Player
[2]; pp
++) {
op
= (pp
== &Player
[COMP
] ? &Player
[PLAYER
] : &Player
[COMP
]);
for (i
= 0; i
< HAND_SZ
; i
++) {
if (issafety(card
) || canplay(pp
, op
, card
)) {
fprintf(outf
, "CHECK_GO: can play %s (%d), ", C_name
[card
], card
);
fprintf(outf
, "issafety(card) = %d, ", issafety(card
));
fprintf(outf
, "canplay(pp, op, card) = %d\n", canplay(pp
, op
, card
));
fprintf(outf
, "CHECK_GO: cannot play %s\n",
* check and see if player has picked
switch (pp
->hand
[Card_no
]) {
return error("must pick first");
case C_GAS_SAFE
: case C_SPARE_SAFE
:
case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
card
= pp
->hand
[Card_no
];
fprintf(outf
, "PLAYCARD: Card = %s\n", C_name
[card
]);
if (pp
->nummiles
[C_200
] == 2)
return error("only two 200's per hand");
if (pp
->speed
== C_LIMIT
)
return error("limit of 50");
if (pp
->mileage
+ Value
[card
] > End
)
return error("puts you over %d", End
);
return error("cannot move now");
if ((pp
->mileage
+= v
) == End
)
case C_GAS
: case C_SPARE
: case C_REPAIRS
:
if (pp
->battle
!= opposite(card
))
return error("can't play \"%s\"", C_name
[card
]);
if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
if (pp
->battle
!= C_INIT
&& pp
->battle
!= C_STOP
&& !isrepair(pp
->battle
))
return error("cannot play \"Go\" on a \"%s\"",
if (pp
->speed
!= C_LIMIT
)
return error("not limited");
case C_EMPTY
: case C_FLAT
: case C_CRASH
:
pp
= &Player
[other(Play
)];
return error("opponent cannot go");
else if (pp
->safety
[safety(card
) - S_CONV
] == S_PLAYED
)
return error("opponent is protected");
pp
= &Player
[other(Play
)];
if (pp
->speed
== C_LIMIT
)
return error("opponent has limit");
if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
case C_GAS_SAFE
: case C_SPARE_SAFE
:
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
&& pp
->speed
== C_LIMIT
)
|| (pp
->new_speed
&& card
== C_RIGHT_WAY
)) {
pp
->coups
[card
- S_CONV
] = TRUE
;
pp
->coupscore
+= SC_COUP
;
* if not coup, must pick first
else if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
)
pp
->safety
[card
- S_CONV
] = S_PLAYED
;
pp
->hand_tot
+= SC_SAFETY
;
if ((pp
->safescore
+= SC_SAFETY
) == NUM_SAFE
* SC_SAFETY
) {
pp
->total
+= SC_ALL_SAFE
;
pp
->hand_tot
+= SC_ALL_SAFE
;
if (card
== C_RIGHT_WAY
) {
if (pp
->speed
== C_LIMIT
)
if (pp
->battle
== C_STOP
|| pp
->battle
== C_INIT
) {
if (!pp
->can_go
&& isrepair(pp
->battle
))
if (pp
== &Player
[PLAYER
])
pp
->hand
[Card_no
] = C_INIT
;
Next
= (Next
== -1 ? FALSE
: TRUE
);
static char moveprompt
[] = ">>:Move:";
static bool last_ex
= FALSE
; /* set if last command was E */
while ((c
= readch()) == killchar() || c
== erasechar())
if (isprint(c
) && !isspace(c
)) {
case 'D': /* Discard Card */
if ((Card_no
= getcard()) < 0)
Movetype
= (c
== 'U' ? M_PLAY
: M_DISCARD
);
rub(); /* Same as a rubout */
case 'W': /* Window toggle */
Window
= nextwin(Window
);
case 'R': /* Redraw screen */
case 'S': /* Save game */
case 'E': /* Extrapolate */
error("%c: command not implemented", c
);
case '\r': /* Ignore RETURNs and */
case '\n': /* Line Feeds */
case '\0': /* and nulls */
case 'Z': /* Debug code */
if (geteuid() == ARNOLD
) {
if (!Debug
&& outf
== NULL
) {
while ((*sp
= readch()) != '\n') {
else if (*sp
== erasechar()) {
if ((outf
= fopen(buf
, "w")) == NULL
)
setbuf(outf
, (char *)NULL
);
error("unknown command: %s", unctrl(c
));
* return whether or not the player has picked
switch (pp
->hand
[Card_no
]) {
case C_GAS_SAFE
: case C_SPARE_SAFE
:
case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
return (pp
->hand
[card
] != C_INIT
);
Numgos
+= Numcards
[oppos
] - Numseen
[oppos
];
static int last_prompt
= -1;
if (promptno
== last_prompt
)
move(MOVE_Y
, MOVE_X
+ strlen(names
[promptno
]) + 1);
if (promptno
== MOVEPROMPT
)
if (promptno
== MOVEPROMPT
)
for ( ; cp
< &hand
[-1]; cp
++)
for (tp
= cp
+ 1; tp
< hand
; tp
++)