mille.h revision 1.11 1 1.11 jsm /* $NetBSD: mille.h,v 1.11 1999/09/30 18:01:32 jsm Exp $ */
2 1.5 cgd
3 1.1 cgd /*
4 1.4 jtc * Copyright (c) 1982, 1993
5 1.4 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd *
35 1.5 cgd * @(#)mille.h 8.1 (Berkeley) 5/31/93
36 1.1 cgd */
37 1.1 cgd
38 1.1 cgd # include <sys/types.h>
39 1.7 lukem # include <sys/uio.h>
40 1.7 lukem # include <sys/stat.h>
41 1.1 cgd # include <ctype.h>
42 1.7 lukem # include <err.h>
43 1.7 lukem # include <errno.h>
44 1.1 cgd # include <curses.h>
45 1.7 lukem # include <fcntl.h>
46 1.7 lukem # include <stdlib.h>
47 1.7 lukem # include <string.h>
48 1.3 mycroft # include <termios.h>
49 1.7 lukem # include <unistd.h>
50 1.1 cgd
51 1.1 cgd /*
52 1.1 cgd * @(#)mille.h 1.1 (Berkeley) 4/1/82
53 1.1 cgd */
54 1.1 cgd
55 1.1 cgd /*
56 1.1 cgd * Miscellaneous constants
57 1.1 cgd */
58 1.1 cgd
59 1.1 cgd # define unsgn unsigned
60 1.1 cgd # define CARD short
61 1.1 cgd
62 1.1 cgd # define HAND_SZ 7 /* number of cards in a hand */
63 1.1 cgd # define DECK_SZ 101 /* number of cards in decks */
64 1.1 cgd # define NUM_SAFE 4 /* number of saftey cards */
65 1.1 cgd # define NUM_MILES 5 /* number of milestones types */
66 1.1 cgd # define NUM_CARDS 20 /* number of types of cards */
67 1.1 cgd # define BOARD_Y 17 /* size of board screen */
68 1.1 cgd # define BOARD_X 40
69 1.1 cgd # define MILES_Y 7 /* size of mileage screen */
70 1.1 cgd # define MILES_X 80
71 1.1 cgd # define SCORE_Y 17 /* size of score screen */
72 1.1 cgd # define SCORE_X 40
73 1.1 cgd # define MOVE_Y 10 /* Where to print move prompt */
74 1.1 cgd # define MOVE_X 20
75 1.1 cgd # define ERR_Y 15 /* Where to print errors */
76 1.1 cgd # define ERR_X 5
77 1.1 cgd # define EXT_Y 4 /* Where to put Extension */
78 1.1 cgd # define EXT_X 9
79 1.1 cgd
80 1.1 cgd # define PLAYER 0
81 1.1 cgd # define COMP 1
82 1.1 cgd
83 1.1 cgd # define W_SMALL 0 /* Small (initial) window */
84 1.1 cgd # define W_FULL 1 /* Full (final) window */
85 1.1 cgd
86 1.1 cgd /*
87 1.1 cgd * Move types
88 1.1 cgd */
89 1.1 cgd
90 1.1 cgd # define M_DISCARD 0
91 1.1 cgd # define M_DRAW 1
92 1.1 cgd # define M_PLAY 2
93 1.1 cgd # define M_ORDER 3
94 1.1 cgd
95 1.1 cgd /*
96 1.1 cgd * Scores
97 1.1 cgd */
98 1.1 cgd
99 1.1 cgd # define SC_SAFETY 100
100 1.1 cgd # define SC_ALL_SAFE 300
101 1.1 cgd # define SC_COUP 300
102 1.1 cgd # define SC_TRIP 400
103 1.1 cgd # define SC_SAFE 300
104 1.1 cgd # define SC_DELAY 300
105 1.1 cgd # define SC_EXTENSION 200
106 1.1 cgd # define SC_SHUT_OUT 500
107 1.1 cgd
108 1.1 cgd /*
109 1.1 cgd * safety descriptions
110 1.1 cgd */
111 1.1 cgd
112 1.11 jsm # undef S_UNKNOWN
113 1.11 jsm # undef S_IN_HAND
114 1.11 jsm # undef S_PLAYED
115 1.11 jsm # undef S_GAS_SAFE
116 1.11 jsm # undef S_SPARE_SAFE
117 1.11 jsm # undef S_DRIVE_SAFE
118 1.11 jsm # undef S_RIGHT_WAY
119 1.11 jsm # undef S_CONV
120 1.1 cgd # define S_UNKNOWN 0 /* location of safety unknown */
121 1.1 cgd # define S_IN_HAND 1 /* safety in player's hand */
122 1.1 cgd # define S_PLAYED 2 /* safety has been played */
123 1.1 cgd # define S_GAS_SAFE 0 /* Gas safety card index */
124 1.1 cgd # define S_SPARE_SAFE 1 /* Tire safety card index */
125 1.1 cgd # define S_DRIVE_SAFE 2 /* Driveing safety card index */
126 1.1 cgd # define S_RIGHT_WAY 3 /* Right-of-Way card index */
127 1.1 cgd # define S_CONV 15 /* conversion from C_ to S_ */
128 1.1 cgd
129 1.1 cgd /*
130 1.1 cgd * card numbers
131 1.1 cgd */
132 1.1 cgd
133 1.1 cgd # define C_INIT -1
134 1.1 cgd # define C_25 0
135 1.1 cgd # define C_50 1
136 1.1 cgd # define C_75 2
137 1.1 cgd # define C_100 3
138 1.1 cgd # define C_200 4
139 1.1 cgd # define C_EMPTY 5
140 1.1 cgd # define C_FLAT 6
141 1.1 cgd # define C_CRASH 7
142 1.1 cgd # define C_STOP 8
143 1.1 cgd # define C_LIMIT 9
144 1.1 cgd # define C_GAS 10
145 1.1 cgd # define C_SPARE 11
146 1.1 cgd # define C_REPAIRS 12
147 1.1 cgd # define C_GO 13
148 1.1 cgd # define C_END_LIMIT 14
149 1.1 cgd # define C_GAS_SAFE 15
150 1.1 cgd # define C_SPARE_SAFE 16
151 1.1 cgd # define C_DRIVE_SAFE 17
152 1.1 cgd # define C_RIGHT_WAY 18
153 1.1 cgd
154 1.1 cgd /*
155 1.1 cgd * prompt types
156 1.1 cgd */
157 1.1 cgd
158 1.1 cgd # define MOVEPROMPT 0
159 1.1 cgd # define REALLYPROMPT 1
160 1.1 cgd # define ANOTHERHANDPROMPT 2
161 1.1 cgd # define ANOTHERGAMEPROMPT 3
162 1.1 cgd # define SAVEGAMEPROMPT 4
163 1.1 cgd # define SAMEFILEPROMPT 5
164 1.1 cgd # define FILEPROMPT 6
165 1.1 cgd # define EXTENSIONPROMPT 7
166 1.1 cgd # define OVERWRITEFILEPROMPT 8
167 1.1 cgd
168 1.1 cgd # ifdef SYSV
169 1.1 cgd # define srandom(x) srand(x)
170 1.1 cgd # define random() rand()
171 1.6 jtc # endif /* SYSV */
172 1.1 cgd
173 1.1 cgd typedef struct {
174 1.1 cgd bool coups[NUM_SAFE];
175 1.1 cgd bool can_go;
176 1.1 cgd bool new_battle;
177 1.1 cgd bool new_speed;
178 1.1 cgd short safety[NUM_SAFE];
179 1.1 cgd short sh_safety[NUM_SAFE];
180 1.1 cgd short nummiles[NUM_MILES];
181 1.1 cgd short sh_nummiles[NUM_MILES];
182 1.1 cgd CARD hand[HAND_SZ];
183 1.1 cgd CARD sh_hand[HAND_SZ];
184 1.1 cgd CARD battle;
185 1.1 cgd CARD sh_battle;
186 1.1 cgd CARD speed;
187 1.1 cgd CARD sh_speed;
188 1.1 cgd int mileage;
189 1.1 cgd int sh_mileage;
190 1.1 cgd int hand_tot;
191 1.1 cgd int sh_hand_tot;
192 1.1 cgd int safescore;
193 1.1 cgd int sh_safescore;
194 1.1 cgd int coupscore;
195 1.1 cgd int total;
196 1.1 cgd int sh_total;
197 1.1 cgd int games;
198 1.1 cgd int sh_games;
199 1.1 cgd int was_finished;
200 1.1 cgd } PLAY;
201 1.1 cgd
202 1.1 cgd /*
203 1.1 cgd * macros
204 1.1 cgd */
205 1.1 cgd
206 1.1 cgd # define other(x) (1 - x)
207 1.1 cgd # define nextplay() (Play = other(Play))
208 1.1 cgd # define nextwin(x) (1 - x)
209 1.1 cgd # define opposite(x) (Opposite[x])
210 1.11 jsm # define is_safety(x) (x >= C_GAS_SAFE)
211 1.1 cgd
212 1.1 cgd /*
213 1.1 cgd * externals
214 1.1 cgd */
215 1.1 cgd
216 1.1 cgd extern bool Debug, Finished, Next, On_exit, Order, Saved;
217 1.1 cgd
218 1.10 jsm extern char Initstr[];
219 1.10 jsm extern const char *C_fmt, *const *C_name, *Fromfile;
220 1.1 cgd
221 1.10 jsm extern int Card_no, End, Handstart, Movetype, Numgos,
222 1.10 jsm Numneed[], Numseen[NUM_CARDS], Play, Window;
223 1.10 jsm extern const int Numcards[], Value[];
224 1.1 cgd
225 1.10 jsm extern CARD Deck[DECK_SZ], Discard, Sh_discard, *Topcard;
226 1.10 jsm extern const CARD Opposite[NUM_CARDS];
227 1.1 cgd
228 1.1 cgd extern FILE *outf;
229 1.1 cgd
230 1.1 cgd extern PLAY Player[2];
231 1.1 cgd
232 1.1 cgd extern WINDOW *Board, *Miles, *Score;
233 1.1 cgd
234 1.1 cgd /*
235 1.1 cgd * functions
236 1.1 cgd */
237 1.1 cgd
238 1.7 lukem void account __P((CARD));
239 1.7 lukem void calcmove __P((void));
240 1.10 jsm int canplay __P((const PLAY *, const PLAY *, CARD));
241 1.7 lukem int check_ext __P((bool));
242 1.7 lukem void check_go __P((void));
243 1.7 lukem void check_more __P((void));
244 1.9 hubertf void die __P((int)) __attribute__((__noreturn__));
245 1.7 lukem void domove __P((void));
246 1.8 mycroft bool error __P((const char *, ...));
247 1.7 lukem void extrapolate __P((PLAY *));
248 1.7 lukem void finalscore __P((PLAY *));
249 1.7 lukem CARD getcard __P((void));
250 1.7 lukem void getmove __P((void));
251 1.7 lukem int getyn __P((int));
252 1.10 jsm int haspicked __P((const PLAY *));
253 1.7 lukem void init __P((void));
254 1.11 jsm int is_repair __P((CARD));
255 1.7 lukem int main __P((int, char **));
256 1.7 lukem void newboard __P((void));
257 1.7 lukem void newscore __P((void));
258 1.10 jsm int onecard __P((const PLAY *));
259 1.7 lukem int playcard __P((PLAY *));
260 1.7 lukem void prboard __P((void));
261 1.7 lukem void prompt __P((int));
262 1.10 jsm void prscore __P((bool));
263 1.7 lukem int readch __P((void));
264 1.10 jsm bool rest_f __P((const char *));
265 1.7 lukem int roll __P((int, int));
266 1.7 lukem void rub __P((int));
267 1.7 lukem int safety __P((CARD));
268 1.7 lukem bool save __P((void));
269 1.7 lukem void show_card __P((int, int, CARD, CARD *));
270 1.7 lukem void show_score __P((int, int, int, int *));
271 1.7 lukem void shuffle __P((void));
272 1.7 lukem void sort __P((CARD *));
273 1.7 lukem void undoex __P((int));
274 1.7 lukem bool varpush __P((int, ssize_t __P((int, const struct iovec *, int))));
275