132258Sbostic /* 232258Sbostic * Copyright (c) 1987 Regents of the University of California. 3*33202Sbostic * All rights reserved. 4*33202Sbostic * 5*33202Sbostic * Redistribution and use in source and binary forms are permitted 6*33202Sbostic * provided that this notice is preserved and that due credit is given 7*33202Sbostic * to the University of California at Berkeley. The name of the University 8*33202Sbostic * may not be used to endorse or promote products derived from this 9*33202Sbostic * software without specific prior written permission. This software 10*33202Sbostic * is provided ``as is'' without express or implied warranty. 1132258Sbostic */ 1232258Sbostic 1332258Sbostic #ifndef lint 14*33202Sbostic char copyright[] = 15*33202Sbostic "@(#) Copyright (c) 1987 Regents of the University of California.\n\ 16*33202Sbostic All rights reserved.\n"; 17*33202Sbostic #endif /* not lint */ 1832258Sbostic 19*33202Sbostic #ifndef lint 20*33202Sbostic static char sccsid[] = "@(#)monop.c 5.3 (Berkeley) 01/02/88"; 21*33202Sbostic #endif /* not lint */ 22*33202Sbostic 2332258Sbostic # include "monop.def" 2432258Sbostic 2532258Sbostic /* 2632258Sbostic * This program implements a monopoly game 2732258Sbostic */ 2832258Sbostic main(ac, av) 2932258Sbostic reg int ac; 3032258Sbostic reg char *av[]; { 3132258Sbostic 3232258Sbostic 3332258Sbostic srand(getpid()); 3432258Sbostic if (ac > 1) { 3532258Sbostic if (!rest_f(av[1])) 3632258Sbostic restore(); 3732258Sbostic } 3832258Sbostic else { 3932258Sbostic getplayers(); 4032258Sbostic init_players(); 4132258Sbostic init_monops(); 4232258Sbostic } 4332258Sbostic num_luck = sizeof lucky_mes / sizeof (char *); 4432258Sbostic init_decks(); 4532258Sbostic signal(2, quit); 4632258Sbostic for (;;) { 4732258Sbostic printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1, 4832258Sbostic cur_p->money, board[cur_p->loc].name); 4932258Sbostic printturn(); 5032258Sbostic force_morg(); 5132258Sbostic execute(getinp("-- Command: ", comlist)); 5232258Sbostic } 5332258Sbostic } 5432258Sbostic /* 5532258Sbostic * This routine gets the names of the players 5632258Sbostic */ 5732258Sbostic getplayers() { 5832258Sbostic 5932258Sbostic reg char *sp; 6032258Sbostic reg int i, j; 6132258Sbostic char buf[257]; 6232258Sbostic 6332258Sbostic blew_it: 6432258Sbostic for (;;) { 6532258Sbostic if ((num_play=get_int("How many players? ")) <= 0 || 6632258Sbostic num_play > MAX_PL) 6732258Sbostic printf("Sorry. Number must range from 1 to 9\n"); 6832258Sbostic else 6932258Sbostic break; 7032258Sbostic } 7132258Sbostic cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY)); 7232258Sbostic for (i = 0; i < num_play; i++) { 7332258Sbostic over: 7432258Sbostic printf("Player %d's name: ", i + 1); 7532258Sbostic for (sp = buf; (*sp=getchar()) != '\n'; sp++) 7632258Sbostic continue; 7732258Sbostic if (sp == buf) 7832258Sbostic goto over; 7932258Sbostic *sp++ = '\0'; 8032258Sbostic strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf); 8132258Sbostic play[i].money = 1500; 8232258Sbostic } 8332258Sbostic name_list[i++] = "done"; 8432258Sbostic name_list[i] = 0; 8532258Sbostic for (i = 0; i < num_play; i++) 8632258Sbostic for (j = i + 1; j < num_play; j++) 8732262Sbostic if (strcasecmp(name_list[i], name_list[j]) == 0) { 8832258Sbostic if (i != num_play - 1) 8932258Sbostic printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n"); 9032258Sbostic else 9132258Sbostic printf("\"done\" is a reserved word. Please try again\n"); 9232258Sbostic for (i = 0; i < num_play; i++) 9332258Sbostic cfree(play[i].name); 9432258Sbostic cfree(play); 9532258Sbostic goto blew_it; 9632258Sbostic } 9732258Sbostic } 9832258Sbostic /* 9932258Sbostic * This routine figures out who goes first 10032258Sbostic */ 10132258Sbostic init_players() { 10232258Sbostic 10332258Sbostic reg int i, rl, cur_max; 10432258Sbostic bool over; 10532258Sbostic int max_pl; 10632258Sbostic 10732258Sbostic again: 10832258Sbostic putchar('\n'); 10932258Sbostic for (cur_max = i = 0; i < num_play; i++) { 11032258Sbostic printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6)); 11132258Sbostic if (rl > cur_max) { 11232258Sbostic over = FALSE; 11332258Sbostic cur_max = rl; 11432258Sbostic max_pl = i; 11532258Sbostic } 11632258Sbostic else if (rl == cur_max) 11732258Sbostic over++; 11832258Sbostic } 11932258Sbostic if (over) { 12032258Sbostic printf("%d people rolled the same thing, so we'll try again\n", 12132258Sbostic over + 1); 12232258Sbostic goto again; 12332258Sbostic } 12432258Sbostic player = max_pl; 12532258Sbostic cur_p = &play[max_pl]; 12632258Sbostic printf("%s (%d) goes first\n", cur_p->name, max_pl + 1); 12732258Sbostic } 12832258Sbostic /* 12932258Sbostic * This routine initalizes the monopoly structures. 13032258Sbostic */ 13132258Sbostic init_monops() { 13232258Sbostic 13332258Sbostic reg MON *mp; 13432258Sbostic reg int i; 13532258Sbostic 13632258Sbostic for (mp = mon; mp < &mon[N_MON]; mp++) { 13732258Sbostic mp->name = mp->not_m; 13832258Sbostic for (i = 0; i < mp->num_in; i++) 13932258Sbostic mp->sq[i] = &board[(int)(mp->sq[i])]; 14032258Sbostic } 14132258Sbostic } 142