[comp.sources.games] v07i016: hotel - boardgame of hotel development, Part02/02

billr@saab.CNA.TEK.COM (Bill Randle) (07/12/89)

Submitted-by: srt@aerospace.aero.org
Posting-number: Volume 7, Issue 16
Archive-name: hotel/Part02


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 2)."
# Contents:  Notice costs.c defs.h help.c makefile my_wgets.c
#   my_wgets.h pcdisp.c utils.c
# Wrapped by billr@saab on Wed Jul 12 07:06:47 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Notice' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Notice'\"
else
echo shar: Extracting \"'Notice'\" \(2164 characters\)
sed "s/^X//" >'Notice' <<'END_OF_FILE'
X
X This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X in both source code and executable form.  Permission is given to 
X copy both the source code and the executable under the following
X conditions:
X 
X   1. You may copy and distribute verbatim copies of Hotel code as you
X receive it, in any medium, provided that you conspicuously and
X appropriately publish on each file a valid copyright notice such as
X "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
X and license notices on all files.  You may charge a distribution fee
X for the physical act of transferring a copy, but that fee may not
X exceed your actual costs in creating and delivering the copy.
X 
X   2. You may modify your copy or copies of Hotel or any portion of it,
X and copy and distribute such modifications under the terms of
X Paragraph 1 above, provided that you also do the following:
X 
X     a) cause the modified files to carry prominent notices stating
X     who last changed such files and the date of any change; and
X 
X     b) cause the whole of any work that you distribute or publish,
X     that in whole or in part contains or is a derivative of Hotel
X     or any part thereof, to be licensed at no charge to all third
X     parties on terms identical to those contained in this License
X     Agreement (except that you may choose to grant more extensive
X     warranty protection to third parties, at your option).
X
X   3. You may not copy, sublicense, distribute or transfer Hotel
X except as expressly provided under this License Agreement.  Any attempt
X otherwise to copy, sublicense, distribute or transfer Hotel is void and
X your rights to use Hotel under this License agreement shall be
X automatically terminated.  However, parties who have received computer
X software programs from you with this License Agreement will not have
X their licenses terminated so long as such parties remain in full compliance.
X 
X   4.  Under no circumstances may you charge for copies of Hotel, for copies
X of any program containing code from Hotel in whole or in part, or for 
X any software package or collection of programs or code that contains Hotel
X in whole or part.
END_OF_FILE
if test 2164 -ne `wc -c <'Notice'`; then
    echo shar: \"'Notice'\" unpacked with wrong size!
fi
# end of 'Notice'
fi
if test -f 'costs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'costs.c'\"
else
echo shar: Extracting \"'costs.c'\" \(3554 characters\)
sed "s/^X//" >'costs.c' <<'END_OF_FILE'
X/*
X * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X * in both source code and executable form.  Permission is given to 
X * copy both the source code and the executable under the following
X * conditions:
X * 
X * COPYING POLICIES
X * 
X *   1. You may copy and distribute verbatim copies of Hotel code as you
X * receive it, in any medium, provided that you conspicuously and
X * appropriately publish on each file a valid copyright notice such as
X * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
X * and license notices on all files.  You may charge a distribution fee for the
X * physical act of transferring a copy, but that fee may not exceed
X * your actual costs in creating and delivering the copy.
X * 
X *   2. You may modify your copy or copies of Hotel or any portion of it,
X * and copy and distribute such modifications under the terms of
X * Paragraph 1 above, provided that you also do the following:
X * 
X *     a) cause the modified files to carry prominent notices stating
X *     who last changed such files and the date of any change; and
X * 
X *     b) cause the whole of any work that you distribute or publish,
X *     that in whole or in part contains or is a derivative of Hotel
X *     or any part thereof, to be licensed at no charge to all third
X *     parties on terms identical to those contained in this License
X *     Agreement (except that you may choose to grant more extensive
X *     warranty protection to third parties, at your option).
X *
X *   3. You may not copy, sublicense, distribute or transfer Hotel
X * except as expressly provided under this License Agreement.  Any attempt
X * otherwise to copy, sublicense, distribute or transfer Hotel is void and
X * your rights to use Hotel under this License agreement shall be
X * automatically terminated.  However, parties who have received computer
X * software programs from you with this License Agreement will not have
X * their licenses terminated so long as such parties remain in full compliance.
X * 
X *   4.  Under no circumstances may you charge for copies of Hotel, for copies
X * of any program containing code from Hotel in whole or in part, or for 
X * any software package or collection of programs or code that contains Hotel
X * in whole or part.
X *
X */ 
X/*
X *  COSTS
X *  Scott R. Turner
X *  9/10/88
X *
X *  Costs contains the functions to compute the cost of a share of stock in
X *  a hotel and the function to figure the majority holders bonus.
X *
X */
X
X#include "defs.h"
X
X/*
X *  Share_cost returns the cost per share of a hotel.
X *
X */
X
Xstatic int cost_table[42] = { 0, 0,
X /*  2    3    4    5    6    7    8    9   10   */
X    200, 300, 400, 500, 600, 600, 600, 600, 600,
X /* 11   12   13   14   15   16   17   18   19   20  */
X    700, 700, 700, 700, 700, 700, 700, 700, 700, 700,
X /* 21   22   23   24   25   26   27   28   29  30  */
X    800, 800, 800, 800, 800, 800, 800, 800, 800, 800,
X /* 31   32   33   34   35   36   37   38   39   40   41+ */
X    900, 900, 900, 900, 900, 900, 900, 900, 900, 900, 1000};
X
Xshare_cost(hot)
X     int hot;
X{
X
X  if (hotels[hot].size < 2) {
X    return(cost_table[2]+(100*hotels[hot].class));
X  } else if (hotels[hot].size > 40) {
X    return(cost_table[41]+(100 * hotels[hot].class));
X  } else return(cost_table[hotels[hot].size]+(100*hotels[hot].class));
X  
X};
X
X/*
X *  majority_bonus returns the first & second major holders bonuses.
X *
X */
X
Xmajority_bonus (hot, first, second)
X     int hot, *first, *second;
X{
X  int cost;
X
X  cost = share_cost(hot);
X  *first = 10*cost;
X  *second = 5*cost;
X
X};
END_OF_FILE
if test 3554 -ne `wc -c <'costs.c'`; then
    echo shar: \"'costs.c'\" unpacked with wrong size!
