Programming Assignment #1, CPS 100E, Fall 1996:
Leaving Las Vegas

Due Date: Early bonus: Monday, September 16, midnight
Final Due Date: Friday, September 20, midnight

table of contents

[ Introduction | Playing Craps | Playing Roulette | Submitting | Extra Credit ]

Introduction

The files for this assignment can be found in ~ola/cps100e/firstprog. These files are itemized below and accessible via netscape or by copying the files from the directory.

You should create a directory cps100e in which all work for this class will be done (see the first lab for an explanation of how to do this). Each assignment should be done in its own subdirectory, for this assignment create a directory firstprog. All work for your assignment will then be done in the directory ~/cps100e/firstprog. You should change the acl (access control list) on your cps100e directory to give the professors, TAs, and UTAs permission to read your files, this was described in the first lab:

     fs setacl cps100e ola:cps100e read
Change acl permissions before creating the firstprog subdirectory, or you'll need to change the acl on the subdirectory too.

You will write programs to simulate the games of craps and roulette as desribed in A Computer Science Tapestry, pages 219-221, exercises 5.16 and 5.17. The explanations from the book are reproduced below.


A Simulated Craps Game (8 points))

Write a program that allows the user to play craps, but to place a bet before each sequence of dice rolls. Start with an initial bankroll of $500.00. Betting $100.00 and winning increases the bankroll by $100.00, losing decreases the bankroll by $100.00. As a start, use the class Game below and implement each member function. Include all the member functions in the same file as main(), there's no reason to use separate .h and .cc files for this program (the code below is stored in docraps.cc and accessible as described above.) Part of a sample run is shown below.
  prompt>  playgame
  place your bet for this round
  enter wager between 0 and 500: 100
  rolling ... 6 5
  natural winner!!
  you have $600
  do you want to continue [yes/no]?: yes
  place your bet for this round
  enter wager between 0 and 600: 200
  rolling ... 5 1
  rolling ... 4 5
  rolling ... 6 4
  rolling ... 5 4
  rolling ... 5 2
  loser, lost going for 6
  you have $400
  do you want to continue [yes/no]?: yes
  place your bet for this round
  enter wager between 0 and 400: 400
  rolling ... 6 4
  rolling ... 1 2
  rolling ... 3 4
  loser, lost going for 10
  you're busted, game's over
As a start, you can implement the class Game and use the function main() shown below. This code is stored in craps.cc. class Game { public: Game(); // initialize state appropriately bool Continue(); // returns true if game continues to play void MakeBet(); // place a wager for one turn of the game void Play(); // play the game once private: int myBankRoll; // current bank roll (money in hand) int myWager; // current wager (bet) int RollTwo(); }; // implement member functions here int main() { Game craps; do { craps.MakeBet(); craps.Play(); } while (craps.Continue()); return 0; }

A Simulated Roulette Game (12 points)

Write a program similar to the craps-playing program, but simulate a roulette game rather than a craps game. In roulette you can place bets on which of 38 numbers is chosen when a ball falls into a numbered-slot. The numbers range from 1--36 with special 0 and 00 slots. The 0 and 00 slots are colored green; each of the numbers 1--36 is red or black. The red numbers are 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, and 36. Gamblers can make several different kinds of bet, each of which pays off at different odds.

bet odds
red/black 1 to 1
odd/even 1 to 1
single number 35 to 1
two consecutive numbers 17 to 1
three consecutive numbers 11 to 1

A payoff of 1 to 1 means that a $10.00 earns $10.00 (plus the bet $10.00 back); 17 to 1 means that a $10.00 earns $170.00 (plus the $10.00 back). If the wheel spins 0 or 00 then all bets lose except for a bet on the single number 0/00 or on the two consecutive numbers 0/00.

You may find it useful to implement a separate Bet class to keep track of the different kinds of bets and odds. For example, when betting on a number you'll need to keep track of the number while betting on red/black requires only that you remember the color chosen.

You should use a class similar to the Game class from the craps program, but modified to play roulette.

Adding bells and whistles to the program can earn extra points.


Submitting

You should create a README file for this and all assignments. All README files should include your name as well as the name(s) of anyone with whom you collaborated on the assignment and the amount of time you spent.

To submit your assignment, type:

submit100e firstprog README docraps.cc doroulette.cc Makefile ... You can submit by typing make submit if the correct README file is in the directory from which you submit. You can always edit the Makefile to add or change filenames.

Extra Credit

Modify the roulette program so that several people can play at once. You can do this in many ways, one way is to prompt for the number of players, ask for their names, then on each roll of the wheel ask for each player's wager. If a player loses all her/his money, the player should be excused from the game and can no longer play.

Submitting Extra Credit

To submit the extra credit assignment, type: submit100 firstprog.xtra README .......... where you include all the files you need to play the game with multiple players.