CSC 306 Introduction to Programming with C++

More on Pseudo-random Numbers in C++


Objectives

  • To make additional use of classes, pseudo-random numbers, and the switch statement.

  • To write a game that has elements of fun and interactivity.
from http://www.shutterstock.com/pic-164738.html

In this lab, we will expand our use of some of the concepts we have recently learned to write a game program. We have already seen and modified RollDice.cpp, a program that contains two classes, the RandGen class that generates pseudo-random numbers and the Dice class that uses RandGen to simulate dice namely.

The History of C++ and Gaming...

The development of C++, as is the case with many technological gains in the past 20 years, started by a game called Space Travel. The UNIX operating system (the predecessor to the LINUX environment you have encountered already) was created in 1969 by a computer scientist at Bell Laboratories named Ken Thompson. Thompson had been a researcher on the pioneering MULTICS project, which was an attempt to create an ‘information utility’ that would gracefully support interactive time-sharing of mainframe computers by large communities of users. When Bell Labs withdrew from the MULTICS research consortium, Ken Thompson was left with some MULTICS-inspired ideas about how to build a filesystem. He was also left without a machine on which to play a game he had written called Space Travel, a science-fiction simulation that involved navigating a rocket through the solar system. Thus, he created an operating system (OS) called UNIX as (1) a platform for him to be able to play the Space Travel game and (2) a testbed for his ideas about operating system design that grew out of the MULTICS project.

Thompson decided that Unix needed a system programming language. After a rapidly abandoned attempt at Fortran (a programming language used by many scientists to test their applications), he created instead a new language of his own, which he called B. This language was one of the ancestors of C and was similar except it did not have types. Thompson then worked with Dennis Ritchie of Bell Labs, and Ritchie created the C Programming Language in 1971-1972 that was designed to improve the design of the UNIX OS. To this day, both UNIX and LINUX operating systems are written in C. Interestingly, Mac OS10 (the operating system for the Apple computers) has as its base a UNIX-like operating system with the characteristic Apple interface laid on top.

Initially designed as a system programming language for the UNIX OS, the features of C expanded to have wide usage on many different systems. As mentioned in a previous assignment, Bjarne Stroustrup at Bell Labs developed C++ during the early 1980's as a superset language of C, supporting the best features of C such as efficiency and low-level support for system-level coding.

The Game of Craps

The History and Origin

Dice games can be dated back to the time of the Holy Roman Empire. Soldiers in the Roman Legions used to shave pig knuckles into the shapes of cubes and toss them onto their inverted shields as a form of entertainment while in camp. This is the origin of the term "to roll the bones".

The Arabs also played a game using small numbered cubes called azzahr (meaning "the die"). The game that presently is called craps migrated to France, where the French renamed the Arab game "hasard". When the game arrived in England some time before 1500 AD, it was given the English spelling of the same word, "hazard", and the roll of lowest value in hazard was called "crabs". The French adopted that term from the English, but its spelling changed to "crabes". In the early 1700's, the game crossed the Atlantic to the French colony of Acadia. In 1755, the French lost Acadia to the English, the French-speaking Acadians, who were kicked out of present-day Nova Scotia, relocated in Louisiana, where they were called Cajuns and developed a language called Louisiana French. The Cajuns still played the old dice game, but dropped the title of "hasard" and called the game simply "crebs" or "creps", which was their spelling of the French "crabes". By 1843, the Cajun word came into American English as "craps".

The Basics

The person rolling the dice in craps is called "the shooter". Craps is played with the shooter rolling 2 six-sided dice. (Note that this is NOT the same as rolling a single 12-sided die.) For each turn (a round) of the game, the shooter rolls the dice and wins or loses money based on the result.

For this lab, you will focus on the rules for the craps game for one player. The simplest version is as follows:

  1. The shooter places a bet of some dollar amount.

  2. The shooter rolls the dice and wins or loses according the the rolls total:
    • A total of 7 or 11 and the shooter wins.
    • A total of 2, 3, or 12 (these are called rolling craps) means the shooter loses. The term "snake eyes" is used when the total is 2 (two dice with a single dot face up each).
    • A total of 4,5,6,8,9 or 10 on the roll results in something different. This total is established as "the point", and the shooter has to roll again until the rolling total is either "the point" or a 7. The shooter wins if "the point" is rolled again before a 7 is rolled, and the shooter loses if a 7 is rolled before "the point" is rolled again.

  3. The bet is then paid out and another turn can occur if the player desires.


Lab Specifics

This lab is to be done individually.

Write a craps game (in a source file called YourLastName305_L06.cpp) that will allow a user (player) to play the game of craps with the computer. This game is to use both of the Dice and RandGen classes. How you construct the game is up to you, but (1) be sure to make good use of functions and NOT run everything from main(), and (2) your program should proceed as detailed below:


Be sure to:

When you have completed your program and have it working to your satisfaction, drop the source code and your Microsoft Word Lab write-up YourLastName_306L6.doc into the CSC306_L06 dropbox on the Academic server.
Back to Introduction to Computer Programming with C++ Homepage