ESc 014

Assignment 8 -- Mille Bornes
Due Tuesday, June 4, 2002
(No lates accepted after 3pm, Fri, June 7)



Mille Bornes (pronounced "meel born") refers to the stones that appear at regular intervals on the highways of France. We would call them "milestones" in English, and they show the distance to the next town. It is also the name of a card game which is sometimes known as "1000 miles". In it, two automobiles (players) take turns in a simulated "race" where the cards can be used to go forward a certain number of miles, upgrade your car, and sabotage your opponent. The first player to go forward 1000 miles is the winner.

Your Mission

Your final assignment for this course is to create a scaled-down two-player version of this game. You'll be using the car class you created last week to simulate the players' cars.

Upgrading your Car Class

Before beginning the game, we need to add a few more member functions to your car class. Alter your "car.cpp" and "car.h" files from Assignment 7 to include the following:
void car::setGas(double newGasLevel)
   // If newGasLevel is between 0 and the tank capacity,
   // sets the private variable keeping track of
   // the amount of gas in the car to be the number
   // in newGasLevel.  Nothing happens if newGasLevel
   // is a negative number or greater than the tank capacity.

void car::displayDistanceGraph() const
   // Displays the total forward distance that the
   // car has gone as a horizontal bar graph.  Use
   // asterisks (*) to represent distance the
   // car has traveled and dashes (-) to represent
   // distance not traveled yet.  Each * or - represents
   // 20 miles.  For example:
   //    100  200  300  400  500  600  700  800  900  1000
   // *******-------------------------------------------
   // this bar graph shows the car has gone 140 miles out
   // of 1000.  Be sure to include the mile labels as I do
   // above.

ostream& operator << (ostream& outs, const car& someCar)
   // This function overloads the << operator so
   // that you can use it with cars.  It will be a
   // replacement for the showDashboard function
   // you wrote in assignment 7.  Note that this function
   // is a friend of the car class.  You'll
   // need to use the friend keyword
   // when you write the prototype in the header file.
   // Use the examples in class and in the book to guide you.
   // Once this function is written, you'll be able to
   // do the following:
   // car c1;
   // cout << c1;
   // and it will print the car's owner, remaining gas,
   // distance traveled, and current gear to cout.
Write a small main function to test these out before going on!

The Game

In our scaled-down version of the game, two players will take turns drawing cards from a special "deck". Here are the cards that a player might draw:

Card Name Meaning
drain gas from opponent decreases opponent car's gas supply by 5 gallons. If opponent's car has less than 5 gallons to start with, opponent's gas supply is set to zero
opponent out of gas sets opponent car's gas supply to zero
opponent stop sets opponent car's gear to park
opponent reverse sets opponent car's gear to reverse
roll sets your own car's gear to forward
gas can adds one gallon of gas to your own tank (do nothing if tank already full)
fill tank fills your own car's gas tank to maximum
move 50 miles moves your own car 50 miles (or as many miles as remaining gas allows)
move 100 miles moves your own car 100 miles (or as many miles as remaining gas allows)
move 200 miles moves your own car 200 miles (or as many miles as remaining gas allows)

Note: for the "move 50 miles", "move 100 miles", and "move 200 miles" cards, movement decreases the car's remaining gas, just as it did back in assignment 7.

Each time a player draws a card, whatever the card says will occur for that player as long as it is legal. For example, if a player draws a "move 50 miles" card, but that player's car gear is still in park, nothing should happen except an explanatory message. The car will go forward only if the car has gas remaining and is in forward gear (that is, if the player previously drew a "roll" card). Note that if a player draws a "move 50 miles" card while the car is in reverse, the car will move backward 50 miles! But remember, you already performed these error checks in assignment 7. So you won't have to do any more work to ensure that the card is legal. The class takes care of it. If the player gets a "move 50 miles" card, you need simply call the go function for that car with 50 as an argument.

Players continue taking turns drawing cards until one car goes forward over 1000 miles.

The Details

You'll be writing your program in a new source code file. The primary algorithm for your program is the following:
  1. Allow the two players to enter their names. Create two cars where each car will get 20 miles per gallon, have a 20 gallon capacity tank, and whose owner will be the player's name.
  2. Player 1 will start.
  3. Player picks a card at random.
  4. Display the card chosen and call the appropriate member function(s) in the car class to perform the required operation.
  5. Display the stats for both cars (using the << operator)
  6. Display each car's horizontal bar graph showing graphically the distance each car has traveled. You will use the displayDistanceGraph function you wrote previously.
  7. Pause so that the user can see the results of the turn. You can do this simply by having the user enter in any character from the keyboard to continue.
  8. Change turn to the next player.
  9. Repeat steps 3 through 8 until one player goes over 1000 miles.

As always, you should use functions to make this program easier to write, debug, and read. The required ones are:

As always, you are encouraged to use other functions to help make the program easier to manage. Other functions you might consider using are playGame that contains the code for the main algorithm of the game so that the main function won't be too long and getRandom that returns a random number.

Try before Coding

I left my version of this game for you to try out on BlackBoard. It's an executable file called "millebornes.exe". After downloading it, just double-click to start it. Your game doesn't need to look EXACTLY like mine, but it helps to see what sample output looks like. If you'd like to see the real (physical) card game, just drop by my office.

Extra Credit Alert

There won't be much user interaction in this game. In fact, the user will simply be watching the action and unpausing the game between turns. The real Mille Bornes game actually deals a certain number of cards to each player (say 5) and then the user gets to pick which card in his/her hand to play instead of it being completely random. If the user can't play any of his/her cards, one must be discarded. On the player's next turn, a new random card is issued to replace the previously played or discarded card.

You will get a full 5 points of extra credit (that's an extra 10%!) for implementing this interactive version of Mille Bornes. The interactive version is also on BlackBoard and you can try it out to see how something closer to the real game plays. Do NOT attempt the extra credit until you've got the regular assignment working. You will get more points for a working regular assignment than for a non-working or late extra credit attempt.

You can also gain extra credit (2 pts max) by expanding the original assignment. Here are a couple of ideas:

A maximum of 5 points of extra credit can be obtained on this assignment.

Turning this in

As always, paste in your test results at the bottom of your source code. It will be lengthy to paste in an entire game so just paste in a round or two.

Turn in both a hard copy and an electronic copy. Like last week, you will have three files in your project, so please put them into a folder named with your name and zip them up into a single file using a utility like winZip and then upload that single file to BlackBoard. In the Olin 110 lab, you can do this by right-clicking on the folder that you want to zip up and then choosing the "Add to Zip" command in the menu that pops up. See me if you're having problems doing this.


No lates will be accepted after 3pm on Friday, June 7, 2002.
50 points will be divided as follows:

Administrative statement

This is an individual project. I encourage you to talk to others about the general nature of the project and ideas about how to pursue it. However, the technical work, the writing, and the inspiration behind these must be substantially your own. If any person besides you contributes in any way to the project, you must credit their work in your report. Similarly, if you include information that you have gleaned from other published sources, you must cite them as references. Looking at, and/or copying, other people's programs or written work is inappropriate, and will be considered cheating.

Return to Assignment Index