fi
# end of 'costs.c'
fi
if test -f 'defs.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'defs.h'\"
else
echo shar: Extracting \"'defs.h'\" \(3776 characters\)
sed "s/^X//" >'defs.h' <<'END_OF_FILE'
X/*
X * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X * in both source code and executable form.  Permission is given to 
X * copy both the source code and the executable under the following
X * conditions:
X * 
X * COPYING POLICIES
X * 
X *   1. You may copy and distribute verbatim copies of Hotel code as you
X * receive it, in any medium, provided that you conspicuously and
X * appropriately publish on each file a valid copyright notice such as
X * "Copyright (C) 1986 Scott R. Turner", and keep intact the copyright
X * and license notices on all files.  You may charge a distribution fee for the
X * physical act of transferring a copy, but that fee may not exceed
X * your actual costs in creating and delivering the copy.
X * 
X *   2. You may modify your copy or copies of Hotel or any portion of it,
X * and copy and distribute such modifications under the terms of
X * Paragraph 1 above, provided that you also do the following:
X * 
X *     a) cause the modified files to carry prominent notices stating
X *     who last changed such files and the date of any change; and
X * 
X *     b) cause the whole of any work that you distribute or publish,
X *     that in whole or in part contains or is a derivative of Hotel
X *     or any part thereof, to be licensed at no charge to all third
X *     parties on terms identical to those contained in this License
X *     Agreement (except that you may choose to grant more extensive
X *     warranty protection to third parties, at your option).
X *
X *   3. You may not copy, sublicense, distribute or transfer Hotel
X * except as expressly provided under this License Agreement.  Any attempt
X * otherwise to copy, sublicense, distribute or transfer Hotel is void and
X * your rights to use Hotel under this License agreement shall be
X * automatically terminated.  However, parties who have received computer
X * software programs from you with this License Agreement will not have
X * their licenses terminated so long as such parties remain in full compliance.
X * 
X *   4.  Under no circumstances may you charge for copies of Hotel, for copies
X * of any program containing code from Hotel in whole or in part, or for 
X * any software package or collection of programs or code that contains Hotel
X * in whole or part.
X *
X */ 
X/*
X    defs.h
X    Scott R. Turner
X    9/7/88
X
X    This file contains the data structure and constant 
X    definitions for Hotel.
X
X*/
X#include <stdio.h>
X#include <curses.h>
X#include <ctype.h>
X
X/*  Constants */
X
X#define MAXHOTELS 12
X#define MAXPLAYERS 7
X#define MAXBOARD 20
X#define MAXSTRATEGIES 20
X#define MAXSHARES 50
X#define TURNLIMIT 100
X#define UNUSED 99           /* Placed but unused tiles. */
X#define UNPLAYABLE -100     /* Tiles which aren't playable because they would
X			     * merge two safe hotel chains.
X			     */
X
X/* Interaction Defines */
X
X#define REFRESHKEY 12
X#define QUITKEY 'Q'
X#define HELPKEY 'H'
X
X/* Functions */
X
X#define round(x) (int) (x + .5)
X
X/*  Hotel Definition */
X
Xtypedef struct hotelstruct {
X  int size;      /* # of squares occupied */
X  int shares;    /* # of outstanding shares */
X  int class;     /* price class */
X  char name[80]; /* name of hotel */
X} hotel;
X
X/*  Player Definition */
X
Xtypedef struct playerstruct {
X  long cash;                /* Cash on hand for this player */
X  int strategy;             /* Strategy, 0  Human Player */
X  char name[80];            /* Name of player */
X  int shares[MAXHOTELS];    /* # shares in each hotel */
X} player;
X
Xextern hotel hotels[MAXHOTELS+1];
Xextern player players[MAXPLAYERS+1];
Xextern int board[MAXBOARD+1][MAXBOARD+1]; 
Xextern int numplayers, numhotels, boardsize,
X  numshares, numtiles, startcash,pnum;  
Xextern int turn, maxbuy;
Xextern WINDOW *iowin;
Xextern int debug;  /* Debug flag */
Xextern int human_player;
END_OF_FILE
if test 3776 -ne `wc -c <'defs.h'`; then
    echo shar: \"'defs.h'\" unpacked with wrong size!
