]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/move.c
1 /* $NetBSD: move.c,v 1.15 2004/11/05 21:30:32 dsl Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: move.c,v 1.15 2004/11/05 21:30:32 dsl Exp $");
44 #include <sys/param.h>
53 * @(#)move.c 1.2 (Berkeley) 3/28/83
57 #define CTRL(c) (c - 'A' + 1)
67 for (i
= 0, j
= 0; i
< HAND_SZ
; i
++)
68 if (pp
->hand
[i
] != -1)
83 if (pp
->hand
[Card_no
] == C_INIT
)
87 error("no card there");
89 if (is_safety(pp
->hand
[Card_no
])) {
90 error("discard a safety?");
94 Discard
= pp
->hand
[Card_no
];
95 pp
->hand
[Card_no
] = C_INIT
;
102 error("must pick first");
105 goodplay
= playcard(pp
);
110 error("no more cards");
111 else if (haspicked(pp
))
112 error("already picked");
114 pp
->hand
[0] = *--Topcard
;
117 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
122 if (is_safety(*Topcard
))
123 pp
->safety
[*Topcard
-S_CONV
] = S_IN_HAND
;
125 if (pp
->hand
[1] == C_INIT
&& Topcard
> Deck
) {
127 pp
->hand
[1] = *--Topcard
;
130 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
134 pp
->new_battle
= FALSE
;
135 pp
->new_speed
= FALSE
;
143 * move blank card to top by one of two methods. If the
144 * computer's hand was sorted, the randomness for picking
145 * between equally valued cards would be lost
147 if (Order
&& Movetype
!= M_DRAW
&& goodplay
&& pp
== &Player
[PLAYER
])
150 for (i
= 1; i
< HAND_SZ
; i
++)
151 if (pp
->hand
[i
] == C_INIT
) {
152 for (j
= 0; pp
->hand
[j
] == C_INIT
; j
++)
157 pp
->hand
[i
] = pp
->hand
[j
];
158 pp
->hand
[j
] = C_INIT
;
167 * Check and see if either side can go. If they cannot,
177 for (pp
= Player
; pp
< &Player
[2]; pp
++) {
178 op
= (pp
== &Player
[COMP
] ? &Player
[PLAYER
] : &Player
[COMP
]);
179 for (i
= 0; i
< HAND_SZ
; i
++) {
181 if (is_safety(card
) || canplay(pp
, op
, card
)) {
184 fprintf(outf
, "CHECK_GO: can play %s (%d), ", C_name
[card
], card
);
185 fprintf(outf
, "is_safety(card) = %d, ", is_safety(card
));
186 fprintf(outf
, "canplay(pp, op, card) = %d\n", canplay(pp
, op
, card
));
193 fprintf(outf
, "CHECK_GO: cannot play %s\n",
209 * check and see if player has picked
211 switch (pp
->hand
[Card_no
]) {
215 return error("must pick first");
216 case C_GAS_SAFE
: case C_SPARE_SAFE
:
217 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
221 card
= pp
->hand
[Card_no
];
224 fprintf(outf
, "PLAYCARD: Card = %s\n", C_name
[card
]);
229 if (pp
->nummiles
[C_200
] == 2)
230 return error("only two 200's per hand");
231 case C_100
: case C_75
:
232 if (pp
->speed
== C_LIMIT
)
233 return error("limit of 50");
235 if (pp
->mileage
+ Value
[card
] > End
)
236 return error("puts you over %d", End
);
239 return error("cannot move now");
240 pp
->nummiles
[card
]++;
244 if ((pp
->mileage
+= v
) == End
)
248 case C_GAS
: case C_SPARE
: case C_REPAIRS
:
249 if (pp
->battle
!= opposite(card
))
250 return error("can't play \"%s\"", C_name
[card
]);
252 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
257 if (pp
->battle
!= C_INIT
&& pp
->battle
!= C_STOP
258 && !is_repair(pp
->battle
))
259 return error("cannot play \"Go\" on a \"%s\"",
266 if (pp
->speed
!= C_LIMIT
)
267 return error("not limited");
268 pp
->speed
= C_END_LIMIT
;
271 case C_EMPTY
: case C_FLAT
: case C_CRASH
:
273 pp
= &Player
[other(Play
)];
275 return error("opponent cannot go");
276 else if (pp
->safety
[safety(card
) - S_CONV
] == S_PLAYED
)
278 return error("opponent is protected");
280 pp
->new_battle
= TRUE
;
286 pp
= &Player
[other(Play
)];
287 if (pp
->speed
== C_LIMIT
)
288 return error("opponent has limit");
289 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
292 pp
->new_speed
= TRUE
;
296 case C_GAS_SAFE
: case C_SPARE_SAFE
:
297 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
298 if (pp
->battle
== opposite(card
)
299 || (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)) {
300 if (!(card
== C_RIGHT_WAY
&& !is_repair(pp
->battle
))) {
304 if (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)
307 || (pp
->new_speed
&& card
== C_RIGHT_WAY
)) {
308 pp
->coups
[card
- S_CONV
] = TRUE
;
309 pp
->total
+= SC_COUP
;
310 pp
->hand_tot
+= SC_COUP
;
311 pp
->coupscore
+= SC_COUP
;
315 * if not coup, must pick first
317 else if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
)
319 pp
->safety
[card
- S_CONV
] = S_PLAYED
;
320 pp
->total
+= SC_SAFETY
;
321 pp
->hand_tot
+= SC_SAFETY
;
322 if ((pp
->safescore
+= SC_SAFETY
) == NUM_SAFE
* SC_SAFETY
) {
323 pp
->total
+= SC_ALL_SAFE
;
324 pp
->hand_tot
+= SC_ALL_SAFE
;
326 if (card
== C_RIGHT_WAY
) {
327 if (pp
->speed
== C_LIMIT
)
329 if (pp
->battle
== C_STOP
|| pp
->battle
== C_INIT
) {
333 if (!pp
->can_go
&& is_repair(pp
->battle
))
340 error("no card there");
344 if (pp
== &Player
[PLAYER
])
346 pp
->hand
[Card_no
] = C_INIT
;
347 Next
= (Next
== (bool)-1 ? FALSE
: TRUE
);
356 static bool last_ex
= FALSE
; /* set if last command was E */
366 leaveok(Board
, FALSE
);
368 while ((c
= readch()) == killchar() || c
== erasechar())
370 if (islower((unsigned char)c
))
371 c
= toupper((unsigned char)c
);
372 if (isprint((unsigned char)c
) && !isspace((unsigned char)c
)) {
380 case 'U': /* Use Card */
381 case 'D': /* Discard Card */
382 if ((Card_no
= getcard()) < 0)
384 Movetype
= (c
== 'U' ? M_PLAY
: M_DISCARD
);
386 case 'O': /* Order */
388 if (Window
== W_SMALL
) {
390 mvwaddstr(Score
, 12, 21,
393 mvwaddstr(Score
, 12, 21,
400 rub(0); /* Same as a rubout */
402 case 'W': /* Window toggle */
403 Window
= nextwin(Window
);
408 case 'R': /* Redraw screen */
412 case 'S': /* Save game */
416 case 'E': /* Extrapolate */
421 if (Window
!= W_FULL
)
428 error("%c: command not implemented", c
);
431 case '\r': /* Ignore RETURNs and */
432 case '\n': /* Line Feeds */
433 case ' ': /* Spaces */
434 case '\0': /* and nulls */
437 case 'Z': /* Debug code */
438 if (!Debug
&& outf
== NULL
) {
439 char buf
[MAXPATHLEN
];
443 leaveok(Board
, FALSE
);
447 while ((*sp
= readch()) != '\n') {
448 if (*sp
== killchar())
450 else if (*sp
== erasechar()) {
461 addstr(unctrl(*sp
++));
465 leaveok(Board
, TRUE
);
466 if ((outf
= fopen(buf
, "w")) == NULL
)
468 setbuf(outf
, (char *)NULL
);
474 error("unknown command: %s", unctrl(c
));
479 leaveok(Board
, TRUE
);
483 * return whether or not the player has picked
493 switch (pp
->hand
[Card_no
]) {
494 case C_GAS_SAFE
: case C_SPARE_SAFE
:
495 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
502 return (pp
->hand
[card
] != C_INIT
);
519 oppos
= opposite(card
);
520 Numgos
+= Numcards
[oppos
] - Numseen
[oppos
];
535 static const char *const names
[] = {
546 static int last_prompt
= -1;
548 if (promptno
== last_prompt
)
549 move(MOVE_Y
, MOVE_X
+ strlen(names
[promptno
]) + 1);
551 move(MOVE_Y
, MOVE_X
);
552 if (promptno
== MOVEPROMPT
)
554 addstr(names
[promptno
]);
555 if (promptno
== MOVEPROMPT
)
558 last_prompt
= promptno
;
572 for ( ; cp
< &hand
[-1]; cp
++)
573 for (tp
= cp
+ 1; tp
< hand
; tp
++)