132258Sbostic /* 232258Sbostic * Copyright (c) 1987 Regents of the University of California. 332258Sbostic * All rights reserved. The Berkeley software License Agreement 432258Sbostic * specifies the terms and conditions for redistribution. 532258Sbostic */ 632258Sbostic 732258Sbostic #ifndef lint 8*32262Sbostic static char sccsid[] = "@(#)monop.c 5.2 (Berkeley) 09/26/87"; 932258Sbostic #endif not lint 1032258Sbostic 1132258Sbostic # include "monop.def" 1232258Sbostic 1332258Sbostic /* 1432258Sbostic * This program implements a monopoly game 1532258Sbostic */ 1632258Sbostic main(ac, av) 1732258Sbostic reg int ac; 1832258Sbostic reg char *av[]; { 1932258Sbostic 2032258Sbostic 2132258Sbostic srand(getpid()); 2232258Sbostic if (ac > 1) { 2332258Sbostic if (!rest_f(av[1])) 2432258Sbostic restore(); 2532258Sbostic } 2632258Sbostic else { 2732258Sbostic getplayers(); 2832258Sbostic init_players(); 2932258Sbostic init_monops(); 3032258Sbostic } 3132258Sbostic num_luck = sizeof lucky_mes / sizeof (char *); 3232258Sbostic init_decks(); 3332258Sbostic signal(2, quit); 3432258Sbostic for (;;) { 3532258Sbostic printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1, 3632258Sbostic cur_p->money, board[cur_p->loc].name); 3732258Sbostic printturn(); 3832258Sbostic force_morg(); 3932258Sbostic execute(getinp("-- Command: ", comlist)); 4032258Sbostic } 4132258Sbostic } 4232258Sbostic /* 4332258Sbostic * This routine gets the names of the players 4432258Sbostic */ 4532258Sbostic getplayers() { 4632258Sbostic 4732258Sbostic reg char *sp; 4832258Sbostic reg int i, j; 4932258Sbostic char buf[257]; 5032258Sbostic 5132258Sbostic blew_it: 5232258Sbostic for (;;) { 5332258Sbostic if ((num_play=get_int("How many players? ")) <= 0 || 5432258Sbostic num_play > MAX_PL) 5532258Sbostic printf("Sorry. Number must range from 1 to 9\n"); 5632258Sbostic else 5732258Sbostic break; 5832258Sbostic } 5932258Sbostic cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY)); 6032258Sbostic for (i = 0; i < num_play; i++) { 6132258Sbostic over: 6232258Sbostic printf("Player %d's name: ", i + 1); 6332258Sbostic for (sp = buf; (*sp=getchar()) != '\n'; sp++) 6432258Sbostic continue; 6532258Sbostic if (sp == buf) 6632258Sbostic goto over; 6732258Sbostic *sp++ = '\0'; 6832258Sbostic strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf); 6932258Sbostic play[i].money = 1500; 7032258Sbostic } 7132258Sbostic name_list[i++] = "done"; 7232258Sbostic name_list[i] = 0; 7332258Sbostic for (i = 0; i < num_play; i++) 7432258Sbostic for (j = i + 1; j < num_play; j++) 75*32262Sbostic if (strcasecmp(name_list[i], name_list[j]) == 0) { 7632258Sbostic if (i != num_play - 1) 7732258Sbostic printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n"); 7832258Sbostic else 7932258Sbostic printf("\"done\" is a reserved word. Please try again\n"); 8032258Sbostic for (i = 0; i < num_play; i++) 8132258Sbostic cfree(play[i].name); 8232258Sbostic cfree(play); 8332258Sbostic goto blew_it; 8432258Sbostic } 8532258Sbostic } 8632258Sbostic /* 8732258Sbostic * This routine figures out who goes first 8832258Sbostic */ 8932258Sbostic init_players() { 9032258Sbostic 9132258Sbostic reg int i, rl, cur_max; 9232258Sbostic bool over; 9332258Sbostic int max_pl; 9432258Sbostic 9532258Sbostic again: 9632258Sbostic putchar('\n'); 9732258Sbostic for (cur_max = i = 0; i < num_play; i++) { 9832258Sbostic printf("%s (%d) rolls %d\n", play[i].name, i+1, rl=roll(2, 6)); 9932258Sbostic if (rl > cur_max) { 10032258Sbostic over = FALSE; 10132258Sbostic cur_max = rl; 10232258Sbostic max_pl = i; 10332258Sbostic } 10432258Sbostic else if (rl == cur_max) 10532258Sbostic over++; 10632258Sbostic } 10732258Sbostic if (over) { 10832258Sbostic printf("%d people rolled the same thing, so we'll try again\n", 10932258Sbostic over + 1); 11032258Sbostic goto again; 11132258Sbostic } 11232258Sbostic player = max_pl; 11332258Sbostic cur_p = &play[max_pl]; 11432258Sbostic printf("%s (%d) goes first\n", cur_p->name, max_pl + 1); 11532258Sbostic } 11632258Sbostic /* 11732258Sbostic * This routine initalizes the monopoly structures. 11832258Sbostic */ 11932258Sbostic init_monops() { 12032258Sbostic 12132258Sbostic reg MON *mp; 12232258Sbostic reg int i; 12332258Sbostic 12432258Sbostic for (mp = mon; mp < &mon[N_MON]; mp++) { 12532258Sbostic mp->name = mp->not_m; 12632258Sbostic for (i = 0; i < mp->num_in; i++) 12732258Sbostic mp->sq[i] = &board[(int)(mp->sq[i])]; 12832258Sbostic } 12932258Sbostic } 130