]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/move.c
422e8db72df5d703f4fc352293a5a32f73a26e0e
1 /* $NetBSD: move.c,v 1.4 1995/03/24 05:01:57 cgd 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
38 static char sccsid
[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: move.c,v 1.4 1995/03/24 05:01:57 cgd Exp $";
53 # define _tty cur_term->Nttyb
57 * @(#)move.c 1.2 (Berkeley) 3/28/83
61 #define CTRL(c) (c - 'A' + 1)
64 "M_DISCARD", "M_DRAW", "M_PLAY", "M_ORDER"
83 if (pp
->hand
[Card_no
] == C_INIT
)
87 error("no card there");
89 if (issafety(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 (issafety(*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,
176 for (pp
= Player
; pp
< &Player
[2]; pp
++) {
177 op
= (pp
== &Player
[COMP
] ? &Player
[PLAYER
] : &Player
[COMP
]);
178 for (i
= 0; i
< HAND_SZ
; i
++) {
180 if (issafety(card
) || canplay(pp
, op
, card
)) {
183 fprintf(outf
, "CHECK_GO: can play %s (%d), ", C_name
[card
], card
);
184 fprintf(outf
, "issafety(card) = %d, ", issafety(card
));
185 fprintf(outf
, "canplay(pp, op, card) = %d\n", canplay(pp
, op
, card
));
192 fprintf(outf
, "CHECK_GO: cannot play %s\n",
207 * check and see if player has picked
209 switch (pp
->hand
[Card_no
]) {
213 return error("must pick first");
214 case C_GAS_SAFE
: case C_SPARE_SAFE
:
215 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
219 card
= pp
->hand
[Card_no
];
222 fprintf(outf
, "PLAYCARD: Card = %s\n", C_name
[card
]);
227 if (pp
->nummiles
[C_200
] == 2)
228 return error("only two 200's per hand");
229 case C_100
: case C_75
:
230 if (pp
->speed
== C_LIMIT
)
231 return error("limit of 50");
233 if (pp
->mileage
+ Value
[card
] > End
)
234 return error("puts you over %d", End
);
237 return error("cannot move now");
238 pp
->nummiles
[card
]++;
242 if ((pp
->mileage
+= v
) == End
)
246 case C_GAS
: case C_SPARE
: case C_REPAIRS
:
247 if (pp
->battle
!= opposite(card
))
248 return error("can't play \"%s\"", C_name
[card
]);
250 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
255 if (pp
->battle
!= C_INIT
&& pp
->battle
!= C_STOP
256 && !isrepair(pp
->battle
))
257 return error("cannot play \"Go\" on a \"%s\"",
264 if (pp
->speed
!= C_LIMIT
)
265 return error("not limited");
266 pp
->speed
= C_END_LIMIT
;
269 case C_EMPTY
: case C_FLAT
: case C_CRASH
:
271 pp
= &Player
[other(Play
)];
273 return error("opponent cannot go");
274 else if (pp
->safety
[safety(card
) - S_CONV
] == S_PLAYED
)
276 return error("opponent is protected");
278 pp
->new_battle
= TRUE
;
284 pp
= &Player
[other(Play
)];
285 if (pp
->speed
== C_LIMIT
)
286 return error("opponent has limit");
287 if (pp
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
290 pp
->new_speed
= TRUE
;
294 case C_GAS_SAFE
: case C_SPARE_SAFE
:
295 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
296 if (pp
->battle
== opposite(card
)
297 || (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)) {
298 if (!(card
== C_RIGHT_WAY
&& !isrepair(pp
->battle
))) {
302 if (card
== C_RIGHT_WAY
&& pp
->speed
== C_LIMIT
)
305 || (pp
->new_speed
&& card
== C_RIGHT_WAY
)) {
306 pp
->coups
[card
- S_CONV
] = TRUE
;
307 pp
->total
+= SC_COUP
;
308 pp
->hand_tot
+= SC_COUP
;
309 pp
->coupscore
+= SC_COUP
;
313 * if not coup, must pick first
315 else if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
)
317 pp
->safety
[card
- S_CONV
] = S_PLAYED
;
318 pp
->total
+= SC_SAFETY
;
319 pp
->hand_tot
+= SC_SAFETY
;
320 if ((pp
->safescore
+= SC_SAFETY
) == NUM_SAFE
* SC_SAFETY
) {
321 pp
->total
+= SC_ALL_SAFE
;
322 pp
->hand_tot
+= SC_ALL_SAFE
;
324 if (card
== C_RIGHT_WAY
) {
325 if (pp
->speed
== C_LIMIT
)
327 if (pp
->battle
== C_STOP
|| pp
->battle
== C_INIT
) {
331 if (!pp
->can_go
&& isrepair(pp
->battle
))
338 error("no card there");
342 if (pp
== &Player
[PLAYER
])
344 pp
->hand
[Card_no
] = C_INIT
;
345 Next
= (Next
== -1 ? FALSE
: TRUE
);
353 static bool last_ex
= FALSE
; /* set if last command was E */
363 leaveok(Board
, FALSE
);
365 while ((c
= readch()) == killchar() || c
== erasechar())
369 if (isprint(c
) && !isspace(c
)) {
377 case 'U': /* Use Card */
378 case 'D': /* Discard Card */
379 if ((Card_no
= getcard()) < 0)
381 Movetype
= (c
== 'U' ? M_PLAY
: M_DISCARD
);
383 case 'O': /* Order */
385 if (Window
== W_SMALL
) {
387 mvwaddstr(Score
, 12, 21,
390 mvwaddstr(Score
, 12, 21,
397 rub(); /* Same as a rubout */
399 case 'W': /* Window toggle */
400 Window
= nextwin(Window
);
405 case 'R': /* Redraw screen */
409 case 'S': /* Save game */
413 case 'E': /* Extrapolate */
418 if (Window
!= W_FULL
)
425 error("%c: command not implemented", c
);
428 case '\r': /* Ignore RETURNs and */
429 case '\n': /* Line Feeds */
430 case ' ': /* Spaces */
431 case '\0': /* and nulls */
434 case 'Z': /* Debug code */
435 if (!Debug
&& outf
== NULL
) {
436 char buf
[MAXPATHLEN
];
439 leaveok(Board
, FALSE
);
442 while ((*sp
= readch()) != '\n') {
443 if (*sp
== killchar())
445 else if (*sp
== erasechar()) {
456 addstr(unctrl(*sp
++));
460 leaveok(Board
, TRUE
);
461 if ((outf
= fopen(buf
, "w")) == NULL
)
463 setbuf(outf
, (char *)NULL
);
469 error("unknown command: %s", unctrl(c
));
474 leaveok(Board
, TRUE
);
477 * return whether or not the player has picked
486 switch (pp
->hand
[Card_no
]) {
487 case C_GAS_SAFE
: case C_SPARE_SAFE
:
488 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
495 return (pp
->hand
[card
] != C_INIT
);
511 oppos
= opposite(card
);
512 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
;
562 for ( ; cp
< &hand
[-1]; cp
++)
563 for (tp
= cp
+ 1; tp
< hand
; tp
++)