Project Two due Fri 21 Sep, 1PM

MCS 260 Project Two : roulette, due Friday 21 September 2001, at 1PM.

Roulette is a gambling game in which a ball is dropped on to a revolving numbered wheel.

The purpose of the project is to write a program that simulates this game. For sake of simplicity, we assume that the gambler places only one bet for every drop of the ball. The range of values for the ball is 0..64: all integer numbers between 0 and 64, 0 and 64 included. Denoting the gambler's bet by b and the value of the ball by v, we rank the possible rewards in decreasing order as follows :

       b == v       : 15 tokens (+ token used to place the bet)
       b in [v,v+1] :  7 tokens (+ token used to place the bet)
       b in [v,v+2] :  3 tokens (+ token used to place the bet)
       b in [v,v+4] :  1 token  (+ token used to place the bet)
The token used to place the bet is returned when the parity of bet and token are the same and bet and token are in the same half of the range 0..64 (i.e., b,v in [0,32] or b,v in [33,64], but not for example b in [0,32] and v in [33,64]). In all other cases, the gambler loses the token. Note that zero is a special number. Unless a bet is placed on zero, the token is lost.

The game ends if the user enters a negative number or if there are no more tokens available. At the end of the game, the program prints the balance of available tokens. There is a one token charge to play the game, so the balance is one less than the amount of available tokens before the user entered a negative bet. In case the gambler ran out of tokens, the balance is consequently -1 and the program reminds the gambler to pay the fee. With a positive balance, the program invites the user to play again.

Following is an example of a profitable session :

      [jan@galois]% ./roulette
      Give the number of available tokens : 3
        place your bet (negative to leave): 9
        outcome is : 15, token kept, balance is 3.
        place your bet (negative to leave): 12
        outcome is : 12, gained 15 tokens, balance is 18.
        place your bet (negative to leave): -3
      Your ending balance is 17.  Please play again.
      [jan@galois]% 
But in general, you will lose :
      [jan@galois]% ./roulette
      Give the number of available tokens : 2
        place your bet (negative to leave): 8
        outcome is : 4, gained 1 token, balance is 3.
        place your bet (negative to leave): 2
        outcome is : 40, token lost, 2 left to play.
        place your bet (negative to leave): 19
        outcome is : 4, token lost, 1 left to play.
        place your bet (negative to leave): 34
        outcome is : 28, token lost, 0 left to play.
      Your ending balance is -1.  Pay the gambling fee.
      [jan@galois]% 
Make sure the game generates new random numbers each time you launch the program. In Lecture 7 we have seen how to achieve this.

Mind spelling mistakes in the dialogue with the user and the output.

The first line of your program should be like

                     /* MCS 260 Project Two by <Author> */
where you replace the <Author> by your name.

The gcc compiler will be used to test your program. So even if you have developed your program in a Windows environment, test your code on icarus.cc.uic.edu with gcc. To ensure your program is written in ANSI C, compile with the option -ansi, e.g., like

                     gcc -ansi proj2.c
Programs that are not conform the ANSI C standard will be discounted.

The printout of your program will be collected at the start of the lecture on Friday 21 September, at 1PM. Before the deadline, send the code by e-mail to janv@uic.edu from your account on icarus. If you saved your program in the file proj2.c, then you send your program typing on icarus the following command :

                     mail janv@uic.edu < proj2.c
This ensures your program is free from any encapsulations. Note that the e-mail address is my university netid and not the address at the MSCS department.

If you have questions, comments, or difficulties, feel free to come to my office for help.