fi
# end of 'defs.h'
fi
if test -f 'help.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'help.c'\"
else
echo shar: Extracting \"'help.c'\" \(7991 characters\)
sed "s/^X//" >'help.c' <<'END_OF_FILE'
X/*
X * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X * in both source code and executable form.  Permission is given to 
X * copy both the source code and the executable under the following
X * conditions:
X * 
X * COPYING POLICIES
X * 
X *   1. You may copy and distribute verbatim copies of Hotel code as you
X * receive it, in any medium, provided that you conspicuously and
X * appropriately publish on each file a valid copyright notice such as
X * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
X * and license notices on all files.  You may charge a distribution fee for the
X * physical act of transferring a copy, but that fee may not exceed
X * your actual costs in creating and delivering the copy.
X * 
X *   2. You may modify your copy or copies of Hotel or any portion of it,
X * and copy and distribute such modifications under the terms of
X * Paragraph 1 above, provided that you also do the following:
X * 
X *     a) cause the modified files to carry prominent notices stating
X *     who last changed such files and the date of any change; and
X * 
X *     b) cause the whole of any work that you distribute or publish,
X *     that in whole or in part contains or is a derivative of Hotel
X *     or any part thereof, to be licensed at no charge to all third
X *     parties on terms identical to those contained in this License
X *     Agreement (except that you may choose to grant more extensive
X *     warranty protection to third parties, at your option).
X *
X *   3. You may not copy, sublicense, distribute or transfer Hotel
X * except as expressly provided under this License Agreement.  Any attempt
X * otherwise to copy, sublicense, distribute or transfer Hotel is void and
X * your rights to use Hotel under this License agreement shall be
X * automatically terminated.  However, parties who have received computer
X * software programs from you with this License Agreement will not have
X * their licenses terminated so long as such parties remain in full compliance.
X * 
X *   4.  Under no circumstances may you charge for copies of Hotel, for copies
X * of any program containing code from Hotel in whole or in part, or for 
X * any software package or collection of programs or code that contains Hotel
X * in whole or part.
X *
X */ 
X/*
X *  help.c
X *  Scott R. Turner
X *  2/1/89
X * 
X *  This file contains the help screen.
X *
X */
X#include "defs.h"
Xextern void any_key();
X
Xvoid help()
X{
X    char ch;	
Xclear();
Xprintw("                   About Hotel\n\n");
Xprintw("Hotel is game of building and controlling hotel chains.  It is played\n");
Xprintw("on a %d by %d board.  Each player takes turns placing tiles on the\n", boardsize, boardsize);
Xprintw("board.  When two tiles are adjacent, a new hotel is created, and the creator\n");
Xprintw("is given one share of stock in the new hotel.  The hotels are numbered\n");
Xprintw("A, B, C and so on.  There can be a maximum of %d hotels.\n",numhotels);
Xprintw("\nThe Screen\n\n");
Xprintw("The left portion of the screen will display the board.  Hotel chains will\n");
Xprintw("be shown by the appropriate capital letter.  Played tiles which are not a\n");
Xprintw("part of any hotel chain are shown as boxes.  Tiles which you can play are\n");
Xprintw("number from 1 to %d.\n\n",numtiles);
Xprintw("The right side of the screen shows the status of all the hotels and how much\n");
Xprintw("money you currently have.  For each hotel, one line shows the cost of a share\n");
Xprintw("in that hotel, how many shares you currently hold, and how many shares are\n");
Xprintw("still available.\n\n");
Xprintw("---Hit any key to continue---");
Xrefresh();
Xch = getch();
Xclear();
Xprintw("\nThe Play\n\n");
Xprintw("You can play a tile by simply typing the number of the tile you wish to play.\n");
Xprintw("If your play creates a new hotel, you will be asked to choose which hotel\n");
Xprintw("you'd like to create.  If no hotels are available, you are not allowed to make\n");
Xprintw("a play which would create a new hotel.\n\n");
Xprintw("If your play makes two hotels touch each other, the smaller hotel is merged\n");
Xprintw("into the larger hotel.  If both are the same size, you are given your choice\n");
Xprintw("which to merge.  When a hotel is merged, everyone who owns stock in the merged\n");
Xprintw("hotel is given a chance to trade in or sell their stock.  In addition, the two\n");
Xprintw("players who own the most stock in the merged hotel are paid bonuses.  This\n");
Xprintw("is the only source of income in the game.\n\n");
Xprintw("When a hotel reaches a size of 10, it is said to be `safe' and cannot be\n");
Xprintw("merged into another hotel.\n\n");
Xprintw("The game ends when all the hotels are safe or when one hotel covers almost\n");
Xprintw("half the board.\n\n");
Xprintw("---Hit any key to continue---");
Xrefresh();
Xch = getch();
Xclear();
Xprintw("\nStock\n\n");
Xprintw("Each turn, you may purchase up to three shares of stock.  To purchase a share,\n");
Xprintw("type the letter corresponding to the hotel.  If you do not have enough money\n");
Xprintw("for the purchase, or if the hotel's stock is not currently available, the game\n");
Xprintw("will beep and reject your purchase.\n\n");
Xprintw("To purchase less than three shares, type a carriage return to end your\n");
Xprintw("purchasing.\n\n");
Xprintw("As a hotel grows in size, its stock becomes more expensive, so\n");
Xprintw("it is a good idea to enlarge the hotels you own stock in.\n\n");
Xprintw("---Hit any key to continue---");
Xrefresh();
Xch = getch();
Xclear();
Xprintw("\nGeneral\n\n");
Xprintw("Most of the time, the 'q' key will quit the game and ^L will refresh\n");
Xprintw("the screen.  'h' will usually give some help.\n");
Xprintw("\nCredits\n\n");
Xprintw("Hotel was written by Scott R. Turner (srt@cs.ucla.edu).  Special thanks\n");
Xprintw("must go to Matthew Merzbacher (matthew@cs.ucla.edu) for help in debugging\n");
Xprintw("and testing the various versions, and for helping me win the 1989 ACM\n");
Xprintw("Scholastic Programming Championship.\n\n");
Xprintw("---Hit any key to continue---");
Xrefresh();
Xch = getch();
Xclear();
X};
X
Xvoid anykey_help()
X{
X    int y,x;
X    getyx(curscr,y,x);
X    move((LINES-2),0);
X    clrtobot();
X    printw("Hit any key to continue on with the program.  You may hit\n");
X    printw("`Q' to quit the program, or `^L' to refresh the screen.");
X    move(y,x);
X    refresh();
X};
X
Xvoid getnum_help()
X{
X    int y,x;
X    getyx(curscr,y,x);
X    move((LINES-2),0);
X    clrtobot();
X    printw("You should enter a number indicating the tile you wish to play.\n");
X    printw("You may also enter `Q' to quit or `^L' to refresh the screen.\n");
X    move(y,x);
X    refresh();
X};
X
Xvoid buy_help()
X{
X    int y,x;
X    getyx(curscr,y,x);
X    move((LINES-5),0);
X    clrtobot();
X    printw("Type the letter for the hotel for each stock you wish to buy, up\n");
X    printw("to a maximum of three.  For instance, typing `abb' would buy two shares\n");
X    printw("of Hotel B and one share of A.  To buy less than three shares, hit a\n");
X    printw("carriage return to end.  The computer will beep if you do not have the\n");
X    printw("money to make a purchase or if there is no stock available.");
X    move(y,x);
X    refresh();
X};
X
Xvoid newhotel_help()
X{
X    int y,x;
X    getyx(curscr,y,x);
X    move((LINES-3),0);
X    clrtobot();
X    printw("You are being asked to select a hotel to create.  Type the letter of one\n");
X    printw("of the available hotels.  You may also type `Q' to quit and `^L' to\n");
X    printw("refresh the screen.");
X    move(y,x);
X    refresh();
X};
X    
Xvoid save_help()
X{
X    int y,x;
X    getyx(curscr,y,x);
X    move((LINES-4),0);
X    clrtobot();
X    printw("You are being asked which of two or more hotels to save.  All the hotels\n");
X    printw("are the same size, and all of them will be liquidated EXCEPT the one you\n");
X    printw("choose to save.  Type the letter of the hotel to save, or `Q' to quit or\n");
X    printw("type `^L' to refresh the screen.");
X    move(y,x);
X    refresh();
X};
X
END_OF_FILE
if test 7991 -ne `wc -c <'help.c'`; then
    echo shar: \"'help.c'\" unpacked with wrong size!
