]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/move.c
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /*static char sccsid[] = "from: @(#)move.c 8.1 (Berkeley) 5/31/93";*/
36 static char rcsid
[] = "$Id: move.c,v 1.3 1994/05/12 17:39:37 jtc Exp $";
48 # define _tty cur_term->Nttyb
52 * @(#)move.c 1.2 (Berkeley) 3/28/83
56 #define CTRL(c) (c - 'A' + 1)
59 "M_DISCARD", "M_DRAW", "M_PLAY", "M_ORDER"
78 if (pp
->hand
[Card_no
] == C_INIT
)
82 error("no card there");
84 if (issafety(pp
->hand
[Card_no
])) {
85 error("discard a safety?");
89 Discard
= pp
->hand
[Card_no
];
90 pp
->hand
[Card_no
] = C_INIT
;
97 error("must pick first");
100 goodplay
= playcard(pp
);
105 error("no more cards");
106 else if (haspicked(pp
))
107 error("already picked");
109 pp
->hand
[0] = *--Topcard
;
112 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
117 if (issafety(*Topcard
))
118 pp
->safety
[*Topcard
-S_CONV
] = S_IN_HAND
;
120 if (pp
->hand
[1] == C_INIT
&& Topcard
> Deck
) {
122 pp
->hand
[1] = *--Topcard
;
125 fprintf(outf
, "DOMOVE: Draw %s\n", C_name
[*Topcard
]);
129 pp
->new_battle
= FALSE
;
130 pp
->new_speed
= FALSE
;
138 * move blank card to top by one of two methods. If the
139 * computer's hand was sorted, the randomness for picking
140 * between equally valued cards would be lost
142 if (Order
&& Movetype
!= M_DRAW
&& goodplay
&& pp
== &Player
[PLAYER
])
145 for (i
= 1; i
< HAND_SZ
; i
++)
146 if (pp
->hand
[i
] == C_INIT
) {
147 for (j
= 0; pp
->hand
[j
] == C_INIT
; j
++)
152 pp
->hand
[i
] = pp
->hand
[j
];
153 pp
->hand
[j
] = C_INIT
;
162 * Check and see if either side can go. If they cannot,
171 for (pp
= Player
; pp
< &Player
[2]; pp
++) {
172 op
= (pp
== &Player
[COMP
] ? &Player
[PLAYER
] : &Player
[COMP
]);
173 for (i
= 0; i
< HAND_SZ
; i
++) {
175 if (issafety(card
) || canplay(pp
, op
, card
)) {
178 fprintf(outf
, "CHECK_GO: can play %s (%d), ", C_name
[card
], card
);
179 fprintf(outf
, "issafety(card) = %d, ", issafety(card
));
180 fprintf(outf
, "canplay(pp, op, card) = %d\n", canplay(pp
, op
, card
));
187 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
== -1 ? FALSE
: TRUE
);
348 static bool last_ex
= FALSE
; /* set if last command was E */
358 leaveok(Board
, FALSE
);
360 while ((c
= readch()) == killchar() || c
== erasechar())
364 if (isprint(c
) && !isspace(c
)) {
372 case 'U': /* Use Card */
373 case 'D': /* Discard Card */
374 if ((Card_no
= getcard()) < 0)
376 Movetype
= (c
== 'U' ? M_PLAY
: M_DISCARD
);
378 case 'O': /* Order */
380 if (Window
== W_SMALL
) {
382 mvwaddstr(Score
, 12, 21,
385 mvwaddstr(Score
, 12, 21,
392 rub(); /* Same as a rubout */
394 case 'W': /* Window toggle */
395 Window
= nextwin(Window
);
400 case 'R': /* Redraw screen */
404 case 'S': /* Save game */
408 case 'E': /* Extrapolate */
413 if (Window
!= W_FULL
)
420 error("%c: command not implemented", c
);
423 case '\r': /* Ignore RETURNs and */
424 case '\n': /* Line Feeds */
425 case ' ': /* Spaces */
426 case '\0': /* and nulls */
429 case 'Z': /* Debug code */
430 if (!Debug
&& outf
== NULL
) {
431 char buf
[MAXPATHLEN
];
434 leaveok(Board
, FALSE
);
437 while ((*sp
= readch()) != '\n') {
438 if (*sp
== killchar())
440 else if (*sp
== erasechar()) {
451 addstr(unctrl(*sp
++));
455 leaveok(Board
, TRUE
);
456 if ((outf
= fopen(buf
, "w")) == NULL
)
458 setbuf(outf
, (char *)NULL
);
464 error("unknown command: %s", unctrl(c
));
469 leaveok(Board
, TRUE
);
472 * return whether or not the player has picked
481 switch (pp
->hand
[Card_no
]) {
482 case C_GAS_SAFE
: case C_SPARE_SAFE
:
483 case C_DRIVE_SAFE
: case C_RIGHT_WAY
:
490 return (pp
->hand
[card
] != C_INIT
);
506 oppos
= opposite(card
);
507 Numgos
+= Numcards
[oppos
] - Numseen
[oppos
];
521 static char *names
[] = {
532 static int last_prompt
= -1;
534 if (promptno
== last_prompt
)
535 move(MOVE_Y
, MOVE_X
+ strlen(names
[promptno
]) + 1);
537 move(MOVE_Y
, MOVE_X
);
538 if (promptno
== MOVEPROMPT
)
540 addstr(names
[promptno
]);
541 if (promptno
== MOVEPROMPT
)
544 last_prompt
= promptno
;
557 for ( ; cp
< &hand
[-1]; cp
++)
558 for (tp
= cp
+ 1; tp
< hand
; tp
++)