xref: /csrg-svn/games/monop/monop.c (revision 34788)
132258Sbostic /*
2*34788Sbostic  * Copyright (c) 1980 Regents of the University of California.
333202Sbostic  * All rights reserved.
433202Sbostic  *
533202Sbostic  * Redistribution and use in source and binary forms are permitted
6*34788Sbostic  * provided that the above copyright notice and this paragraph are
7*34788Sbostic  * duplicated in all such forms and that any documentation,
8*34788Sbostic  * advertising materials, and other materials related to such
9*34788Sbostic  * distribution and use acknowledge that the software was developed
10*34788Sbostic  * by the University of California, Berkeley.  The name of the
11*34788Sbostic  * University may not be used to endorse or promote products derived
12*34788Sbostic  * from this software without specific prior written permission.
13*34788Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34788Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34788Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1632258Sbostic  */
1732258Sbostic 
1832258Sbostic #ifndef lint
1933202Sbostic char copyright[] =
20*34788Sbostic "@(#) Copyright (c) 1980 Regents of the University of California.\n\
2133202Sbostic  All rights reserved.\n";
2233202Sbostic #endif /* not lint */
2332258Sbostic 
2433202Sbostic #ifndef lint
25*34788Sbostic static char sccsid[] = "@(#)monop.c	5.6 (Berkeley) 06/18/88";
2633202Sbostic #endif /* not lint */
2733202Sbostic 
2832258Sbostic # include	"monop.def"
2932258Sbostic 
3032258Sbostic /*
3132258Sbostic  *	This program implements a monopoly game
3232258Sbostic  */
3332258Sbostic main(ac, av)
3432258Sbostic reg int		ac;
3532258Sbostic reg char	*av[]; {
3632258Sbostic 
3732258Sbostic 
3832258Sbostic 	srand(getpid());
3932258Sbostic 	if (ac > 1) {
4032258Sbostic 		if (!rest_f(av[1]))
4132258Sbostic 			restore();
4232258Sbostic 	}
4332258Sbostic 	else {
4432258Sbostic 		getplayers();
4532258Sbostic 		init_players();
4632258Sbostic 		init_monops();
4732258Sbostic 	}
4832258Sbostic 	num_luck = sizeof lucky_mes / sizeof (char *);
4932258Sbostic 	init_decks();
5032258Sbostic 	signal(2, quit);
5132258Sbostic 	for (;;) {
5232258Sbostic 		printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
5332258Sbostic 			cur_p->money, board[cur_p->loc].name);
5432258Sbostic 		printturn();
5532258Sbostic 		force_morg();
5632258Sbostic 		execute(getinp("-- Command: ", comlist));
5732258Sbostic 	}
5832258Sbostic }
5932258Sbostic /*
6032258Sbostic  *	This routine gets the names of the players
6132258Sbostic  */
6232258Sbostic getplayers() {
6332258Sbostic 
6432258Sbostic 	reg char	*sp;
6532258Sbostic 	reg int		i, j;
6632258Sbostic 	char		buf[257];
6732258Sbostic 
6832258Sbostic blew_it:
6932258Sbostic 	for (;;) {
7032258Sbostic 		if ((num_play=get_int("How many players? ")) <= 0 ||
7132258Sbostic 		    num_play > MAX_PL)
7232258Sbostic 			printf("Sorry. Number must range from 1 to 9\n");
7332258Sbostic 		else
7432258Sbostic 			break;
7532258Sbostic 	}
7632258Sbostic 	cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY));
7732258Sbostic 	for (i = 0; i < num_play; i++) {
7832258Sbostic over:
7932258Sbostic 		printf("Player %d's name: ", i + 1);
8032258Sbostic 		for (sp = buf; (*sp=getchar()) != '\n'; sp++)
8132258Sbostic 			continue;
8232258Sbostic 		if (sp == buf)
8332258Sbostic 			goto over;
8432258Sbostic 		*sp++ = '\0';
8532258Sbostic 		strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf);
8632258Sbostic 		play[i].money = 1500;
8732258Sbostic 	}
8832258Sbostic 	name_list[i++] = "done";
8932258Sbostic 	name_list[i] = 0;
9032258Sbostic 	for (i = 0; i < num_play; i++)
9132258Sbostic 		for (j = i + 1; j < num_play; j++)
9232262Sbostic 			if (strcasecmp(name_list[i], name_list[j]) == 0) {
9332258Sbostic 				if (i != num_play - 1)
9432258Sbostic 					printf("Hey!!! Some of those are IDENTICAL!!  Let's try that again....\n");
9532258Sbostic 				else
9632258Sbostic 					printf("\"done\" is a reserved word.  Please try again\n");
9732258Sbostic 				for (i = 0; i < num_play; i++)
9832258Sbostic 					cfree(play[i].name);
9932258Sbostic 				cfree(play);
10032258Sbostic 				goto blew_it;
10132258Sbostic 			}
10232258Sbostic }
10332258Sbostic /*
10432258Sbostic  *	This routine figures out who goes first
10532258Sbostic  */
10632258Sbostic init_players() {
10732258Sbostic 
10832258Sbostic 	reg int	i, rl, cur_max;
10932258Sbostic 	bool	over;
11032258Sbostic 	int	max_pl;
11132258Sbostic 
11232258Sbostic again:
11332258Sbostic 	putchar('\n');
11432258Sbostic 	for (cur_max = i = 0; i < num_play; i++) {
11532258Sbostic 		printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6));
11632258Sbostic 		if (rl > cur_max) {
11732258Sbostic 			over = FALSE;
11832258Sbostic 			cur_max = rl;
11932258Sbostic 			max_pl = i;
12032258Sbostic 		}
12132258Sbostic 		else if (rl == cur_max)
12232258Sbostic 			over++;
12332258Sbostic 	}
12432258Sbostic 	if (over) {
12532258Sbostic 		printf("%d people rolled the same thing, so we'll try again\n",
12632258Sbostic 		    over + 1);
12732258Sbostic 		goto again;
12832258Sbostic 	}
12932258Sbostic 	player = max_pl;
13032258Sbostic 	cur_p = &play[max_pl];
13132258Sbostic 	printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
13232258Sbostic }
13332258Sbostic /*
13432258Sbostic  *	This routine initalizes the monopoly structures.
13532258Sbostic  */
13632258Sbostic init_monops() {
13732258Sbostic 
13832258Sbostic 	reg MON	*mp;
13932258Sbostic 	reg int	i;
14032258Sbostic 
14132258Sbostic 	for (mp = mon; mp < &mon[N_MON]; mp++) {
14232258Sbostic 		mp->name = mp->not_m;
14332258Sbostic 		for (i = 0; i < mp->num_in; i++)
14433217Sbostic 			mp->sq[i] = &board[mp->sqnums[i]];
14532258Sbostic 	}
14632258Sbostic }
147