xref: /csrg-svn/games/mille/init.c (revision 30201)
1*30201Sbostic /*
2*30201Sbostic  * Copyright (c) 1982 Regents of the University of California.
3*30201Sbostic  * All rights reserved.  The Berkeley software License Agreement
4*30201Sbostic  * specifies the terms and conditions for redistribution.
5*30201Sbostic  */
6*30201Sbostic 
7*30201Sbostic #ifndef lint
8*30201Sbostic static char sccsid[] = "@(#)init.c	5.1 (Berkeley) 11/26/86";
9*30201Sbostic #endif not lint
10*30201Sbostic 
11*30201Sbostic # include	"mille.h"
12*30201Sbostic 
13*30201Sbostic /*
14*30201Sbostic  * @(#)init.c	1.1 (Berkeley) 4/1/82
15*30201Sbostic  */
16*30201Sbostic 
17*30201Sbostic init() {
18*30201Sbostic 
19*30201Sbostic 	reg PLAY	*pp;
20*30201Sbostic 	reg int		i, j;
21*30201Sbostic 	reg CARD	card;
22*30201Sbostic 
23*30201Sbostic 	bzero(Numseen, sizeof Numseen);
24*30201Sbostic 	Numgos = 0;
25*30201Sbostic 
26*30201Sbostic 	for (i = 0; i < 2; i++) {
27*30201Sbostic 		pp = &Player[i];
28*30201Sbostic 		pp->hand[0] = C_INIT;
29*30201Sbostic 		for (j = 0; j < NUM_SAFE; j++) {
30*30201Sbostic 			pp->safety[j] = S_UNKNOWN;
31*30201Sbostic 			pp->coups[j] = FALSE;
32*30201Sbostic 		}
33*30201Sbostic 		for (j = 1; j < HAND_SZ; j++) {
34*30201Sbostic 			pp->hand[j] = *--Topcard;
35*30201Sbostic 			if (i == COMP) {
36*30201Sbostic 				account(card = *Topcard);
37*30201Sbostic 				if (issafety(card))
38*30201Sbostic 					pp->safety[card - S_CONV] = S_IN_HAND;
39*30201Sbostic 			}
40*30201Sbostic 		}
41*30201Sbostic 		pp->mileage = 0;
42*30201Sbostic 		pp->hand_tot = 0;
43*30201Sbostic 		pp->safescore = 0;
44*30201Sbostic 		pp->coupscore = 0;
45*30201Sbostic 		pp->can_go = FALSE;
46*30201Sbostic 		pp->speed = C_INIT;
47*30201Sbostic 		pp->battle = C_INIT;
48*30201Sbostic 		pp->new_speed = FALSE;
49*30201Sbostic 		pp->new_battle = FALSE;
50*30201Sbostic 		for (j = 0; j < NUM_MILES; j++)
51*30201Sbostic 			pp->nummiles[j] = 0;
52*30201Sbostic 	}
53*30201Sbostic 	if (Order)
54*30201Sbostic 		sort(Player[PLAYER].hand);
55*30201Sbostic 	Discard = C_INIT;
56*30201Sbostic 	Finished = FALSE;
57*30201Sbostic 	End = 700;
58*30201Sbostic }
59*30201Sbostic 
60*30201Sbostic shuffle() {
61*30201Sbostic 
62*30201Sbostic 	reg int		i, r;
63*30201Sbostic 	reg CARD	temp;
64*30201Sbostic 
65*30201Sbostic 	for (i = 0; i < DECK_SZ; i++) {
66*30201Sbostic 		r = roll(1, DECK_SZ) - 1;
67*30201Sbostic 		if (r < 0 || r > DECK_SZ - 1) {
68*30201Sbostic 			fprintf(stderr, "shuffle: card no. error: %d\n", r);
69*30201Sbostic 			die();
70*30201Sbostic 		}
71*30201Sbostic 		temp = Deck[r];
72*30201Sbostic 		Deck[r] = Deck[i];
73*30201Sbostic 		Deck[i] = temp;
74*30201Sbostic 	}
75*30201Sbostic 	Topcard = &Deck[DECK_SZ];
76*30201Sbostic }
77*30201Sbostic 
78*30201Sbostic newboard() {
79*30201Sbostic 
80*30201Sbostic 	register int	i;
81*30201Sbostic 	register PLAY	*pp;
82*30201Sbostic 	static int	first = TRUE;
83*30201Sbostic 
84*30201Sbostic 	if (first) {
85*30201Sbostic 		werase(Board);
86*30201Sbostic 		werase(Score);
87*30201Sbostic 		mvaddstr(5, 0, "--HAND--");
88*30201Sbostic 		mvaddch(6, 0, 'P');
89*30201Sbostic 		mvaddch(7, 0, '1');
90*30201Sbostic 		mvaddch(8, 0, '2');
91*30201Sbostic 		mvaddch(9, 0, '3');
92*30201Sbostic 		mvaddch(10, 0, '4');
93*30201Sbostic 		mvaddch(11, 0, '5');
94*30201Sbostic 		mvaddch(12, 0, '6');
95*30201Sbostic 		mvaddstr(13, 0, "--BATTLE--");
96*30201Sbostic 		mvaddstr(15, 0, "--SPEED--");
97*30201Sbostic 		mvaddstr(5, 20, "--DECK--");
98*30201Sbostic 		mvaddstr(7, 20, "--DISCARD--");
99*30201Sbostic 		mvaddstr(13, 20, "--BATTLE--");
100*30201Sbostic 		mvaddstr(15, 20, "--SPEED--");
101*30201Sbostic 		mvwaddstr(Miles, 0, 0, "--MILEAGE--");
102*30201Sbostic 		mvwaddstr(Miles, 0, 41, "--MILEAGE--");
103*30201Sbostic 		Sh_discard = -1;
104*30201Sbostic 		for (pp = Player; pp <= &Player[COMP]; pp++) {
105*30201Sbostic 			for (i = 0; i < HAND_SZ; i++)
106*30201Sbostic 				pp->sh_hand[i] = -1;
107*30201Sbostic 			pp->sh_battle = -1;
108*30201Sbostic 			pp->sh_speed = -1;
109*30201Sbostic 			pp->sh_mileage = -1;
110*30201Sbostic 		}
111*30201Sbostic 		first = FALSE;
112*30201Sbostic 	}
113*30201Sbostic 	else {
114*30201Sbostic 		for (i = 0; i < 5; i++) {
115*30201Sbostic 			move(i, 0);
116*30201Sbostic 			clrtoeol();
117*30201Sbostic 		}
118*30201Sbostic 		wmove(Miles, 1, 0);
119*30201Sbostic 		wclrtobot(Miles);
120*30201Sbostic 		wmove(Board, MOVE_Y + 1, MOVE_X);
121*30201Sbostic 		wclrtoeol(Board);
122*30201Sbostic 		wmove(Board, MOVE_Y + 2, MOVE_X);
123*30201Sbostic 		wclrtoeol(Board);
124*30201Sbostic 	}
125*30201Sbostic 	Sh_discard = -1;
126*30201Sbostic 	for (pp = Player; pp <= &Player[COMP]; pp++) {
127*30201Sbostic 		for (i = 0; i < NUM_SAFE; i++)
128*30201Sbostic 			pp->sh_safety[i] = FALSE;
129*30201Sbostic 		for (i = 0; i < NUM_MILES; i++)
130*30201Sbostic 			pp->sh_nummiles[i] = 0;
131*30201Sbostic 		pp->sh_safescore = -1;
132*30201Sbostic 	}
133*30201Sbostic 	newscore();
134*30201Sbostic }
135*30201Sbostic 
136*30201Sbostic newscore() {
137*30201Sbostic 
138*30201Sbostic 	reg int		i, new;
139*30201Sbostic 	register PLAY	*pp;
140*30201Sbostic 	static int	was_full = -1;
141*30201Sbostic 	static int	last_win = -1;
142*30201Sbostic 
143*30201Sbostic 	if (was_full < 0)
144*30201Sbostic 		was_full = (Window != W_FULL);
145*30201Sbostic 	stdscr = Score;
146*30201Sbostic 	move(0, 22);
147*30201Sbostic 	new = FALSE;
148*30201Sbostic 	if (inch() != 'Y') {
149*30201Sbostic 		erase();
150*30201Sbostic 		mvaddstr(0, 22,  "You   Comp   Value");
151*30201Sbostic 		mvaddstr(1, 2, "Milestones Played");
152*30201Sbostic 		mvaddstr(2, 8, "Each Safety");
153*30201Sbostic 		mvaddstr(3, 5, "All 4 Safeties");
154*30201Sbostic 		mvaddstr(4, 3, "Each Coup Fourre");
155*30201Sbostic 		mvaddstr(2, 37, "100");
156*30201Sbostic 		mvaddstr(3, 37, "300");
157*30201Sbostic 		mvaddstr(4, 37, "300");
158*30201Sbostic 		new = TRUE;
159*30201Sbostic 	}
160*30201Sbostic 	else if (((Window == W_FULL || Finished) ^ was_full) ||
161*30201Sbostic 		 pp->was_finished != Finished) {
162*30201Sbostic 		move(5, 1);
163*30201Sbostic 		clrtobot();
164*30201Sbostic 		new = TRUE;
165*30201Sbostic 	}
166*30201Sbostic 	else if (Window != last_win)
167*30201Sbostic 		new = TRUE;
168*30201Sbostic 	if (new) {
169*30201Sbostic 		for (i = 0; i < SCORE_Y; i++)
170*30201Sbostic 			mvaddch(i, 0, '|');
171*30201Sbostic 		move(SCORE_Y - 1, 1);
172*30201Sbostic 		while (addch('_') != ERR)
173*30201Sbostic 			continue;
174*30201Sbostic 		for (pp = Player; pp <= &Player[COMP]; pp++) {
175*30201Sbostic 			pp->sh_hand_tot = -1;
176*30201Sbostic 			pp->sh_total = -1;
177*30201Sbostic 			pp->sh_games = -1;
178*30201Sbostic 			pp->sh_safescore = -1;
179*30201Sbostic 		}
180*30201Sbostic 	}
181*30201Sbostic 	Player[PLAYER].was_finished = !Finished;
182*30201Sbostic 	Player[COMP].was_finished = !Finished;
183*30201Sbostic 	if (Window == W_FULL || Finished) {
184*30201Sbostic 		if (!was_full || new) {
185*30201Sbostic 			mvaddstr(5, 5, "Trip Completed");
186*30201Sbostic 			mvaddstr(6, 10, "Safe Trip");
187*30201Sbostic 			mvaddstr(7, 5, "Delayed Action");
188*30201Sbostic 			mvaddstr(8, 10, "Extension");
189*30201Sbostic 			mvaddstr(9, 11, "Shut-Out");
190*30201Sbostic 			mvaddstr(10, 21, "----   ----   -----");
191*30201Sbostic 			mvaddstr(11, 9, "Hand Total");
192*30201Sbostic 			mvaddstr(12, 20, "-----  -----");
193*30201Sbostic 			mvaddstr(13, 6, "Overall Total");
194*30201Sbostic 			mvaddstr(14, 15, "Games");
195*30201Sbostic 			mvaddstr(5, 37, "400");
196*30201Sbostic 			mvaddstr(6, 37, "300");
197*30201Sbostic 			mvaddstr(7, 37, "300");
198*30201Sbostic 			mvaddstr(8, 37, "200");
199*30201Sbostic 			mvaddstr(9, 37, "500");
200*30201Sbostic 		}
201*30201Sbostic 	}
202*30201Sbostic 	else
203*30201Sbostic 		if (was_full || new) {
204*30201Sbostic 			mvaddstr(5, 21, "----   ----   -----");
205*30201Sbostic 			mvaddstr(6, 9, "Hand Total");
206*30201Sbostic 			mvaddstr(7, 20, "-----  -----");
207*30201Sbostic 			mvaddstr(8, 6, "Overall Total");
208*30201Sbostic 			mvaddstr(9, 15, "Games");
209*30201Sbostic 			mvaddstr(11, 2, "p: pick");
210*30201Sbostic 			mvaddstr(12, 2, "u: use #");
211*30201Sbostic 			mvaddstr(13, 2, "d: discard #");
212*30201Sbostic 			mvaddstr(14, 2, "w: toggle window");
213*30201Sbostic 			mvaddstr(11, 21, "q: quit");
214*30201Sbostic 			if (!Order)
215*30201Sbostic 				mvaddstr(12, 21, "o: order hand");
216*30201Sbostic 			else
217*30201Sbostic 				mvaddstr(12, 21, "o: stop ordering");
218*30201Sbostic 			mvaddstr(13, 21, "s: save");
219*30201Sbostic 			mvaddstr(14, 21, "r: reprint");
220*30201Sbostic 		}
221*30201Sbostic 	stdscr = Board;
222*30201Sbostic 	was_full = (Window == W_FULL || Finished);
223*30201Sbostic 	last_win = Window;
224*30201Sbostic }
225