home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume7 / hotel / part01 / hotel.c < prev    next >
C/C++ Source or Header  |  1989-07-13  |  18KB  |  814 lines

  1. /*
  2.  * This program (called "Hotel") is copyright 1989 to Scott R. Turner,
  3.  * in both source code and executable form.  Permission is given to 
  4.  * copy both the source code and the executable under the following
  5.  * conditions:
  6.  * 
  7.  * COPYING POLICIES
  8.  * 
  9.  *   1. You may copy and distribute verbatim copies of Hotel code as you
  10.  * receive it, in any medium, provided that you conspicuously and
  11.  * appropriately publish on each file a valid copyright notice such as
  12.  * "Copyright (C) 1989 Scott R. Turner", and keep intact the copyright
  13.  * and license notices on all files.  You may charge a distribution fee for the
  14.  * physical act of transferring a copy, but that fee may not exceed
  15.  * your actual costs in creating and delivering the copy.
  16.  * 
  17.  *   2. You may modify your copy or copies of Hotel or any portion of it,
  18.  * and copy and distribute such modifications under the terms of
  19.  * Paragraph 1 above, provided that you also do the following:
  20.  * 
  21.  *     a) cause the modified files to carry prominent notices stating
  22.  *     who last changed such files and the date of any change; and
  23.  * 
  24.  *     b) cause the whole of any work that you distribute or publish,
  25.  *     that in whole or in part contains or is a derivative of Hotel
  26.  *     or any part thereof, to be licensed at no charge to all third
  27.  *     parties on terms identical to those contained in this License
  28.  *     Agreement (except that you may choose to grant more extensive
  29.  *     warranty protection to third parties, at your option).
  30.  *
  31.  *   3. You may not copy, sublicense, distribute or transfer Hotel
  32.  * except as expressly provided under this License Agreement.  Any attempt
  33.  * otherwise to copy, sublicense, distribute or transfer Hotel is void and
  34.  * your rights to use Hotel under this License agreement shall be
  35.  * automatically terminated.  However, parties who have received computer
  36.  * software programs from you with this License Agreement will not have
  37.  * their licenses terminated so long as such parties remain in full compliance.
  38.  * 
  39.  *   4.  Under no circumstances may you charge for copies of Hotel, for copies
  40.  * of any program containing code from Hotel in whole or in part, or for 
  41.  * any software package or collection of programs or code that contains Hotel
  42.  * in whole or part.
  43.  *
  44.  */ 
  45. /*
  46.  *  hotel.c
  47.  *  Scott R. Turner
  48.  *  9/7/88
  49.  *
  50.  *  The main program and declarations for Hotel.
  51.  *
  52.  */
  53.  
  54. #include "defs.h"
  55. #include <signal.h>
  56.  
  57. #ifdef TURBO
  58. #include <stdlib.h>
  59. #include <time.h>
  60. #endif
  61.  
  62. /* Hotels Array */
  63.  
  64. hotel hotels[MAXHOTELS+1];
  65.  
  66. /* Players Array */
  67.  
  68. player players[MAXPLAYERS+1];
  69.  
  70. /* Board */
  71.  
  72. int board[MAXBOARD+1][MAXBOARD+1];
  73.  
  74. /* Run-time variables */
  75.  
  76. int numplayers, numhotels, boardsize, numshares, numtiles, startcash;
  77. int turn, maxbuy, debug, pnum;
  78.  
  79. /* Externals */
  80.  
  81. extern int share_cost();
  82. extern void majority_bonus();
  83. extern void print_board();
  84. extern int new_hotel();
  85. extern void anykey_help();
  86.  
  87. void endgame()
  88. {
  89.   nocrmode();
  90.   echo();
  91.   endwin();
  92.   printf("\n");
  93.   exit(1);
  94. };
  95.  
  96. /*
  97.  *  Quit - a little subroutine to handle the quit key.
  98.  *
  99.  */
  100.  
  101. void quit()
  102. {
  103.   char ans;
  104.   
  105.   printw("\nAre you sure you want to quit? (Y/N) ");
  106.   refresh();
  107.   ans = getch();
  108.   if (ans == 'Y' || ans == 'y') {
  109.     echo();
  110.     nocrmode();
  111.     endwin();
  112.     exit(1);
  113.   };
  114. };
  115.  
  116. main ()
  117. {
  118.   int i,j,k,x,y,hotelchoice,played;
  119.   int purchases[MAXHOTELS];
  120.   extern long time();
  121. #ifdef UNIX
  122.   extern void srandom();
  123. #endif
  124.   extern void  human_play();
  125.   extern int  human_new();
  126.   extern int  human_save();
  127.   extern void  human_buy();
  128.   extern void  human_liquidate();
  129.   extern void  comp_play();
  130.   extern int  comp_new();
  131.   extern int  comp_save();
  132.   extern void  get_maj_strategy();
  133.   extern void  comp_liquidate();
  134.  
  135.   /* Debug flag. */
  136.   
  137.   debug = 0;
  138.   
  139.   /* Initialize random number generator. */
  140.  
  141. #ifdef UNIX
  142.   srandom((int) time(0));
  143. #else
  144.   randomize();
  145. #endif
  146.  
  147.   /*
  148.      Curses Initialization.
  149.    */
  150.    
  151.   initscr();
  152. #ifdef UNIX
  153.   nonl();
  154. #endif UNIX
  155.   crmode();
  156.  
  157.   /* Initialize game. */
  158.  
  159.   init();
  160.   noecho();
  161.  
  162.   signal(SIGINT,endgame);
  163. #ifdef UNIX
  164.   signal(SIGQUIT,endgame);
  165. #endif
  166.  
  167.   /* Game Cycle:
  168.  
  169.         For each player in the game, execute their "play" and "buy"
  170.     behaviors.
  171.   */
  172.   
  173.   turn = 1;
  174.  
  175.   while(!game_over()) {
  176.  
  177.     for (i=1;i<=numplayers;i++) {
  178.     
  179.        /*
  180.         *  If a player has a tile that is permanently unplayable because
  181.         *  it would cause the merger of two safe hotel chains, then he
  182.         *  is allowed to discard that tile and draw a new one.  We do this
  183.         *  automatically for each player at the beginning of each round.
  184.         *
  185.         */
  186.  
  187.       for(k=1;k<=boardsize;k++)
  188.         for(j=1;j<=boardsize;j++)
  189.       if (unplayable(k,j)) {
  190.         if (board[k][j] < 0 && board[k][j] != UNPLAYABLE) 
  191.             newtile(-board[k][j]);
  192.         board[k][j] = UNPLAYABLE;
  193.       };
  194.       
  195.       pnum = i;
  196.       move((boardsize+5),0);
  197.       clrtobot();
  198.       played = 0;
  199.  
  200.       /*
  201.        *  The "play" behavior returns (in &x and &y) the location of
  202.        *  the tile the player would like to play this round.
  203.        *
  204.        */
  205.  
  206.       if (players[i].strategy) {
  207.      /*  A computer player. */
  208.     comp_play(i,&x,&y);
  209.     printw("%s played (%d,%d).\n",players[i].name,x,y);
  210.       } else {
  211.           /*  Human player. */
  212.           human_play(i,&x,&y);
  213.       };
  214.  
  215.       /*
  216.        *  If the move is legal and on the board and owned by the player,
  217.        *  then make the move.
  218.        *
  219.        */
  220.       
  221.       if (x > 0 && y > 0 && x <= boardsize && y <= boardsize && legal_play(x,y) &&
  222.       board[x][y] == -i) {
  223.     
  224.     /*  Place the tile on the board. */
  225.     
  226.     board[x][y] = UNUSED;
  227.     
  228.     /* Check to see if the play merged two hotel chains, or added to a hotel. */
  229.  
  230.     hotel_merge(x,y,i);
  231.  
  232.     /* Check to see if the play created a new hotel chain. */
  233.  
  234.     if (new_hotel(x,y)) {
  235.  
  236.       /* It did, so let him choose the hotel chain. */
  237.       
  238.       if (players[i].strategy) {
  239.         hotelchoice = comp_new(i,x,y);
  240.       } else {
  241.         hotelchoice = human_new(i,x,y);
  242.           };
  243.       make_new_hotel(hotelchoice,x,y,i);
  244.     };
  245.     played = 1;
  246.     
  247.       };
  248.  
  249.       /*
  250.        *  The player is done placing his tile.  Now execute his buy
  251.        *  behavior, which returns (in purchases) the stocks he chooses
  252.        *  to buy.
  253.        *
  254.        */
  255.     
  256.       if (players[i].strategy) {
  257.         get_maj_strategy(i,purchases);
  258.     print_board(human_player);
  259.     refresh();
  260.     any_key();
  261.       } else {
  262.         human_buy(i,purchases);
  263.       };
  264.       /*
  265.        *  Actually make the purchases, checking to see that the
  266.        *  the shares are available, the hotel exists, and he has the money.
  267.        *
  268.        */
  269.  
  270.       for (j=1;j<=numhotels;j++)
  271.     if (purchases[j] != 0 && hotels[j].size > 0 &&
  272.         purchases[j] <= hotels[j].shares &&
  273.         purchases[j]*share_cost(j) <= players[i].cash) {
  274.  
  275.       hotels[j].shares -= purchases[j];
  276.       players[i].shares[j] += purchases[j];
  277.       players[i].cash -= purchases[j]*share_cost(j);
  278.     };
  279.  
  280.       /*  Give the player a new tile to replace the one just played. */
  281.  
  282.       if (played==1) newtile(i);
  283.       
  284.     };
  285.     turn++;
  286.   };
  287.   standings();
  288.   endwin();
  289.   exit(1);
  290. };
  291.  
  292. /*
  293.  *  game_over checks to see whether or not the end conditions
  294.  *  have become satisfied.
  295.  *
  296.  */
  297.  
  298. game_over()
  299. {
  300.   int i,x,y;
  301.   int done = 1, any = 0, available = 0;
  302.   
  303.   /* Game is over if all the hotels on the board are safe,
  304.    * or any chain is >  42% of the board, or if no one has
  305.    * a legal play.
  306.    */
  307.   
  308.   /*
  309.    *  No legal plays...?
  310.    *
  311.    */
  312.  
  313.   for(x=1;x<=boardsize;x++)
  314.     for(y=1;y<=boardsize;y++)
  315.       if (board[x][y] <= 0 && board[x][y] != UNPLAYABLE &&
  316.           !unplayable(x,y)) available++;
  317.       
  318.   if (!available) return(1);
  319.  
  320.   /*
  321.    *  Big hotel?
  322.    *
  323.    */
  324.   for(i=1;i<=numhotels;i++)
  325.     if(hotels[i].size > (.42 * boardsize * boardsize)) return(1);
  326.   /*
  327.    *  Just started?
  328.    *
  329.    */
  330.   for(i=1;i<=numhotels;i++)
  331.     if(hotels[i].size > 0) {
  332.         any = 1;
  333.     break;
  334.     };
  335.   if (!any) return(0);
  336.   for(i=1;i<=numhotels;i++)
  337.     if(hotels[i].size > 0 && !safe(i)) {
  338.       done = 0;
  339.       break;
  340.     };
  341.   return(done);
  342.   
  343. };
  344.  
  345. /*
  346.  *  make_new_hotel makes a new hotel (hotel #n) around x,y.
  347.  *
  348.  */
  349.   
  350. make_new_hotel(n,x,y,pl)
  351.      int n,x,y,pl;
  352. {
  353.   int change,i,j;
  354.   
  355.   board[x][y] = n;
  356.   hotels[n].size++;
  357.   spread_hotel(n,x,y);
  358.  
  359.   /*  Give the player one free share, if available. */
  360.  
  361.   if (hotels[n].shares > 0) {
  362.     hotels[n].shares -= 1;
  363.     players[pl].shares[n] += 1;
  364.   };
  365.  
  366. };
  367.         
  368. /*
  369.  *  hotel_merge checks to see if the newly placed tile at (x,y) merges two 
  370.  *  hotel chains.
  371.  * 
  372.  */  
  373.        
  374. hotel_merge(x,y,p)
  375.   int x,y,p;
  376. {
  377.   int adj[MAXHOTELS+1],shares[MAXHOTELS+1];
  378.   int i, j, k, count, max, dup, winner, hot, maxhot;
  379.   int hold, sell, trade, numtraded, cp;
  380.   int max1, max2, num1, num2, first, second;
  381.  
  382.   /*
  383.    *  Start by making a list of all the hotels that this 
  384.    *  new play is adjacent to.
  385.    * 
  386.    */
  387.  
  388.   for(i=1;i<=numhotels;i++) {
  389.     adj[i] = 0;
  390.     shares[i] = 0;
  391.   };
  392.   count = 0;
  393.   max =  0;
  394.   dup = 0;
  395.  
  396.   for(i= -1;i<2;i++)
  397.     for(j= -1;j<2;j++) {
  398.     hot = board[x+i][y+j];
  399.     if ((i*j == 0) && (i != 0 || j != 0) &&
  400.         ((x+i) > 0) && ((y+j) > 0) &&
  401.         ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
  402.         (hot > 0) && (hot != UNUSED)) {
  403.       if (!adj[hot]) count++;
  404.       adj[hot] = hotels[hot].size;
  405.       shares[hot] = share_cost(hot);
  406.     };
  407.       };
  408.  
  409.   for(i=1;i<=numhotels;i++) 
  410.     if (adj[i] == max) {
  411.       dup++;
  412.     } else if (adj[i] > max) {
  413.       dup = 0;
  414.       max = adj[i];
  415.       maxhot = i;
  416.     };
  417.       
  418.   /*  If count = 0, we weren't adjacent to anything.  */
  419.  
  420.   if (count == 0) return(0);
  421.                                                                                                  
  422.   /*  If count = 1, we were adjacent to a single hotel, so spread that hotel. */
  423.  
  424.   if (count == 1) {
  425.      spread_hotel(maxhot,x,y);
  426.      return(1);
  427.        };
  428.   
  429.   /* If count > 1, then we are merging two or more chains. */      
  430.  
  431.   /* If dup > 0, then we have two chains of the same size,
  432.    * so the player gets to choose which to dump.  If dup = 0,
  433.    * then there is a clear winner, and we find it.
  434.    */
  435.  
  436.   if (dup > 0) 
  437.     if (players[p].strategy) {
  438.         maxhot = comp_save(p,max,adj);
  439.     } else {
  440.         maxhot = human_save(p,max,adj);
  441.     };
  442.  
  443.   /*
  444.    *  Hand out the majority bonuses for all the sunken hotels.
  445.    *
  446.    */
  447.  
  448.   for(i=1;i<=numhotels;i++)
  449.     if(i != maxhot && adj[i] != 0) do_maj_bonuses(i);
  450.  
  451.   /*
  452.    *  After the other chains have been sunk, we need to give people
  453.    *  a chance to liquidate, starting with the current player and 
  454.    *  continuing in play order.
  455.    *
  456.    */
  457.  
  458.   for(j=1;j<=numhotels;j++)
  459.     if(adj[j] && j != maxhot)
  460.       for(i=0;i<numplayers;i++){
  461.     cp = ((p+i)%numplayers) + 1;
  462.     if (players[cp].shares[j] > 0) {
  463.  
  464.           if (players[cp].strategy) {
  465.             comp_liquidate(cp,maxhot,j,&sell,&trade);
  466.       } else {
  467.             human_liquidate(cp,maxhot,j,&sell,&trade);
  468.       };
  469.  
  470.       /* Sell as many as he asked. */
  471.  
  472.       if (sell <= players[cp].shares[j] && sell > 0) {
  473.         players[cp].cash += sell*share_cost(j);
  474.         players[cp].shares[j] -= sell;
  475.         hotels[j].shares += sell;
  476.       };
  477.       
  478.       /* Trade as many as possible. */
  479.  
  480.       if (trade <= players[cp].shares[j] && trade > 0) {
  481.         numtraded = (hotels[maxhot].shares <= (int) (trade / 2)) ? (hotels[maxhot].shares * 2) :
  482.           trade;
  483.         players[cp].shares[j] -= numtraded;
  484.         hotels[j].shares += numtraded;
  485.         players[cp].shares[maxhot] += round(numtraded / 2);
  486.         hotels[maxhot].shares -= round(numtraded / 2);
  487.       };
  488.  
  489.       /* Everything left gets held. */
  490.     };
  491.     
  492.       };
  493.  
  494.   /*
  495.    *  Merge all the chains other than the winner into the winner.
  496.    *
  497.    */
  498.  
  499.   for(i=1;i<=numhotels;i++)
  500.    if(i != maxhot && adj[i] != 0)
  501.      for(x=1;x<=boardsize;x++)   
  502.         for(y=1;y<=boardsize;y++)
  503.           if (board[x][y] == i) {
  504.              board[x][y] = maxhot;
  505.              hotels[i].size--;
  506.              hotels[maxhot].size++;
  507.           };
  508.  
  509.   /*
  510.    *  Finally, spread the winning hotel, in case the new tile also
  511.    *  touched some unused tiles.
  512.    *
  513.    */
  514.   
  515.   spread_hotel(maxhot,x,y);
  516.   
  517. };
  518.  
  519. /*
  520.  *  Spread_hotel iteratively changes unused tiles into the hotel
  521.  *  they are next to. 
  522.  *
  523.  */
  524.  
  525. spread_hotel(n,x,y)
  526.   int n,x,y;
  527. {
  528.   int i,j,change;
  529.   
  530.   change = 1;
  531.  
  532.   while(change){
  533.     change = 0;
  534.     for(x=1;x<=boardsize;x++)
  535.       for(y=1;y<=boardsize;y++)
  536.     if(board[x][y] == n)
  537.       for(i= -1;i<2;i++)
  538.         for(j= -1;j<2;j++)
  539.           if((i*j == 0) && (i != 0 || j != 0) && (x+i) > 0 && (x+i) <= boardsize &&
  540.          (y+j) > 0 && (y+j) <= boardsize &&
  541.          board[x+i][y+j] == UNUSED) {
  542.         board[x+i][y+j] = n;
  543.         hotels[n].size++;
  544.         change = 1;
  545.           };
  546.   };
  547.  
  548. };
  549.  
  550. /*
  551.  *  safe returns true if a hotel is safe, i.e., > 10
  552.  *
  553.  */
  554.  
  555. safe(hot)
  556.      int hot;
  557. {
  558.   if (hotels[hot].size > 10) return(1);
  559.   else return(0);
  560. };
  561.  
  562. /*
  563.  *  legal_play returns false if the play would create a (numhotels + 1) hotel
  564.  *
  565.  */
  566.  
  567. legal_play(x,y)
  568.      int x,y;
  569. {
  570.   int i,j,new;
  571.  
  572.   /* Is the new tile adjacent to an existing hotel? */
  573.  
  574.   new = 1;
  575.   for(i= -1;i<2;i++)
  576.     for(j= -1;j<2;j++)
  577.       if ( i*j == 0 && (i != 0 || j != 0) &&
  578.       ((x+i) > 0) && ((y+j) > 0) &&
  579.       ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
  580.       (board[x+i][y+j] > 0) && (board[x+i][y+j] < UNUSED)) {
  581.         new = 0;
  582.     break;
  583.       };
  584.  
  585.   if (new == 0) return(1);
  586.  
  587.   /* Is there an UNUSED adjacent? */
  588.  
  589.   new = 0;
  590.   for(i= -1;i<2;i++)
  591.     for(j= -1;j<2;j++)
  592.       if ( i*j == 0 && (i != 0 || j != 0) &&
  593.       ((x+i) > 0) && ((y+j) > 0) &&
  594.       ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
  595.       (board[x+i][y+j] == UNUSED)) {
  596.     new = 1;
  597.     goto done;
  598.       };
  599.   
  600.  done:
  601.  
  602.   if (new == 0) return(1);
  603.   
  604.   /* Is there an available hotel? */
  605.  
  606.   new = 0;
  607.   for(i=1;i<=numhotels;i++)
  608.     if(hotels[i].size == 0) {
  609.      new = 1;
  610.      break;
  611.    };
  612.  
  613.   return(new);
  614.  
  615. };
  616.  
  617. /*
  618.  *  unplayable returns true if the play would merge two "safe" hotels.
  619.  *
  620.  */
  621.  
  622. unplayable(x,y)
  623.      int x,y;
  624. {
  625.   
  626.   int i,j,count,adj[MAXHOTELS+1];
  627.  
  628.   for(i=1;i<=numhotels;i++)
  629.     adj[i] = 0;
  630.  
  631.   for(i= -1;i<2;i++)
  632.     for(j= -1;j<2;j++)
  633.       if (i*j == 0 && (i != 0 || j != 0) &&
  634.       ((x+i) > 0) && ((y+j) > 0) &&
  635.       ((x+i) <= boardsize) && ((y+j) <= boardsize) &&
  636.       (board[x+i][y+j] != UNUSED) &&
  637.       (board[x+i][y+j] > 0) &&
  638.       safe(board[x+i][y+j]))
  639.     adj[board[x+i][y+j]] = 1;
  640.  
  641.   count = 0;
  642.   for(i=1;i<=numhotels;i++)
  643.     if(adj[i]) count++;
  644.     
  645.   if (count > 1 && debug) {
  646.       printw("(%d, %d): ",x,y);
  647.       for(i=1;i<=numhotels;i++)
  648.           if(adj[i]) printw("%c ",'A'+i-1);
  649.       printw("%d\n",count);
  650.     refresh();
  651.     any_key();
  652.   };
  653.  
  654.   if (count > 1) return(1);
  655.   else return(0);
  656.  
  657. };
  658.  
  659. /*
  660.  *  standings calculates and  prints the value of everyone at the endgame.
  661.  *
  662.  */
  663.  
  664. standings()
  665. {
  666.   int i,j,order[MAXPLAYERS+1],tmp;
  667.  
  668.   clear();
  669.   printw("The game is over!.\n\n");
  670.   for(i=1;i<=numhotels;i++)
  671.     if(hotels[i].size > 0) do_maj_bonuses(i);
  672.  
  673.   for(i=1;i<=numplayers;i++)
  674.     for(j=1;j<=numhotels;j++)
  675.       if (hotels[j].size > 0) players[i].cash += players[i].shares[j] * share_cost(j);
  676.  
  677.   /*  Sort  */
  678.   
  679.   for(i=1;i<=numplayers;i++) order[i] = i;
  680.  
  681.   for(j=1;j<=numplayers;j++)
  682.     for(i=1;i<=(numplayers-1);i++)
  683.       if (players[order[i]].cash < players[order[i+1]].cash) {
  684.     tmp = order[i];
  685.     order[i] = order[i+1];
  686.     order[i+1] = tmp;
  687.       };
  688.  
  689.   clear();
  690.   printw("Here are the final standings:\n");
  691.   for(i=1;i<=numplayers;i++)
  692.     printw("  (%d) %s:  $%ld\n",i,players[order[i]].name,
  693.                       players[order[i]].cash);
  694.   refresh();
  695.   any_key();
  696.   
  697. };
  698.  
  699. any_key()
  700.  
  701. {
  702.   char ans;
  703.   int y,x;
  704.  
  705.   clrtoeol();
  706.   printw("--- Hit any Key to Continue ---");
  707.   getyx(stdscr,y,x);
  708.   refresh();
  709. topofanykey:
  710.   ans = getch();
  711.   if (islower(ans)) ans = toupper(ans);
  712. /*
  713.  *  Removed in production version...
  714.  *
  715.  
  716.   if (ans == 'D') {
  717.       if (!debug) debug = 1;
  718.     else debug = 0;
  719.     goto topofanykey;
  720.   };
  721.  
  722.  *
  723.  */
  724.  
  725.   if (ans == REFRESHKEY) {
  726.     wrefresh(curscr);
  727.     goto topofanykey;
  728.   };
  729.   if (ans == HELPKEY) {
  730.     anykey_help();
  731.     goto topofanykey;
  732.   };
  733.   if (ans == QUITKEY) {
  734.     quit();
  735.   };
  736.   move(y,0);
  737.   clrtoeol();
  738. };
  739.  
  740.  
  741.  
  742. do_maj_bonuses(i)
  743.   int i;
  744. {
  745.   int j,k,max1,num1,max2,num2,first,second;
  746.  
  747.   max1 = 0;
  748.   num1 = 0;
  749.   max2 = 0;
  750.   num2 = 0;
  751.  
  752.   for(j=1;j<=numplayers;j++) {
  753.     if (players[j].shares[i] > max1) {
  754.       max2 = max1;
  755.       num2 = num1;
  756.       max1 = players[j].shares[i];
  757.       num1 = 1;
  758.     } else if (players[j].shares[i] == max1) {
  759.       num1++;
  760.     } else if (players[j].shares[i] > max2) {
  761.       max2 = players[j].shares[i];
  762.       num2 = 1;
  763.     } else if (players[j].shares[i] == max2) {
  764.       num2++;
  765.     };
  766.   };
  767.  
  768.   majority_bonus(i,&first,&second);
  769.  
  770.   if (max2 == 0 || num1 > 1) {
  771.  
  772.     /*
  773.      *  The top dogs split both.
  774.      *
  775.      */
  776.      
  777.     for(k=1;k<=numplayers;k++)
  778.       if (players[k].shares[i] == max1) {
  779.         if (players[k].strategy == 0) {
  780.         printw("%s get $%d Majority Bonus for %s\n",
  781.            players[k].name, round((first + second) / num1), hotels[i].name);
  782.     } else {
  783.         printw("%s gets $%d Majority Bonus for %s\n",
  784.            players[k].name, round((first + second) / num1), hotels[i].name);
  785.     };
  786.     players[k].cash += round((first + second) / num1);
  787.       };
  788.   } else
  789.     for (k=1;k<=numplayers;k++)
  790.       if (players[k].shares[i] == max1) {
  791.         if (players[k].strategy == 0) {
  792.         printw("%s get %d Majority Bonus (First) for %s\n",
  793.            players[k].name, first, hotels[i].name);
  794.     } else {
  795.         printw("%s gets %d Majority Bonus (First) for %s\n",
  796.            players[k].name, first, hotels[i].name);
  797.     };
  798.     players[k].cash += round(first);
  799.       } else if (players[k].shares[i] == max2) {
  800.         if (players[k].strategy == 0) {
  801.     printw("%s get %d Majority Bonus (Second) for %s\n",
  802.            players[k].name, round(second/num2), hotels[i].name);
  803.     } else {
  804.         printw("%s gets %d Majority Bonus (Second) for %s\n",
  805.            players[k].name, round(second/num2), hotels[i].name);
  806.     };
  807.     players[k].cash += round(second/num2);
  808.       };
  809.   refresh();
  810.   any_key();
  811.  
  812. };
  813.  
  814.