fi
# end of 'help.c'
fi
if test -f 'makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile'\"
else
echo shar: Extracting \"'makefile'\" \(1051 characters\)
sed "s/^X//" >'makefile' <<'END_OF_FILE'
X#  Makefile for Hotel
X
XOBJECTS = hotel.o human.o comp.o init.o utils.o costs.o help.o my_wgets.o display.o
XPCOBJECTS = hotel.obj human.obj comp.obj init.obj utils.obj costs.obj display.obj help.obj my_wgets.obj
XSOURCE = init.c utils.c hotel.c human.c costs.c comp.c help.c my_wgets.c
XCFLAGS = -DUNIX
X
X.c.obj:
X	tcc -ms -c -a -N -v -DTURBO  $<
X
Xhotel: $(OBJECTS)
X	cc -o hotel -O $(OBJECTS)  -lcurses -ltermcap
X
Xpchotel: $(PCOBJECTS)
X	tcc -ms $(PCOBJECTS) scurses.lib
X
Xshar: hotel.1 hotel.2
Xhotel.1: README comp.c costs.c defs.h help.c makefile
X	shar README comp.c costs.c defs.h help.c makefile > hotel.1
Xhotel.2: hotel.c human.c init.c utils.c my_wgets.c my_wgets.h Notice
X	shar hotel.c human.c init.c utils.c display.c my_wgets.c my_wgets.h Notice > hotel.2
X
Xdisplay.obj: defs.h
Xcomp.c: defs.h
Xhotel.obj: defs.h
Xinit.obj: defs.h
Xutils.obj: defs.h
Xhuman.obj: defs.h my_wgets.h
Xcosts.obj: defs.h
Xhelp.obj: defs.h
X
Xdisplay.o: defs.h
Xcomp.c: defs.h
Xhotel.o: defs.h
Xinit.o: defs.h
Xutils.o: defs.h
Xhuman.o: defs.h my_wgets.h
Xcosts.o: defs.h
Xhelp.o: defs.h
X
END_OF_FILE
if test 1051 -ne `wc -c <'makefile'`; then
    echo shar: \"'makefile'\" unpacked with wrong size!
