Fundamentals of Computer Science I: Media Computing (CS151.02 2007F)

Homework 10: Simulating Craps

This homework assignment is also available in PDF.

Assigned:
Due:
Extensions due to weather automatically approved.

Summary: In this assignment, you will further explore the use of the random procedure to simulate a game of Craps.

Purposes: To reinforce the exploration of the random procedure from the lab on randomness and simulation. To remind you that the house always wins.

Expected Time: One to two hours.

Collaboration: You may work in a group of any size between one and four, inclusive. You may consult others outside your group, provided you cite those others. You need only submit one assignment per group.

Submitting: Email me your work, using a subject of CSC151 Homework 10.

Warning: So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.

Background

One of the many table gains available in most casinos is Craps. While Craps has a variety of betting rules, the basic rules for rolling the dice are fairly simple. Here's what Wikipedia has to say on the subject.

Craps features a plethora of bets, but the most fundamental is the pass line wager, which nearly all players make. On a come-out roll, the pass line bettors win when either a 7 or 11 is rolled. A 2, 3, or 12 loses, and is called craps. When any other number (4, 5, 6, 8, 9, or 10) is rolled, it is called the point. Once a point has been set, the pass-line bettor wins if the point is rolled again, and loses if a 7 is rolled first (seven-out).

For our purposes in this assignment, we'll assume one die is red (or scarlet) and one die is black.

Assignment

In this assignment, you will simulate the game of Craps, focusing only on the results for pass-line bettors.

a. Write a procedure, (craps-narrative), that plays and narrates one sequence from a game of Craps. Your narrative should roll new dice each time, and therefore have unpredictable results.

> (craps-narrative)
Come-out roll.
  The red die shows 1.  The black die shows 6.
A seven: You win!
> (craps-narrative)
Come-out roll.
  The red die shows 2.  The black die shows 3.
The point is 5.
  The red die shows 5.  The black die shows 5.
The point is 5.
  The red die shows 3.  The black die shows 4.
Seven out.
> (craps-narrative)
Come-out roll.
  The red die shows 1.  The black die shows 5.
The point is 6.
  The red die shows 3.  The black die shows 5.
The point is 6.
  The red die shows 4.  The black die shows 2.
You made the point.
> (craps-narrative)
Come-out roll.
  The red die shows 1.  The black die shows 5.
The point is 6.
  The red die shows 3.  The black die shows 5.
The point is 6.
  The red die shows 4.  The black die shows 2.
You made the point.
> (craps-narrative)
Come-out roll.
  The red die shows 4.  The black die shows 1.
The point is 5.
  The red die shows 2.  The black die shows 5.
Seven out.

b. To the Statistician, the interesting thing about Craps is not what happens in one game, or even a few, but what happens, on average, over a sequence of games.

Write a procedure, pass-line-bet-wins? that simulates one sequence from a game of Craps and returns true (#t) if the pass-line bettor wins and false otherwise.

Using this procedure, simulate one thousand sequences of Craps and determine how often the pass-line bettor wins in that sequence.

Helpful Hints

For both parts of the assignment, you will likely find it useful to write a main procedure that does the initial roll and a helper procedure that gets passed the points goal from the first roll. For example, in the first part, you might write:

(define craps-narrative
  (lambda ()
    (let ((point ...))
      ...
      (continue-narrative point))))

(define continue-narrative
  (lambda (point)
    (let ((nextroll ...))
      ...)))

We wrote the following two helper procedures in our own solution to this assignment. You may also find them helpful.

(define roll-a-die
  (lambda ()
    (+ 1 (random 6))))

(define display-dice
  (lambda (red black)
    (display "  The red die shows ")
    (display red)
    (display ".  The black die shows ")
    (display black)
    (display ".")
    (newline)))

Sources Cited

Wikipedia (2006). Craps. Online article at http://en.wikipedia.org/wiki/Craps (dated 28 September 2006, visited 1 October 2006).

 

History

Sunday, 1 October 2006 [Samuel A. Rebelsky]

Monday, 2 October 2006 [Samuel A. Rebelsky]

Thursday, 1 March 2007 [Samuel A. Rebelsky]

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Wed Aug 29 08:59:26 2007.
The source to the document was last modified on Sun Jul 29 16:12:58 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007F/Homework/hw.10.html.

You may wish to validate this document's HTML ; Valid CSS! ; Creative Commons License

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2007 Janet Davis, Matthew Kluber, and Samuel A. Rebelsky. This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.