Craps Dice Game

Play a given number of rounds with a given set of players. For each play try to match the first roll of a pair of dice.

Recreated in coffeescript:

players = ['Ward', 'Tom', 'Paul', 'Jerry'] bet = 100 score = {} for who in players score[who] = 500 die = -> Math.ceil Math.random()*6 eq = (roll,nums) -> -1 != nums.indexOf roll pr = (string) -> console.log string play = (who) -> pr "#{who} rolls #{point = die()+die()}" win = -> pr " win #{bet} for #{score[who]+=bet} total" lose = -> pr " lose #{bet} for #{score[who]-=bet} total" play = -> pr " then #{roll=die()+die()}" return play() unless eq roll, [point, 7] roll if eq point, [7, 11] win() else if eq point, [2, 3, 12] loose() else if play() != 7 win() else lose() for round in [1..3] for who in players play who

Produces this output:

Ward rolls 4
  then 8
  then 6
  then 7
  loose 100 for 400 total
Tom rolls 9
  then 7
  loose 100 for 400 total
Paul rolls 8
  then 6
  then 10
  then 7
  loose 100 for 400 total
Jerry rolls 7
  win 100 for 600 total
Ward rolls 6
  then 9
  then 7
  loose 100 for 300 total
Tom rolls 12
  loose 100 for 300 total
Paul rolls 11
  win 100 for 500 total
Jerry rolls 8
  then 6
  then 3
  then 7
  loose 100 for 500 total
Ward rolls 12
  loose 100 for 200 total
Tom rolls 2
  loose 100 for 200 total
Paul rolls 7
  win 100 for 600 total
Jerry rolls 8
  then 6
  then 9
  then 4
  then 3
  then 7
  loose 100 for 400 total

I recognized this to be a variation of a random walk. Even so, with names of real people included, I found it strangely entertaining to read.

The friends were Tom Kelm, Paul Erickson and Jerry Dijak. I don't recall that they were equally fascinated in my results.