fi
# end of 'makefile'
fi
if test -f 'my_wgets.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'my_wgets.c'\"
else
echo shar: Extracting \"'my_wgets.c'\" \(4382 characters\)
sed "s/^X//" >'my_wgets.c' <<'END_OF_FILE'
X/*
X * A possible replacement for curses' wgetstr(). Allows
X * line editing as in csh. 
X * Recognizes the erase, kill chars, word deleting.
X *
X * By Hung Le (mott@ucscb.ucsc.edu  ...!ucbvax!ucscc!ucscb!mott)
X * History:
X *	01/18/89 - Initial version 
X *	03/20/89 - Add control-w to delete word
X *  05/17/89 - add option to return immediately or to bell()
X *			when buffer is full.
X *
X * Release to Public Domain 
X */
X#include <curses.h>
X#ifdef UNIX
X#include <sys/ioctl.h>
X#include <sgtty.h>
X#endif 
X
X#define STD_INPUT 0		/* standard input */
X#define NEWLINE '\n'
X#define SPACE ' '
X/* default for erase and kill characters */
X#define ERASE '\010'
X#define KILL '\025'
X#define WORD '\027'
X
X/* You bugger !!! you did something wrong */
X#define bell() fprintf(stderr,"%c", '\007')
X
X/*
X * my_wgetstr(WINDOW *win, char *str, int size, int ret)
X *	win: the concerned window
X * 	str: buffer holding input
X *	size: (size -1) is the maximum chars to get
X *	ret: flag indicating what to do when (size -1) is reached
X *		0: ring bell()
X *		1: returns
X *		two macros are defined in "my_wgetstr.h" as RET=1 and NO_RET=0
X *
X * works same as wgetstr() in curses but allows editing.
X * Recognizes the erase character and the kill character and
X * WORD as the word deleting char.
X * Will try to get the erase and kill char from the terminal setting.
X * If failed, will use the default ERASE and KILL definitions.
X * Word char is set to WORD.
X *
X * DOES NOT check for illegal scrolling.
X * Returns
X *	. when received a new line character 
X *	. if ( (strlen(str) == (size - 1)) and (ret) )		
X *
X * str[size - 1] must be set to '\0' to end the string properly 
X * so my_wgetstr(errwin, str, 8) will get at most 7 characters.
X *
X * Returned value is the number of chars read. 
X */
X
Xmy_wgetstr(win, str, size, ret)
XWINDOW *win;
Xchar *str;
Xint size;
Xint ret;
X{
X#ifdef UNIX  
X	struct sgttyb ttyb;
X#endif 	
X	char erase_char, kill_char;
X	register int x_pos, y_pos, index, in;
X
X#ifdef UNIX	
X	if (ioctl(STD_INPUT, TIOCGETP, &ttyb) == -1)
X	{
X#endif	  
X		/*
X		 * failed to get terminal setting. Let's use the default
X		 * ERASE and KILL 
X		 */
X		erase_char = ERASE;
X		kill_char = KILL;
X#ifdef UNIX		
X	}
X	else
X	{
X		erase_char = ttyb.sg_erase;
X		kill_char = ttyb.sg_kill;
X	}
X#endif
X
X	/*
X	 * since we are going to set noecho() and crmode() let's be safe and
X	 * save the current tty 
X	 */
X	savetty();
X	noecho();
X	crmode();
X
X	/* get current position */
X	getyx(win, y_pos, x_pos);
X	/* intializing */
X	index = 0;
X	str[index] = '\0';
X
X	/* while input char is not NEWLINE */
X	while ((in = getch() & 0177) != NEWLINE)
X	{
X		/* if buffer is full (size -1) */
X		if (index >= size - 1)
X			if (ret)/* return flag set, return immediately */
X				break;
X			else	/* allows editing chars to pass through */
X			if ((in != erase_char) && (in != kill_char) && (in != WORD))
X			{
X				/* warns user that buffer is full */
X				bell();
X				continue;
X			}
X
X		if (in == erase_char)	/* ERASING */
X		{
X			if (index > 0)
X			{
X				mvwaddch(win, y_pos, --x_pos, SPACE);
X				str[--index] = SPACE;
X				wmove(win, y_pos, x_pos);
X			}
X			else
X				bell();
X		}
X		else
X		if (in == kill_char)	/* KILLING */
X		{
X			if (index > 0)
X				while (index > 0)
X				{
X					mvwaddch(win, y_pos, --x_pos, SPACE);
X					str[--index] = SPACE;
X					wmove(win, y_pos, x_pos);
X				}
X			else
X				bell();
X		}
X		else
X		if (in == WORD)	/* WORD DELETING */
X		{
X			if (index > 0)
X			{
X				/* throw away all spaces */
X				while ((index > 0) && (str[index - 1] == SPACE))
X				{
X					mvwaddch(win, y_pos, --x_pos, SPACE);
X					str[--index] = SPACE;
X					wmove(win, y_pos, x_pos);
X				}
X				/* move back until see another space */
X				while ((index > 0) && (str[index - 1] != SPACE))
X				{
X					mvwaddch(win, y_pos, --x_pos, SPACE);
X					str[--index] = SPACE;
X					wmove(win, y_pos, x_pos);
X				}
X			}
X			else
X				bell();
X		}
X		else
X		{
X			mvwaddch(win, y_pos, x_pos++, in);
X			str[index++] = in;
X		}
X		/* show result */
X		wrefresh(win);
X	}
X	/* ends the string properly */
X	str[index] = '\0';
X	/* restore the tty */
X	resetty();
X	/* returns number of chars read */
X	return (index);
X}
X
X/*
X *  Getint
X *
X *  Just a little function for Hotel that gets an integer
X *  using Le's wgetstr.
X *
X *
X */
X
X#include "my_wgets.h"
Xint getint()
X{
X  int x,y,num,ans;
X  char get[80];
X  
X  num = 0;
X  do {
X    my_getstr(get,80,0);
X    num = sscanf(get,"%d",&ans);
X  } while (num == 0);
X  return(ans);
X};
END_OF_FILE
if test 4382 -ne `wc -c <'my_wgets.c'`; then
    echo shar: \"'my_wgets.c'\" unpacked with wrong size!
fi
# end of 'my_wgets.c'
fi
if test -f 'my_wgets.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'my_wgets.h'\"
else
echo shar: Extracting \"'my_wgets.h'\" \(421 characters\)
sed "s/^X//" >'my_wgets.h' <<'END_OF_FILE'
X/*
X * A possible replacement for curses' wgetstr(). Allows
X * limited editing. Recognizes the erase and kill chars.
X *
X * By Hung Le (mott@ucscb.ucsc.edu  ...!ucbvax!ucscc!ucscb!mott)
X * History:
X *	05/18/89 - Initial version 
X *
X * Release to Public Domain 
X */
X
X/* following the curses's convention */
X#define my_getstr(str,size,ret) my_wgetstr(stdscr,str,size,ret)
X#define RET 1
X#define NO_RET 0
Xextern int getint();
X
END_OF_FILE
if test 421 -ne `wc -c <'my_wgets.h'`; then
    echo shar: \"'my_wgets.h'\" unpacked with wrong size!
