]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - mille/comp.c
1 /* $NetBSD: comp.c,v 1.5 1997/10/12 00:53:45 lukem Exp $ */
4 * Copyright (c) 1982, 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
[] = "@(#)comp.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: comp.c,v 1.5 1997/10/12 00:53:45 lukem Exp $");
48 * @(#)comp.c 1.1 (Berkeley) 4/1/82
51 # define V_VALUABLE 40
59 bool foundend
, cango
, canstop
, foundlow
;
60 unsgn
int i
, count200
, badcount
, nummin
, nummax
, diff
;
63 int valbuf
[HAND_SZ
], count
[NUM_CARDS
];
66 wmove(Score
, ERR_Y
, ERR_X
); /* get rid of error messages */
75 /* Try for a Coup Forre, and see what we have. */
76 for (i
= 0; i
< NUM_CARDS
; i
++)
78 for (i
= 0; i
< HAND_SZ
; i
++) {
81 case C_STOP
: case C_CRASH
:
82 case C_FLAT
: case C_EMPTY
:
83 if ((playit
[i
] = canplay(pp
, op
, card
)) != 0)
87 if ((playit
[i
] = canplay(pp
, op
, card
))
88 && Numseen
[C_25
] == Numcards
[C_25
]
89 && Numseen
[C_50
] == Numcards
[C_50
])
92 case C_25
: case C_50
: case C_75
:
93 case C_100
: case C_200
:
94 if ((playit
[i
] = canplay(pp
, op
, card
))
95 && pp
->mileage
+ Value
[card
] == End
)
99 playit
[i
] = canplay(pp
, op
, card
);
104 case C_GAS_SAFE
: case C_DRIVE_SAFE
:
105 case C_SPARE_SAFE
: case C_RIGHT_WAY
:
106 if (pp
->battle
== opposite(card
) ||
107 (pp
->speed
== C_LIMIT
&& card
== C_RIGHT_WAY
)) {
120 /* No Coup Forre. Draw to fill hand, then restart, as needed. */
121 if (pp
->hand
[0] == C_INIT
&& Topcard
> Deck
) {
128 fprintf(outf
, "CALCMOVE: cango = %d, canstop = %d, safe = %d\n",
129 cango
, canstop
, safe
);
132 foundend
= !check_ext(TRUE
);
133 for (i
= 0; safe
&& i
< HAND_SZ
; i
++) {
134 if (issafety(pp
->hand
[i
])) {
135 if (onecard(op
) || (foundend
&& cango
&& !canstop
)) {
139 "CALCMOVE: onecard(op) = %d, foundend = %d\n",
140 onecard(op
), foundend
);
147 oppos
= opposite(pp
->hand
[i
]);
148 if (Numseen
[oppos
] == Numcards
[oppos
] &&
149 !(pp
->hand
[i
] == C_RIGHT_WAY
&&
150 Numseen
[C_LIMIT
] != Numcards
[C_LIMIT
]))
153 && (op
->can_go
|| !pp
->can_go
|| Topcard
< Deck
)) {
154 card
= (Topcard
- Deck
) - roll(1, 10);
155 if ((!pp
->mileage
) != (!op
->mileage
))
160 "CALCMOVE: card = %d, DECK_SZ / 4 = %d\n",
163 if (card
< DECK_SZ
/ 4)
170 if (!pp
->can_go
&& !isrepair(pp
->battle
))
171 Numneed
[opposite(pp
->battle
)]++;
173 foundlow
= (cango
|| count
[C_END_LIMIT
] != 0
174 || Numseen
[C_LIMIT
] == Numcards
[C_LIMIT
]
175 || pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
);
177 count200
= pp
->nummiles
[C_200
];
184 for (i
= 0; i
< HAND_SZ
; i
++) {
186 if (issafety(card
) || playit
[i
] == (cango
!= 0)) {
189 fprintf(outf
, "CALCMOVE: switch(\"%s\")\n",
193 case C_25
: case C_50
:
194 diff
= End
- pp
->mileage
;
195 /* avoid getting too close */
196 if (Topcard
> Deck
&& cango
&& diff
<= 100
197 && diff
/ Value
[card
] > count
[card
]
198 && (card
== C_25
|| diff
% 50 == 0)) {
199 if (card
== C_50
&& diff
- 50 == 25
208 *value
= (Value
[card
] >> 3);
209 if (pp
->speed
== C_LIMIT
)
214 && (card
== C_50
|| count
[C_50
] == 0)) {
215 *value
= (pp
->mileage
? 10 : 20);
220 if (++count200
> 2) {
224 case C_75
: case C_100
:
225 *value
= (Value
[card
] >> 3);
226 if (pp
->speed
== C_LIMIT
)
231 if (pp
->mileage
+ Value
[card
] > End
)
232 *value
= (End
== 700 ? card
: 0);
233 else if (pp
->mileage
+ Value
[card
] == End
) {
234 *value
= (foundend
? card
: V_VALUABLE
);
239 if (pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
)
240 *value
= (pp
->safety
[S_RIGHT_WAY
] ==
242 else if (pp
->speed
== C_LIMIT
&&
243 End
- pp
->mileage
<= 50)
245 else if (pp
->speed
== C_LIMIT
246 || Numseen
[C_LIMIT
] != Numcards
[C_LIMIT
]) {
253 --count
[C_END_LIMIT
];
256 case C_REPAIRS
: case C_SPARE
: case C_GAS
:
257 safe
= safety(card
) - S_CONV
;
258 oppos
= opposite(card
);
259 if (pp
->safety
[safe
] != S_UNKNOWN
)
260 *value
= (pp
->safety
[safe
] ==
262 else if (pp
->battle
!= oppos
263 && (Numseen
[oppos
] == Numcards
[oppos
] ||
264 Numseen
[oppos
] + count
[card
] >
271 *value
= Numcards
[oppos
] * 6;
272 *value
+= Numseen
[card
] -
275 *value
/= (count
[card
]*count
[card
]);
280 if (pp
->safety
[S_RIGHT_WAY
] != S_UNKNOWN
)
281 *value
= (pp
->safety
[S_RIGHT_WAY
] ==
284 && Numgos
+ count
[C_GO
] == Numneed
[C_GO
]) {
289 *value
= Numneed
[C_GO
] * 3;
290 *value
+= (Numseen
[C_GO
] - Numgos
);
291 *value
/= (count
[C_GO
] * count
[C_GO
]);
296 if (op
->mileage
+ 50 >= End
) {
297 *value
= (End
== 700 && !cango
);
300 if (canstop
|| (cango
&& !op
->can_go
))
303 *value
= (pp
->safety
[S_RIGHT_WAY
] !=
310 case C_CRASH
: case C_EMPTY
: case C_FLAT
:
311 safe
= safety(card
) - S_CONV
;
312 oppos
= opposite(card
);
313 *value
= (pp
->safety
[safe
]!=S_UNKNOWN
? 3 : 4);
315 if (op
->safety
[safe
] == S_PLAYED
)
318 *value
*= Numneed
[oppos
] +
320 if (!pp
->mileage
|| foundend
||
323 if (op
->mileage
== 0 || onecard(op
))
325 if (op
->speed
== C_LIMIT
)
328 pp
->safety
[safe
] != S_UNKNOWN
)
331 *value
/= ++badcount
;
335 if (op
->safety
[S_RIGHT_WAY
] == S_PLAYED
)
338 *value
= (pp
->safety
[S_RIGHT_WAY
] !=
340 *value
*= Numcards
[C_STOP
] +
342 if (!pp
->mileage
|| foundend
||
346 *value
/= ++badcount
;
347 if (op
->mileage
== 0)
349 if ((card
== C_LIMIT
&&
350 op
->speed
== C_LIMIT
) ||
353 if (cango
&& pp
->safety
[S_RIGHT_WAY
] !=
358 case C_GAS_SAFE
: case C_DRIVE_SAFE
:
359 case C_SPARE_SAFE
: case C_RIGHT_WAY
:
360 *value
= cango
? 0 : 101;
368 *value
= cango
? 0 : 101;
369 if (card
!= C_INIT
) {
370 if (*value
>= curmax
) {
374 if (*value
<= curmin
) {
381 mvprintw(i
+ 6, 2, "%3d %-14s", *value
,
382 C_name
[pp
->hand
[i
]]);
386 if (!pp
->can_go
&& !isrepair(pp
->battle
))
387 Numneed
[opposite(pp
->battle
)]++;
390 mvaddstr(MOVE_Y
+ 1, MOVE_X
, "PLAY\n");
395 if (issafety(pp
->hand
[nummin
])) { /* NEVER discard a safety */
399 mvaddstr(MOVE_Y
+ 1, MOVE_X
, "DISCARD\n");
400 Movetype
= M_DISCARD
;
403 mvprintw(MOVE_Y
+ 2, MOVE_X
, "%16s", C_name
[pp
->hand
[Card_no
]]);
407 * Return true if the given player could conceivably win with his next card.
418 if (pp
->can_go
|| ((isrepair(bat
) || bat
== C_STOP
|| spd
== C_LIMIT
) &&
419 Numseen
[S_RIGHT_WAY
] != 0) ||
420 (bat
>= 0 && Numseen
[safety(bat
)] != 0))
421 switch (End
- pp
->mileage
) {
423 if (pp
->nummiles
[C_200
] == 2)
430 card
= (End
- pp
->mileage
== 75 ? C_75
: C_100
);
432 return Numseen
[S_RIGHT_WAY
] == 0;
436 card
= (End
- pp
->mileage
== 25 ? C_25
: C_50
);
437 return Numseen
[card
] != Numcards
[card
];
443 canplay(pp
, op
, card
)
449 if (pp
->nummiles
[C_200
] == 2)
452 case C_75
: case C_100
:
453 if (pp
->speed
== C_LIMIT
)
457 if (pp
->mileage
+ Value
[card
] > End
)
464 case C_EMPTY
: case C_FLAT
: case C_CRASH
:
466 if (op
->can_go
&& op
->safety
[safety(card
) - S_CONV
] != S_PLAYED
)
470 if (op
->speed
!= C_LIMIT
&&
471 op
->safety
[S_RIGHT_WAY
] != S_PLAYED
&&
472 op
->mileage
+ 50 < End
)
475 case C_GAS
: case C_SPARE
: case C_REPAIRS
:
476 if (pp
->battle
== opposite(card
))
481 (isrepair(pp
->battle
) || pp
->battle
== C_STOP
))
485 if (pp
->speed
== C_LIMIT
)