Craps

Dice, anyone?

September 2004
Jim Mahoney

dice[] := 
        Module[{}, 
Return[{
Random[
                Integer, {1, 6}], 
Random[
                Integer, {1, 
                  6}]
}]
];

dice[]

dice[]

Rules:
  First roll : 
       5 or 11 wins.
       2, 3, or 12 loses.
       4,6,8,9,10 sets the "point".
  Following rolls :
      point wins
      7 loses
      otherwise, roll again.

\(\(\( (*\ Globals : \ rollNumber, \ 
      point\ *) \)\(
\)\(\(rollNumber = 
        0;\)

    \(point = \(-1\);\)

    \(roll[] := 
        Module[{n, roll}, 
rollNumber = 
            rollNumber + 1; 
roll = 
            dice[]; 
Print["The dice come up as "\  <> \ ToString[roll] <> "."]; 
n = 
            Total[roll]; 
If[\ \((n == 7\  || \ 
                  n == 11)\)\  && \ 
              rollNumber == 
                1, 
Print["You win!"]; 
rollNumber = 
              0; 
Return[];
]; 
If[\ \((n == 2\  || \ n == 3\  || 
                  n == 12)\)\  && \ 
              rollNumber == 
                1, \ 
Print["You lose."]; 
rollNumber = 
              0; 
Return[];
]; 
If[
            rollNumber == 1, 
point = 
              n; 
Print["Your point is "\  <> \ 
                ToString[
                  point] <> "."];
]; 
If[
            rollNumber > 1\  && \ 
              point == 
                n, 
Print["You made your point - you win."]; 
rollNumber = 
              0; 
Return[];
]; 
If[
            rollNumber > 1 && 
              n == 
                7, 
Print["Oops - you crapped out."]; 
rollNumber = 
              0; 
Return[];
]; 
Print["Keep rolling."];
];\)\)\)\)

roll[]

roll[]

roll[]