11-30-2011 03:42 PM
If you can't tell from my recent rash of posts I am having a slow week...
Craps is a gambling game:
1. The game is played with 2 dice
2. If the pips on the dice total 2, 3 or 12 the player loses
3. If the pips on the dice total 7 or 11, the player wins
4. If the pips total 4, 5, 6, 8, 9 or 10 the total pips establishes the 'point.' The player continues to roll until he rolls the point (wins) or rolls a 7 (loses)
Write a program that simulates a game of craps, calculate various statistics from the game:
A. Most Common Roll
B. Win Percentage
C. Number of Rolls/Game
D. Maximum Rolls/Game
E. Whatever else you can think of...
FROM WIKIPEDIA: http://en.wikipedia.org/wiki/Craps
Bank craps is a game played by multiple players betting against a casino. Each casino might set slightly different payouts for the various bets. Players take turns rolling two dice and whoever is throwing the dice is called the "shooter". Players can bet on the various options by placing chips in the appropriate sections of the board. It may be required to ask the dealer to place certain bets.
While acting as the shooter, a player must have a bet on the "Pass" line or the "Don't Pass" line. Pass and don’t pass are sometimes called "Win" and "Don’t Win" or "Right" and "Wrong" bets. The game is played in rounds and these "Pass" and "Don't Pass" bets are betting on the outcome of a round. The shooter is often replaced at the end of the round or when they lose a round with a seven. The dice are moved clockwise around the table for the next player to become shooter. The shooter is presented with multiple dice (typically five) by the "stickman", and must choose two for the round. The remaining dice are returned to the stickman's bowl and are not used.
Each round has two phases: "come-out" and "point". To start a round, the shooter makes one or more "come-out" rolls. A come-out roll of 2, 3 or 12 loses and is called "craps". Anyone betting on the Pass line loses in this situation. A come-out roll of 7 or 11 (a "natural") wins and results in a payout for "pass line" bets. The other possible numbers are the point numbers: 4, 5, 6, 8, 9, and 10. If the shooter rolls one of these numbers on the come-out roll, this establishes the "point" - the number that must be rolled again before a seven. The dealer flips a button to the "On" side and moves it to the point number signifying the second phase of the round. If the shooter rolls a seven before repeating the point number (a "seven-out"), the Pass line loses and the round ends.
|1||Snake Eyes||Ace Deuce||Easy Four||Five (Fever Five)||Easy Six||Natural or Seven Out|
|2||Ace Deuce||Hard Four||Five (Fever Five)||Easy Six||Natural or Seven Out||Easy Eight|
|3||Easy Four||Five (Fever Five)||Hard Six||Natural or Seven Out||Easy Eight||Nine (Nina)|
|4||Five (Fever Five)||Easy Six||Natural or Seven Out||Hard Eight||Nine (Nina)||Easy Ten|
|5||Easy Six||Natural or Seven Out||Easy Eight||Nine (Nina)||Hard Ten||Yo (Yo-leven)|
|6||Natural or Seven Out||Easy Eight||Nine (Nina)||Easy Ten||Yo (Yo-leven)||Boxcars or Midnight|
SPOILER: Below is my blacked-out answer
options fullstimer macrogen symbolgenmlogic mprint;
%do i=1 %to 2;
if rol.find()=0 then
declare hash ga(ordered:'a');
declare hash rol();
do i=1 to &games;
win=ifn(pips in (2,3,12),1,0);
loss=ifn(pips in (7,11),1,0);
if pips in (4,5,6,8,9,10) then
do until(win or loss);
declare hiter iga('ga');
declare hiter irol('rol');
if max=n then
put 'Most Common Roll: ' r1 ' / ' r2 ' with ' n comma8. ' rolls';
put 'Longest game: ' rolls 'rolls';
if rolls>1 then
put 'Total Rolls Processed: ' tot comma12.;
put 'Average Rolls per Game: ' avg;
put 'Win Percentage: ' wpct percent8.2;
put 'Probability of Winning a Game with More than 1 roll: ' wpctx percent8.2;
12-18-2013 08:58 AM
Those who have my book Statistical Programming with SAS/IML Software can find a PROC IML solution on pp 322-327. The code is available as a free download from the book's Web page.