]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/move.c
1 /* $NetBSD: move.c,v 1.9 1999/09/08 20:43:48 jsm 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: move.c,v 1.9 1999/09/08 20:43:48 jsm Exp $");
53 * @(#)move.c 1.2 (Berkeley) 3/28/83
57 #define CTRL(c) (c - 'A' + 1)
76 if (pp
->hand
[Card_no
] == C_INIT
)
80 error("no card there");
82 if (issafety(pp
->hand
[Card_no
])) {
83 error("discard a safety?");
87 Discard
= pp
->hand
[Card_no
];
88 pp
->hand
[Card_no
] = C_INIT
;
95 error("must pick first");
98 goodplay
= playcard(pp
);
103 error("no more cards");
104 else if (haspicked(pp
))
105 error("already picked");
107 pp
->hand
[0] = *--Topcard
;
110 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
115 if (issafety(*Topcard
))
116 pp
->safety
[*Topcard
-S_CONV
] = S_IN_HAND
;
118 if (pp
->hand
[1] == C_INIT
&& Topcard
> Deck
) {
120 pp
->hand
[1] = *--Topcard
;
123 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
127 pp
->new_battle
= FALSE
;
128 pp
->new_speed
= FALSE
;
136 * move blank card to top by one of two methods. If the
137 * computer's hand was sorted, the randomness for picking
138 * between equally valued cards would be lost
140 if (Order
&& Movetype
!= M_DRAW
&& goodplay
&& pp
== &Player
[PLAYER
])
143 for (i
= 1; i
< HAND_SZ
; i
++)
144 if (pp
->hand
[i
] == C_INIT
) {
145 for (j
= 0; pp
->hand
[j
] == C_INIT
; j
++)
150 pp
->hand
[i
] = pp
->hand
[j
];
151 pp
->hand
[j
] = C_INIT
;
160 * Check and see if either side can go. If they cannot,
170 for (pp
= Player
; pp
< &Player
[2]; pp
++) {
171 op
= (pp
== &Player
[COMP
] ? &Player
[PLAYER
] : &Player
[COMP
]);
172 for (i
= 0; i
< HAND_SZ
; i
++) {
174 if (issafety(card
) || canplay(pp
, op
, card
)) {
177 fprintf(outf
, "CHECK_GO: can play %s (%d), ", C_name
[card
], card
);
178 fprintf(outf
, "issafety(card) = %d, ", issafety(card
));
179 fprintf(outf
, "canplay(pp, op, card) = %d\n", canplay(pp
, op
, card
));
186 fprintf(outf
, "CHECK_GO: cannot play %s\n",
202 * check and see if player has picked
204 switch (pp
->hand
[Card_no
]) {
208 return error("must pick first");
209 case C_GAS_SAFE
: case C_SPARE_SAFE
:
210 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
214 card
= pp
->hand
[Card_no
];
217 fprintf(outf
, "PLAYCARD: Card = %s\n", C_name
[card
]);
222 if (pp
->nummiles
[C_200
] == 2)
223 return error("only two 200's per hand");
224 case C_100
: case C_75
:
225 if (pp
->speed
== C_LIMIT
)
226 return error("limit of 50");
228 if (pp
->mileage
+ Value
[card
] > End
)
229 return error("puts you over %d", End
);
232 return error("cannot move now");
233 pp
->nummiles
[card
]++;
237 if ((pp
->mileage
+= v
) == End
)
241 case C_GAS
: case C_SPARE
: case C_REPAIRS
:
242 if (pp
->battle
!= opposite(card
))
243 return error("can't play \"%s\"", C_name
[card
]);
245 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
250 if (pp
->battle
!= C_INIT
&& pp
->battle
!= C_STOP
251 && !isrepair(pp
->battle
))
252 return error("cannot play \"Go\" on a \"%s\"",
259 if (pp
->speed
!= C_LIMIT
)
260 return error("not limited");
261 pp
->speed
= C_END_LIMIT
;
264 case C_EMPTY
: case C_FLAT
: case C_CRASH
:
266 pp
= &Player
[other(Play
)];
268 return error("opponent cannot go");
269 else if (pp
->safety
[safety(card
) - S_CONV
] == S_PLAYED
)
271 return error("opponent is protected");
273 pp
->new_battle
= TRUE
;
279 pp
= &Player
[other(Play
)];
280 if (pp
->speed
== C_LIMIT
)
281 return error("opponent has limit");
282 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
285 pp
->new_speed
= TRUE
;
289 case C_GAS_SAFE
: case C_SPARE_SAFE
:
290 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
291 if (pp
->battle
== opposite(card
)
292 || (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)) {
293 if (!(card
== C_RIGHT_WAY
&& !isrepair(pp
->battle
))) {
297 if (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)
300 || (pp
->new_speed
&& card
== C_RIGHT_WAY
)) {
301 pp
->coups
[card
- S_CONV
] = TRUE
;
302 pp
->total
+= SC_COUP
;
303 pp
->hand_tot
+= SC_COUP
;
304 pp
->coupscore
+= SC_COUP
;
308 * if not coup, must pick first
310 else if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
)
312 pp
->safety
[card
- S_CONV
] = S_PLAYED
;
313 pp
->total
+= SC_SAFETY
;
314 pp
->hand_tot
+= SC_SAFETY
;
315 if ((pp
->safescore
+= SC_SAFETY
) == NUM_SAFE
* SC_SAFETY
) {
316 pp
->total
+= SC_ALL_SAFE
;
317 pp
->hand_tot
+= SC_ALL_SAFE
;
319 if (card
== C_RIGHT_WAY
) {
320 if (pp
->speed
== C_LIMIT
)
322 if (pp
->battle
== C_STOP
|| pp
->battle
== C_INIT
) {
326 if (!pp
->can_go
&& isrepair(pp
->battle
))
333 error("no card there");
337 if (pp
== &Player
[PLAYER
])
339 pp
->hand
[Card_no
] = C_INIT
;
340 Next
= (Next
== (bool)-1 ? FALSE
: TRUE
);
349 static bool last_ex
= FALSE
; /* set if last command was E */
359 leaveok(Board
, FALSE
);
361 while ((c
= readch()) == killchar() || c
== erasechar())
365 if (isprint(c
) && !isspace(c
)) {
373 case 'U': /* Use Card */
374 case 'D': /* Discard Card */
375 if ((Card_no
= getcard()) < 0)
377 Movetype
= (c
== 'U' ? M_PLAY
: M_DISCARD
);
379 case 'O': /* Order */
381 if (Window
== W_SMALL
) {
383 mvwaddstr(Score
, 12, 21,
386 mvwaddstr(Score
, 12, 21,
393 rub(0); /* Same as a rubout */
395 case 'W': /* Window toggle */
396 Window
= nextwin(Window
);
401 case 'R': /* Redraw screen */
405 case 'S': /* Save game */
409 case 'E': /* Extrapolate */
414 if (Window
!= W_FULL
)
421 error("%c: command not implemented", c
);
424 case '\r': /* Ignore RETURNs and */
425 case '\n': /* Line Feeds */
426 case ' ': /* Spaces */
427 case '\0': /* and nulls */
430 case 'Z': /* Debug code */
431 if (!Debug
&& outf
== NULL
) {
432 char buf
[MAXPATHLEN
];
435 leaveok(Board
, FALSE
);
438 while ((*sp
= readch()) != '\n') {
439 if (*sp
== killchar())
441 else if (*sp
== erasechar()) {
452 addstr(unctrl(*sp
++));
456 leaveok(Board
, TRUE
);
457 if ((outf
= fopen(buf
, "w")) == NULL
)
459 setbuf(outf
, (char *)NULL
);
465 error("unknown command: %s", unctrl(c
));
470 leaveok(Board
, TRUE
);
474 * return whether or not the player has picked
484 switch (pp
->hand
[Card_no
]) {
485 case C_GAS_SAFE
: case C_SPARE_SAFE
:
486 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
493 return (pp
->hand
[card
] != C_INIT
);
510 oppos
= opposite(card
);
511 Numgos
+= Numcards
[oppos
] - Numseen
[oppos
];
526 static char *names
[] = {
537 static int last_prompt
= -1;
539 if (promptno
== last_prompt
)
540 move(MOVE_Y
, MOVE_X
+ strlen(names
[promptno
]) + 1);
542 move(MOVE_Y
, MOVE_X
);
543 if (promptno
== MOVEPROMPT
)
545 addstr(names
[promptno
]);
546 if (promptno
== MOVEPROMPT
)
549 last_prompt
= promptno
;
563 for ( ; cp
< &hand
[-1]; cp
++)
564 for (tp
= cp
+ 1; tp
< hand
; tp
++)