[comp.sources.games] v06i025: bandit - slot machine

games@tekred.CNA.TEK.COM (03/16/89)

Submitted-by: Pete Granger <ulowell!cg-atla!granger>
Posting-number: Volume 6, Issue 25
Archive-name: bandit

	[This could be addicting, if you're not careful.... -br]

#! /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 shell archive."
# Contents:  Makefile README bandit.c
# Wrapped by billr@saab on Wed Mar 15 14:18:34 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(127 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# simple makefile for bandit
X
XCFLAGS = -O
XLIBS = -lcurses -ltermcap
X
Xbandit:	bandit.c
X	cc -o bandit $(CFLAGS) bandit.c $(LIBS)
END_OF_FILE
if test 127 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1942 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X     One-Armed Bandit, v 1.01, by Pete Granger   (December 13, 1988)
X  
X   Abstract:
X  
X     This is a slot machine simulation which uses curses routines. The
X    setup and payoffs are described in comments below, and the means of
X    play can be read in the print_instructions() routine.
X  
X   Notes:
X  
X    This program has been compiled and run on a VAX running Ultrix 3.0,
X    and on a Sun-3, Sun-4, and Sun-386i. It will compile on an IBM
X    AT-compatible, but there are problems with the stty and curses
X    commands. Fixes for the AT are forthcoming at an undetermined date.
X  
X    If your machine does not have the random() and srandom() functions,
X    then set the value of RANDOM to 0, prior to compiling, and rand() and
X    srand() will be used instead.
X  
X   This is the configuration and payoff chart for a fair but profitable
X   slot machine. It has a 9.54% chance of paying off on each play, and
X   (on one-dollar bets) will pay back an average of 91.47% of all bets.
X
X         Wheel 1     Wheel 2     Wheel 3
X          -----       -----       -----
X    Bars    1           1           1
X   Bells    2           1           1
X Oranges    1           5           1
X  Lemons    3           1           4
X   Plums    3           2           3
XCherries    4           4           4
X
X
X   Combination     Pays   Frequency   Total Payoff
X      -----        ----     -----         -----
X      Bar * 3      1000        1          1000
X     Bell * 3       100        2           200
X   Orange * 3        50        5           250
X    Lemon * 3        20       12           240
X     Plum * 3        10       18           180
X   Cherry * 3         5       64           320
XCherry * 2 + Any      2      160           320
X                            _____         _____
X                              262         2510
X                                          (234 profit)
X
X   Pete Granger   ...!{ulowell,decvax,ima,ism780c}!cg-atla!granger
END_OF_FILE
if test 1942 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'bandit.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bandit.c'\"
else
echo shar: Extracting \"'bandit.c'\" \(18965 characters\)
sed "s/^X//" >'bandit.c' <<'END_OF_FILE'
X/*
X *   One-Armed Bandit, v 1.01, by Pete Granger   (December 13, 1988)
X *
X * Abstract:
X *
X *   This is a slot machine simulation which uses curses routines. The
X *  setup and payoffs are described in comments below, and the means of
X *  play can be read in the print_instructions() routine.
X *
X * Notes:
X *
X *  This program has been compiled and run on a VAX running Ultrix 3.0,
X *  and on a Sun-3, Sun-4, and Sun-386i. It will compile on an IBM
X *  AT-compatible, but there are problems with the stty and curses
X *  commands. Fixes for the AT are forthcoming at an undetermined date.
X *
X *  If your machine does not have the random() and srandom() functions,
X *  then set the value of RANDOM to 0, prior to compiling, and rand() and
X *  srand() will be used instead.
X *
X *  In order to compile, the -lcurses and -ltermcap options must be
X *  used.
X *
X * Release:
X *
X *  This program is released to the public domain via usenet on February
X *  15th, 1989. You may redistribute freely, on the condition that no
X *  attempt is made to earn a profit for distributing this software. You
X *  may change the code as necessary to fit the system on which you wish
X *  to run it. The author bears no responsibility for the use or misuse
X *  of this game, or any damages caused thereby.
X *
X * Revision History:
X *
X *  1.0   12/09/88   Pete Granger
X *  First release for public use. Incorporates all basic functions.
X *
X *  1.01  12/13/88   Pete Granger
X *  Added the "refresh" option in play_game().
X *
X */
X
X/*
X   This is the configuration and payoff chart for a fair but profitable
X   slot machine. It has a 9.54% chance of paying off on each play, and
X   (on one-dollar bets) will pay back an average of 91.47% of all bets.
X
X         Wheel 1     Wheel 2     Wheel 3
X          -----       -----       -----
X    Bars    1           1           1
X   Bells    2           1           1
X Oranges    1           5           1
X  Lemons    3           1           4
X   Plums    3           2           3
XCherries    4           4           4
X
X
X   Combination     Pays   Frequency   Total Payoff
X      -----        ----     -----         -----
X      Bar * 3      1000        1          1000
X     Bell * 3       100        2           200
X   Orange * 3        50        5           250
X    Lemon * 3        20       12           240
X     Plum * 3        10       18           180
X   Cherry * 3         5       64           320
XCherry * 2 + Any      2      160           320
X                            _____         _____
X                              262         2510
X                                          (234 profit)
X*/
X
X#include <stdio.h>
X#include <curses.h>
X
X#define RANDOM 1
X
Xtypedef unsigned char   u_8;
Xtypedef char            s_8;
Xtypedef unsigned short u_16;
Xtypedef short          s_16;
Xtypedef unsigned long  u_32;
Xtypedef long           s_32;
X
X#define NUMSYMS    6
X#define NAMELEN    8
X#define ON_WHEEL  14
X#define MIN_ROW    0
X#define MAX_ROW   23
X#define MIN_COL    0
X#define MAX_COL   78
X   
X#define BAR    0
X#define BELL   1
X#define ORANGE 2
X#define LEMON  3
X#define PLUM   4
X#define CHERRY 5
X
X#define BAR3      000
X#define BELL3     111
X#define ORANGE3   222
X#define LEMON3    333
X#define PLUM3     444
X#define CHERRY3   555
X#define W_BAR     550
X#define W_BELL    551
X#define W_ORANGE  552
X#define W_LEMON   553
X#define W_PLUM    554
X
X#define PAY_BAR     1000
X#define PAY_BELL     100
X#define PAY_ORANGE    50
X#define PAY_LEMON     20
X#define PAY_PLUM      10
X#define PAY_CHERRY     5
X#define PAY_WILD       2
X#define BUST           0
X
X#define START_MONEY 100
X
Xtypedef int wheel[ON_WHEEL];
X
Xstatic wheel w1 = {BAR, PLUM, CHERRY, BELL, LEMON, PLUM, CHERRY,
X                   ORANGE, LEMON, PLUM, CHERRY, BELL, LEMON, CHERRY};
X
Xstatic wheel w2 = {ORANGE, BAR, CHERRY, ORANGE, PLUM, ORANGE, CHERRY,
X                   BELL, ORANGE, CHERRY, PLUM, LEMON, ORANGE, CHERRY};
X
Xstatic wheel w3 = {BELL, LEMON, CHERRY, ORANGE, PLUM, LEMON, CHERRY,
X                   BAR, PLUM, CHERRY, LEMON, PLUM, LEMON, CHERRY};
X
Xstatic char symnames[NUMSYMS][NAMELEN+1] = {" *BAR*  ", "  BELL  ",
X                                            " ORANGE ", " LEMON  ",
X                                            "  PLUM  ", " CHERRY " };
X
Xstatic char winflash[6][35] = { "*    * *** *   * *   * **** **** *",
X                                "*    *  *  **  * **  * *    *  * *",
X                                "* ** *  *  * * * * * * ***  **** *",
X                                "**  **  *  *  ** *  ** *    * *   ",
X                                "*    * *** *   * *   * **** *  * *",
X                                "                                  " };
X
X#define W1ROW  10
X#define W1COL   5
X#define W2ROW  10
X#define W2COL  17
X#define W3ROW  10
X#define W3COL  29
X
X#define ODDS_R      6
X#define ODDS_C     43
X#define QUERY_R    19
X#define QUERY_C     6
X#define INVALID_R  18
X#define INVALID_C   6
X#define PAY_R      14
X#define PAY_C       6
X#define TOTAL_R    15
X#define TOTAL_C     6
X
X
X#define do_wheel1(W1)  {                            \
X                         move(W1ROW,W1COL);         \
X                         addstr(symnames[w1[W1]]);  \
X                         refresh();                 \
X                       }
X
X#define do_wheel2(W2)  {                            \
X                         move(W2ROW,W2COL);         \
X                         addstr(symnames[w2[W2]]);  \
X                         refresh();                 \
X                       }
X
X#define do_wheel3(W3)  {                            \
X                         move(W3ROW,W3COL);         \
X                         addstr(symnames[w3[W3]]);  \
X                         refresh();                 \
X                       }
X
X#define str_out(R,C)   {                     \
X                         move((R),(C));      \
X                         addstr(outbuf);     \
X                         refresh();          \
X                       }
X
X#define MIN(A,B) (((A)<(B)) ? (A) : (B))
X
Xchar replybuf[80];
Xchar outbuf[80];
X
X/*
X *  Initialize the random number generator.
X */
X
Xvoid init_rand()
X{
X  u_32 z;
X
X  z = time();
X#if RANDOM
X  srandom(z);
X#else
X  srand(z);
X#endif
X}
X
X/*
X *  Returns an integer in the range from min to max, inclusive.
X */
X
Xs_16 range(min,max)
Xu_16 min, max;
X{
X  u_8 det;
X  u_16 dist;
X  s_16 return_val, discard;
X
X#if RANDOM
X  det = random() % 100 + 1;
X#else
X  det = rand() % 100 + 1;
X#endif
X  dist = max - min + 1;
X  if (det > 50)
X#if RANDOM
X    discard = random();
X  return_val = random() % dist + min;
X#else
X    discard = rand();
X  return_val = rand() % dist + min;
X#endif
X  return(return_val);
X}
X
X/*
X * Prompt the user at a break in the instructions.
X */
X
Xrest()
X{
X	printf(" -- More --   ");
X    while (getchar() != ' ');
X}
X
X/*
X * Give the user instructions on the game.
X */
X
Xvoid print_instructions(in_char)
Xchar in_char;
X{
Xsystem("clear");
Xif (in_char != 'y' && in_char != 'Y') return;
Xsystem("stty cbreak -echo");
Xprintf("                   Instructions for One-Armed Bandit\n");
Xprintf("                                  by\n");
Xprintf("                             Pete Granger\n\n");
Xprintf("OBJECT:   To amass a fortune, of course. Also to have a good time\n");
Xprintf("        playing the slots.\n\n");
Xprintf(" MEANS:   I have designed a slot machine which I consider to be\n");
Xprintf("        fairly honest. By both statistical and empirical means,\n");
Xprintf("        it is calculated to have a payoff rate of about 91 percent.\n");
Xprintf("        The payoffs are as follows:\n\n");
Xprintf("               Combination     Pays   Frequency   Total Payoff\n");
Xprintf("                  -----        ----     -----         -----\n");
Xprintf("                  Bar * 3      1000         1          1000\n");
Xprintf("                 Bell * 3       100         2           200\n");
Xprintf("               Orange * 3        50         5           250\n");
Xprintf("                Lemon * 3        20        12           240\n");
Xprintf("                 Plum * 3        10        18           180\n");
Xprintf("               Cherry * 3         5        64           320\n");
Xprintf("            Cherry * 2 + Any      2       160           320\n");
Xprintf("                                        -----         -----\n");
Xprintf("                                          262          2510\n");
Xrest();
Xprintf("\n\n\n\n");
Xprintf("          You will be given an initial bankroll of $%d. Not\n",
X        START_MONEY);
Xprintf("        bad for a day at the casino, right? On each play, you can\n");
Xprintf("        bet from $1 to $5, and the payoff will be proportional\n");
Xprintf("        to the bet. You may also place a bet of 0, which means you\n");
Xprintf("        want to sit out this round, and watch the wheels spin. The\n");
Xprintf("        catch, of course, is that you don't win anything this way.\n");
Xprintf("        The only other restriction is that your bet can't exceed\n");
Xprintf("        your current bankroll.\n");
Xprintf("\n");
Xprintf("          If you wish to refresh the screen (e.g. after receiving\n");
Xprintf("        system messages) enter a 'r' at the 'Bet?' prompt.\n");
Xprintf("\n");
Xprintf("          If you decide you want to quit, just enter a 'q' at the\n");
Xprintf("        'Bet?' prompt. You can then cash in your winnings and\n");
Xprintf("        leave the casino.\n");
Xprintf("\n");
Xprintf("          Also, if your bankroll reaches 0, you will be asked to\n");
Xprintf("        leave the casino. But don't worry, you can always come\n");
Xprintf("        back later.\n");
Xprintf("\n");
Xprintf("              Good luck, and enjoy One-Armed Bandit!\n");
Xprintf("\n");
Xrest();
Xsystem("stty -cbreak echo");
Xsystem("clear");
X}
X
X/*
X *  Blank part of a line with curses.
X */
X
Xvoid blank_seg(row,col,length)
Xu_16 row,col,length;
X{
X  char locbuf[80];
X  u_8 i;
X
X  if (row >= MIN_ROW && row <= MAX_ROW && col >= MIN_COL && col <= MAX_COL)
X  {
X    if ((col+length-1) > MAX_COL)
X      length = MAX_COL - col + 1;
X    for (i = 0; i < length; i++)
X      locbuf[i] = ' ';
X    locbuf[i] = '\0';
X    move(row,col);
X    addstr(locbuf);
X    refresh();
X  }
X}
X
X/*
X *  Print an odds chart on the screen.
X */
X
Xvoid show_odds()
X{
X  extern char outbuf[];
X  extern char symnames[NUMSYMS][NAMELEN+1];
X
X  sprintf(outbuf,"          Pete Granger's");
X  str_out(ODDS_R-5,ODDS_C);
X  sprintf(outbuf,"         ONE-ARMED BANDIT");
X  str_out(ODDS_R-4,ODDS_C);
X  sprintf(outbuf,"        Combination        | Odds");
X  str_out(ODDS_R-2,ODDS_C);
X  sprintf(outbuf,"---------------------------+------");
X  str_out(ODDS_R-1,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[BAR],symnames[BAR],symnames[BAR],PAY_BAR);
X  str_out(ODDS_R,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[BELL],symnames[BELL],symnames[BELL],PAY_BELL);
X  str_out(ODDS_R+BELL,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[ORANGE],symnames[ORANGE],symnames[ORANGE],PAY_ORANGE);
X  str_out(ODDS_R+ORANGE,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[LEMON],symnames[LEMON],symnames[LEMON],PAY_LEMON);
X  str_out(ODDS_R+LEMON,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[PLUM],symnames[PLUM],symnames[PLUM],PAY_PLUM);
X  str_out(ODDS_R+PLUM,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[CHERRY],symnames[CHERRY],symnames[CHERRY],PAY_CHERRY);
X  str_out(ODDS_R+CHERRY,ODDS_C);
X  sprintf(outbuf,"%s %s %s | %4d",
X          symnames[CHERRY],symnames[CHERRY]," *wild* ",PAY_WILD);
X  str_out(ODDS_R+CHERRY+1,ODDS_C);
X}
X
X
X/*
X *  Draw a box with curses, given the top left and bottom right corners.
X */
X
Xvoid draw_box(tlr,tlc,brr,brc)
Xs_16 tlr,tlc,brr,brc;
X{
X  u_8 i, j;
X  u_16 tmp;
X
X  if (tlc > brc)
X  {
X    tmp = brc; brc = tlc; tlc = tmp;
X  }
X  if (tlr > brr)
X  {
X    tmp = brr; brr = tlr; tlr = tmp;
X  }
X  if (tlc < 0) tlc = 0;
X  else if (tlc > 78) tlc = 78;
X  if (brc < 0) brc = 0;
X  else if (brc > 78) brc = 78;
X  if (tlr < 0) tlr = 0;
X  else if (tlr > 23) tlr = 23;
X  if (brr < 0) brr = 0;
X  else if (brr > 23) brr = 23;
X  move(tlr,tlc); addch('+'); refresh();
X  move(brr,tlc); addch('+'); refresh();
X  for (i = tlc + 1; i < brc; i++)
X  {
X    move(tlr,i); addch('-'); refresh();
X    move(brr,i); addch('-'); refresh();
X  }
X  move(tlr,brc); addch('+'); refresh();
X  move(brr,brc); addch('+'); refresh();
X  for (i = tlr + 1; i < brr; i++)
X  {
X    move(i,tlc); addch('|'); refresh();
X    for (j = tlc + 1; j < brr; j++)
X    {
X      move(i,j); addch(' '); refresh();
X    }
X    move(i,brc); addch('|'); refresh();
X  }
X}
X
X/*
X *  Draw the three windows where the wheels appear.
X */
X
Xvoid draw_windows()
X{
X  extern void draw_box();
X
X  draw_box(W1ROW-2,W1COL-2,W1ROW+2,W1COL+NAMELEN+1);
X  draw_box(W2ROW-2,W2COL-2,W2ROW+2,W2COL+NAMELEN+1);
X  draw_box(W3ROW-2,W3COL-2,W3ROW+2,W3COL+NAMELEN+1);
X}
X
X/*
X * Convert the three wheel indices into a simple integer.
X */
X
Xu_16 wheel_sum(s1,s2,s3)
Xu_8 s1,s2,s3;
X{
X  extern wheel w1, w2, w3;
X
X  u_16 return_val;
X
X  return_val = (100 * w1[s1]) + (10 * w2[s2]) + w3[s3];
X  return(return_val);
X}
X
X/*
X * Determine the payoff odds based on the three wheel indices.
X */
X
Xu_16 payoff(s1,s2,s3)
Xu_8 s1,s2,s3;
X{
X  extern u_16 wheel_sum();
X
X  u_16 payoff_index, return_val;
X
X  payoff_index = wheel_sum(s1,s2,s3);
X  switch (payoff_index)
X  {
X    case BAR3:     return_val = PAY_BAR;
X                   break;
X    case BELL3:    return_val = PAY_BELL;
X                   break;
X    case ORANGE3:  return_val = PAY_ORANGE;
X                   break;
X    case LEMON3:   return_val = PAY_LEMON;
X                   break;
X    case PLUM3:    return_val = PAY_PLUM;
X                   break;
X    case CHERRY3:  return_val = PAY_CHERRY;
X                   break;
X    case W_BAR:
X    case W_BELL:
X    case W_ORANGE:
X    case W_LEMON:
X    case W_PLUM:   return_val = PAY_WILD;
X                   break;
X    default:       return_val = BUST;
X                   break;
X  }
X  return(return_val);
X}
X
X/*
X *  Flash the "WINNER!" box on a jackpot.
X */
X
Xvoid flash_win(payoff)
Xu_16 payoff;
X{
X  extern void draw_box();
X  extern void blank_seg();
X  extern char winflash[6][35];
X  extern char outbuf[];
X
X  u_8 i, j, flashes;
X
X  draw_box(1,W1COL-2,W1ROW-3,W3COL+NAMELEN+1);
X  if (payoff >= PAY_BAR)
X    flashes = 10;
X  else if (payoff >= PAY_ORANGE)
X    flashes = 6;
X  else
X    flashes = 3;
X  for (i = 0; i < flashes; i++)
X  {
X    for (j = 0; j < 5; j++)
X    {
X      sprintf(outbuf,winflash[j]);
X      str_out(j+2,W1COL-1);
X    }
X    if (i == flashes - 1)
X      sleep(8);
X    else
X      for (j = 0; j < 5; j++)
X      {
X        sprintf(outbuf,winflash[5]);
X        str_out(j+2,W1COL-1);
X      }
X  }
X  for (i = 0; i < 7; i++)
X    blank_seg(i+1,W1COL-2,36);
X}
X
X/*
X *  Refresh the screen at the user's request. Handy if you get mail in
X *  the middle of a game or something.
X */
X
Xvoid refresh_screen(ts,br)
Xu_32 ts, br;
X{
X  extern void draw_windows();
X  extern void show_odds();
X  extern void blank_seg();
X  extern char outbuf[];
X
X  initscr();
X  draw_windows();
X  show_odds();
X  if (!ts)
X  {
X    blank_seg(TOTAL_R,TOTAL_C,78);
X    sprintf(outbuf,"Starting bankroll: %d",br);
X    str_out(TOTAL_R,TOTAL_C);
X  }
X  else
X  {
X    blank_seg(TOTAL_R,TOTAL_C,78);
X    sprintf(outbuf,"New total (after %d %s) is %d.",
X            ts,((ts != 1) ? "plays" : "play"),br);
X    str_out(TOTAL_R,TOTAL_C);
X  }
X}
X
Xvoid play_game()
X{
X  extern s_16 range();
X  extern u_16 payoff();
X  extern void draw_windows();
X  extern void show_odds();
X  extern void flash_win();
X  extern void refresh_screen();
X  extern void blank_seg();
X  extern wheel w1, w2, w3;
X  extern char symnames[NUMSYMS][NAMELEN+1];
X  extern char replybuf[];
X  extern char outbuf[];
X
X  u_8  r1, s1, r2, s2, r3, s3, offset;
X  u_8  this_bet, maxbet;
X  u_16 c1, c2, c3, counter;
X  u_32 bankroll, times_spun, payoffs;
X
X  bankroll = START_MONEY;
X  this_bet = 0;
X  payoffs = times_spun = 0;
X  s1 = s2 = s3 = 0;
X  initscr();
X  draw_windows();
X  show_odds();
X  while (bankroll)
X  {
X    if (!times_spun)
X    {
X      blank_seg(TOTAL_R,TOTAL_C,78);
X      sprintf(outbuf,"Starting bankroll: %d",bankroll);
X      str_out(TOTAL_R,TOTAL_C);
X    }
X    maxbet = MIN(5,bankroll);
X    sprintf(outbuf,"How much do you wish to bet (0-%d)? ",maxbet);
X    blank_seg(QUERY_R,QUERY_C,78);
X    str_out(QUERY_R,QUERY_C);
X    if (gets(replybuf) == NULL) continue;
X    if (replybuf[0] == 'q' || replybuf[0] == 'Q')
X      break;
X    else if (replybuf[0] == 'r' || replybuf[0] == 'R')
X      refresh_screen(times_spun,bankroll);
X    else
X    {
X      if ((this_bet = atoi(replybuf)) > maxbet)
X      {
X        sprintf(outbuf,"You can't bet that much!");
X        str_out(INVALID_R,INVALID_C);
X        continue;
X      }
X      else
X        blank_seg(INVALID_R,INVALID_C,30);
X      if (this_bet)
X        times_spun++;
X      r1 = range(5,8);
X      r2 = r1 + range(2,4);
X      r3 = r2 + range(2,4);
X      s1 = (s1 + range(0,ON_WHEEL-1)) % ON_WHEEL;
X      s2 = (s2 + range(0,ON_WHEEL-1)) % ON_WHEEL;
X      s3 = (s3 + range(0,ON_WHEEL-1)) % ON_WHEEL;
X      c1 = ON_WHEEL * r1 + s1;
X      c2 = ON_WHEEL * r2 + s2;
X      c3 = ON_WHEEL * r3 + s3;
X      bankroll -= this_bet;
X      for (counter = 0; counter <= c3; counter++)
X      {
X        offset = counter % ON_WHEEL;
X        if (counter <= c1)
X          do_wheel1(offset);
X        if (counter <= c2)
X          do_wheel2(offset);
X        do_wheel3(offset);
X      }
X      if (payoff(s1,s2,s3))
X      {
X        flash_win(payoff(s1,s2,s3));
X        sprintf(outbuf,"The payoff for %d %s is %d.",this_bet,
X                ((this_bet != 1) ? "dollars" : "dollar"),
X                (this_bet * payoff(s1,s2,s3)));
X        bankroll += (this_bet * payoff(s1,s2,s3));
X        if (this_bet)
X          payoffs++;
X      }
X      else
X        sprintf(outbuf,"No winner.");
X      blank_seg(PAY_R,PAY_C,40);
X      str_out(PAY_R,PAY_C);
X      blank_seg(TOTAL_R,TOTAL_C,78);
X      sprintf(outbuf,"New total (after %d %s) is %d.",
X              times_spun,((times_spun != 1) ? "plays" : "play"),bankroll);
X      str_out(TOTAL_R,TOTAL_C);
X    }
X  }
X  blank_seg(QUERY_R,QUERY_C,78);
X  endwin();
X  if (!bankroll)
X  {
X    printf("\nYou are bankrupt after %d %s, %d %s.\n",
X            times_spun,((times_spun != 1) ? "plays" : "play"),
X            payoffs,((payoffs != 1) ? "payoffs" : "payoff"));
X    printf("\nLuck does not seem to be with you. Unfortunately,\n");
X    printf("Guido and Vito, the casino's bouncers, are. They grab\n");
X    printf("you by the elbows and escort you to the sidewalk.\n\n");
X    printf("                      GAME OVER\n\n");
X  }
X  else
X    printf("\nTotal of %d after %d %s, %d %s.\n",bankroll,
X            times_spun,((times_spun != 1) ? "plays" : "play"),
X            payoffs,((payoffs != 1) ? "payoffs" : "payoff"));
X}
X
Xvoid main()
X{
X  extern void init_rand();
X  extern void play_game();
X  extern char replybuf[];
X  extern void print_instructions();
X
X  system("clear");
X  printf("Would you like instructions, y/n [default is n] -> ");
X  fflush(stdout);
X  while (gets(replybuf) == NULL);
X  print_instructions(replybuf[0]);
X  init_rand();
X  play_game();
X}
END_OF_FILE
if test 18965 -ne `wc -c <'bandit.c'`; then
    echo shar: \"'bandit.c'\" unpacked with wrong size!
fi
# end of 'bandit.c'
fi
echo shar: End of shell archive.
exit 0