fi
# end of 'my_wgets.h'
fi
if test -f 'pcdisp.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pcdisp.c'\"
else
echo shar: Extracting \"'pcdisp.c'\" \(6618 characters\)
sed "s/^X//" >'pcdisp.c' <<'END_OF_FILE'
X/*
X * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X * in both source code and executable form.  Permission is given to 
X * copy both the source code and the executable under the following
X * conditions:
X * 
X * COPYING POLICIES
X * 
X *   1. You may copy and distribute verbatim copies of Hotel code as you
X * receive it, in any medium, provided that you conspicuously and
X * appropriately publish on each file a valid copyright notice such as
X * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
X * and license notices on all files.  You may charge a distribution fee for the
X * physical act of transferring a copy, but that fee may not exceed
X * your actual costs in creating and delivering the copy.
X * 
X *   2. You may modify your copy or copies of Hotel or any portion of it,
X * and copy and distribute such modifications under the terms of
X * Paragraph 1 above, provided that you also do the following:
X * 
X *     a) cause the modified files to carry prominent notices stating
X *     who last changed such files and the date of any change; and
X * 
X *     b) cause the whole of any work that you distribute or publish,
X *     that in whole or in part contains or is a derivative of Hotel
X *     or any part thereof, to be licensed at no charge to all third
X *     parties on terms identical to those contained in this License
X *     Agreement (except that you may choose to grant more extensive
X *     warranty protection to third parties, at your option).
X *
X *   3. You may not copy, sublicense, distribute or transfer Hotel
X * except as expressly provided under this License Agreement.  Any attempt
X * otherwise to copy, sublicense, distribute or transfer Hotel is void and
X * your rights to use Hotel under this License agreement shall be
X * automatically terminated.  However, parties who have received computer
X * software programs from you with this License Agreement will not have
X * their licenses terminated so long as such parties remain in full compliance.
X * 
X *   4.  Under no circumstances may you charge for copies of Hotel, for copies
X * of any program containing code from Hotel in whole or in part, or for 
X * any software package or collection of programs or code that contains Hotel
X * in whole or part.
X *
X */ 
X/*
X *  Wed Nov  2 11:28:34 1988 -- Scott R. Turner
X *  display_utils.c  (PC Version)
X *
X *  This file contains utility functions for maintaining
X *  the screen display.  (Primarily print_board).
X *
X */
X
X#include "defs.h"
X#ifdef TURBO
X#define DULCORNER 201  
X#define DURCORNER 187
X#define DLRCORNER 188  
X#define DLLCORNER 200
X#define DLINE 205    
X#define DVERTICAL 186    
X#define BLOCK 254      
X#define POINT 250      
X#define LINE 196  
X#define LINETEE 194  
X#define VERTICAL 179    
X#define ULCORNER 218
X#define URCORNER 191
X#define LRCORNER 217
X#define LLCORNER 192
X#define TRIPLELINE 240
X#define LHORTEE 180
X#define RHORTEE 195
X#endif
X
X#ifdef UNIX
X#define DULCORNER '+' 
X#define DURCORNER '+'
X#define DLRCORNER '+'  
X#define DLLCORNER '+'
X#define DLINE '-'
X#define DVERTICAL '|'
X#define BLOCK '*'  
X#define POINT '.'      
X#define LINE '-' 
X#define LINETEE '+'
X#define VERTICAL '|'
X#define ULCORNER '+'
X#define URCORNER '+'
X#define LRCORNER '+'
X#define LLCORNER '+'
X#define TRIPLELINE '*'
X#define LHORTEE '|'
X#define RHORTEE '|'
X#endif
X
Xprint_board(p)
X     int p;
X{
X  int i,j,tile,x,y;
X
X  getyx(stdscr,y,x);
X  tile = 1;
X  move(2,3);
X  addch(DULCORNER);
X  for(i=1;i<=boardsize;i++) {
X    move(2,(i-1)*2+4);
X/*    addstr("MM"); */
X    addch(DLINE);
X    addch(DLINE);
X  }
X  move(2,boardsize*2+4);
X  addch(DLINE);
X  addch(DURCORNER);
X/*  addstr("M;"); */
X  for(i=1;i<=boardsize;i++) {
X    move(i+2,3);
X/*    addch(':'); */
X    addch(DVERTICAL);
X    for(j=1;j<=boardsize;j++) {
X      move(i+2,(2 * j)+3);
X      if (board[i][j] == UNUSED) {
X/*	addch('~'); */
X        addch(BLOCK);
X      } else if (board[i][j] == 0) {
X/*	addch('y');  */
X        addch(POINT);
X      } else if (board[i][j] == -p) {
X	standout();
X	addch('0' + tile++);
X	standend();
X      } else if (board[i][j] == UNPLAYABLE && debug) {
X        addch('*');
X      } else if (board[i][j] < 0) {
X/*	addch('y');  */
X        addch(POINT);
X      } else
X	addch(board[i][j] + 'A' - 1);
X    };
X    move(i+2,(boardsize*2+5));
X/*    addch(':');  */
X    addch(DVERTICAL);
X  };
X  move(boardsize+3,3);
X/*  addch('H'); */
X  addch(DLLCORNER);
X  for(i=1;i<=boardsize;i++) {
X    move(boardsize+3,(i-1)*2+4);
X/*    addstr("MM");  */
X    addch(DLINE);
X    addch(DLINE);
X  }
X  move(boardsize+3,boardsize*2+4);
X/*  addstr("M<"); */
X  addch(DLINE);
X  addch(DLRCORNER);
X
X  /*  Now do rhs info. */
X
X  move(2,(boardsize*2+8));
X  printw("Hotel    Cost    Yours   Available");
X  move(3,(boardsize*2+8));
X  for (i=1;i<=6;i++) addch(LINE);
X  addch(LINETEE);
X  for (i=1;i<=8;i++) addch(LINE);
X  addch(LINETEE);
X  for (i=1;i<=7;i++) addch(LINE);
X  addch(LINETEE);
X  for (i=1;i<=10;i++) addch(LINE);
X/*  printw("D D D D D D B D D D D D D D D B D D D D D D D B D D D D D D D D D D"); */
X  for(i=1;i<=numhotels;i++) {
X    move(i+3,(boardsize*2+10));
X    clrtoeol();
X    addch(i+'A'-1);
X    if(hotels[i].size > 0) {
X      move(i+3,(boardsize*2+17));
X      printw("$%d",share_cost(i));
X    } else {
X      move(i+3,(boardsize*2+16));
X      printw("($%d)",share_cost(i));
X    };
X    if (players[p].shares[i] > 0) {
X      move(i+3,(boardsize*2+27));
X      printw("%d",players[p].shares[i]);
X    };
X    move(i+3,(boardsize*2+36));
X    printw("%d",hotels[i].shares);
X    move(i+3,(boardsize*2+14));
X/*    addch('3'); */
X    addch(VERTICAL);
X    move(i+3,(boardsize*2+23));    
X/*    addch('3');  */
X    addch(VERTICAL);
X    move(i+3,(boardsize*2+31));
X/*    addch('3');  */
X    addch(VERTICAL);
X  };
X
X  move(numhotels+6,(boardsize*2+18));
X  clrtoeol();
X  printw("Cash = $%d",players[p].cash);
X  move(0,0);
X/*  printw("ZDDDDDDDDDDDDDDDDDDDDDDDDD 4 pHpOpTpEpLp C D D D D D D D D D D D D D D D D D D D D D D D D ?"); */
X  addch(ULCORNER);
X  for(i=1;i<=25;i++) addch(LINE);
X  addch(LHORTEE); addch(' ');
X  addch(TRIPLELINE); addch('H');
X  addch(TRIPLELINE); addch('O');
X  addch(TRIPLELINE); addch('T');
X  addch(TRIPLELINE); addch('E');
X  addch(TRIPLELINE); addch('L');
X  addch(' '); addch(RHORTEE);
X  for(i=1;i<=25;i++) addch(LINE);
X  addch(URCORNER);
X  for(i=1;i<=(boardsize+3);i++) {
X  	move(i,0);
X/*  	addch('3');  */
X        addch(VERTICAL);
X	move(i,65);
X/*  	addch('3');  */
X        addch(VERTICAL);
X  };
X  move((boardsize + 4),0);
X/*  printw("@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY"); */
X  addch(LLCORNER);
X  for(i=1;i<=64;i++) addch(LINE);
X  addch(LRCORNER);
X  move(y,x);
X  refresh();
X};
X
END_OF_FILE
if test 6618 -ne `wc -c <'pcdisp.c'`; then
    echo shar: \"'pcdisp.c'\" unpacked with wrong size!
fi
# end of 'pcdisp.c'
fi
if test -f 'utils.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'utils.c'\"
else
echo shar: Extracting \"'utils.c'\" \(6857 characters\)
sed "s/^X//" >'utils.c' <<'END_OF_FILE'
X/*
X * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
X * in both source code and executable form.  Permission is given to 
X * copy both the source code and the executable under the following
X * conditions:
X * 
X * COPYING POLICIES
X * 
X *   1. You may copy and distribute verbatim copies of Hotel code as you
X * receive it, in any medium, provided that you conspicuously and
X * appropriately publish on each file a valid copyright notice such as
X * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
X * and license notices on all files.  You may charge a distribution fee for the
X * physical act of transferring a copy, but that fee may not exceed
X * your actual costs in creating and delivering the copy.
X * 
X *   2. You may modify your copy or copies of Hotel or any portion of it,
X * and copy and distribute such modifications under the terms of
X * Paragraph 1 above, provided that you also do the following:
X * 
X *     a) cause the modified files to carry prominent notices stating
X *     who last changed such files and the date of any change; and
X * 
X *     b) cause the whole of any work that you distribute or publish,
X *     that in whole or in part contains or is a derivative of Hotel
X *     or any part thereof, to be licensed at no charge to all third
X *     parties on terms identical to those contained in this License
X *     Agreement (except that you may choose to grant more extensive
X *     warranty protection to third parties, at your option).
X *
X *   3. You may not copy, sublicense, distribute or transfer Hotel
X * except as expressly provided under this License Agreement.  Any attempt
X * otherwise to copy, sublicense, distribute or transfer Hotel is void and
X * your rights to use Hotel under this License agreement shall be
X * automatically terminated.  However, parties who have received computer
X * software programs from you with this License Agreement will not have
X * their licenses terminated so long as such parties remain in full compliance.
X * 
X *   4.  Under no circumstances may you charge for copies of Hotel, for copies
X * of any program containing code from Hotel in whole or in part, or for 
X * any software package or collection of programs or code that contains Hotel
X * in whole or part.
X *
X */ 
X/*
X *  utils.c
X *  Scott R. Turner
X *  9/7/88
X *
X *  Various utility functions.
X *
X */
X#include "defs.h"
X
Xextern int unplayable();
X#ifdef UNIX
Xextern long random();
X#endif UNIX
Xint tilecount = 0;
X
X/*
X *  randum is the standard 1-n random integer generator.
X *
X */
X
Xint randum(n)
X     int n;
X{
X  if (!n) return(0);
X#ifdef UNIX
X  return((random() % n) + 1);
X#endif
X#ifdef TURBO
X  return((rand() % n) + 1);
X#endif
X};
X
X/*
X *  newtile replaces a tile in a player's holding with a tile
X *  from the board.
X *
X */
X
Xnewtile(p)
X     int p;
X{
X  int x,y,available,choice;
X
X  available=0;
X  for(x=1;x<=boardsize;x++)
X    for(y=1;y<=boardsize;y++)
X      if (board[x][y] == 0 && !unplayable(x,y)) available++;
X
X  if (debug) {
X  	printw("Available tiles = %d.\n",available);
X	refresh();
X  };
X  if (available == 0) return(0);
X  
X  choice = randum(available);
X
X  for(x=1;x<=boardsize;x++)
X    for(y=1;y<=boardsize;y++) {
X      if (board[x][y] == 0) {
X	choice--;
X	if (choice == 0) {
X	  board[x][y] = -p;
X	  return(1);
X	};
X      };
X    };
X      
X  return(0);
X
X};
X
X/*
X *  new_hotel returns true if the placement creates a new hotel
X *  and there is a new hotel to create.
X *
X */
X
Xnew_hotel(x,y)
X     int x,y;
X{
X  int i,j,new;
X
X  /* Is the new tile adjacent to an existing hotel? */
X
X  new = 1;
X  for(i= -1;i<2;i++)
X    for(j= -1;j<2;j++)
X      if ( i*j == 0 && (i != 0 || j != 0) &&
X	  ((x+i) > 0) && ((y+j) > 0) &&
X	  ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
X	  (board[x+i][y+j] > 0) && (board[x+i][y+j] < UNUSED)) {
X	new = 0;
X	break;
X      };
X
X  if (new == 0) return(new);
X              
X  /* Is there an UNUSED adjacent? */
X
X  new = 0;
X  for(i= -1;i<2;i++)
X    for(j= -1;j<2;j++)
X      if ( i*j == 0 && (i != 0 || j != 0) &&
X	  ((x+i) > 0) && ((y+j) > 0) &&
X	  ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
X	  (board[x+i][y+j] == UNUSED)) {
X	new = 1;
X	break;
X      };
X
X  if (new == 0) return(new);
X  
X/* Is there an available hotel? */
X
X  new = 0;
X  for(i=1;i<=numhotels;i++)
X    if(hotels[i].size == 0) {
X      new = 1;
X      break;
X    };
X
X  return(new);
X
X};
X
Xint maj_bonus(p,i)
X  int p,i;
X{
X  int j,k,max1,num1,max2,num2,first,second;
X  
X  max1 = 0;
X  num1 = 0;
X  max2 = 0;
X  num2 = 0;
X
X  for(j=1;j<=numplayers;j++) {
X    if (players[j].shares[i] > max1) {
X      max2 = max1;
X      num2 = num1;
X      max1 = players[j].shares[i];
X      num1 = 1;
X    } else if (players[j].shares[i] == max1) {
X      num1++;
X    } else if (players[j].shares[i] > max2) {
X      max2 = players[j].shares[i];
X      num2 = 1;
X    } else if (players[j].shares[i] == max2) {
X      num2++;
X    };
X  };
X
X  majority_bonus(i,&first,&second);
X
X  if (max2 == 0 || num1 > 1) {
X
X    /*
X     *  The top dogs split both.
X     *
X     */
X
X    for(k=1;k<=numplayers;k++)
X      if (players[k].shares[i] == max1 && k == p) {
X	return(round((first + second) / num1));
X      };
X  } else
X    for (k=1;k<=numplayers;k++)
X      if (players[k].shares[i] == max1 && k == p) {
X	return(round(first));
X      } else if (players[k].shares[i] == max2 && k == p) {
X	return(round(second/num2));
X      };
X
X  return(0);
X  
X};
X
X/*
X *  merge returns true if this play will merge 2 or more hotels.
X *  It returns the list of hotels that will/can be merge in
X *  possibles.
X *
X */
X
Xint mergecheck(x,y,possibles)
X     int x,y,*possibles;
X{
X  int i,j,k,lsize,count,seen[MAXHOTELS];
X
X  if (unplayable(x,y)) return(0);
X  for (i=1;i<=numhotels;i++) seen[i] = 0;
X  lsize = 9999;
X  count = 0;
X  for(i= -1;i<2;i++)
X    for(j= -1;j<2;j++)
X      if ( i*j == 0 && (i != 0 || j != 0) &&
X	  ((x+i) > 0) && ((y+j) > 0) &&
X	  ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
X	  (board[x+i][y+j] != UNUSED) &&
X	  (board[x+i][y+j] > 0)){
X	if (!seen[board[x+i][y+j]]) {
X	  count++;
X	  seen[board[x+i][y+j]] = 1;
X	  if (hotels[board[x+i][y+j]].size < lsize) {
X	    for (k=1;k<=numhotels;k++) possibles[k] = 0;
X	    lsize = hotels[board[x+i][y+j]].size;
X	    possibles[board[x+i][y+j]] = 1;
X	  } else if (hotels[board[x+i][y+j]].size == lsize) {
X	    possibles[board[x+i][y+j]] = 1;
X	  };
X	};
X      };
X
X  if (count < 2) return(0);
X  else return(1);
X  
X};
X	    
X/*
X *  adjacent returns the number of an adjacent hotel if there
X *  is one.  adjacent assumes that there is at most one adjacent
X *  hotel.
X *
X */
X
Xint adjacent(x,y,h)
X     int x,y,*h;
X{
X  int i,j;
X
X  for(i= -1;i<2;i++)
X    for(j= -1;j<2;j++)
X      if ( i*j == 0 && (i != 0 || j != 0) &&
X	  ((x+i) > 0) && ((y+j) > 0) &&
X	  ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
X	  (board[x+i][y+j] != UNUSED) &&
X	  (board[x+i][y+j] > 0)){
X	*h = board[x+i][y+j];
X	return(*h);
X      };
X  *h = 0;
X  return(0);
X};
X	
END_OF_FILE
if test 6857 -ne `wc -c <'utils.c'`; then
    echo shar: \"'utils.c'\" unpacked with wrong size!
fi
# end of 'utils.c'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0