Functional Python Programming

(Wang) #1

The PyMonad Library


There's a lot of very strange gambling terminology involved. We can't provide much
background about the various buzzwords involved. In some cases, the origins are
lost in history.


Craps involves someone rolling the dice (a shooter) and additional bettors. The game
works like this:


The first roll is called a come out roll. There are three conditions:



  1. If the dice total is 7 or 11, the shooter wins. Anyone betting on the pass line
    will be paid off as a winner, and all other bets lose. The game is over, and the
    shooter can play again.

  2. If the dice total is 2, 3, or 12, the shooter loses. Anyone betting on the don't
    pass line will win, and all other bets lose. The game is over, and the shooter
    must pass the dice to another shooter.

  3. Any other total (that is, 4, 5, 6, 8, 9, or 10) establishes a point. The game
    changes state from the come out roll to the point roll. The game continues.


If a point was established, each point roll is evaluated with three conditions:



  • If the dice total is 7, the shooter loses. Indeed, almost all bets are losers except
    for don't pass bets and a special proposition bet. Since the shooter lost, the
    dice are passed to another shooter.

  • If the dice totals the original point, the shooter wins. Anyone betting on the
    pass line will be paid off as a winner, and all other bets lose. The game is
    over, and the shooter can play again.

  • Any other total continues the game with no resolution.


The rules involve a kind of state change. We can look at this as a sequence of
operations rather than a state change. There's one function that must be used first.
Another recursive function is used after that. In this way, it fits the monad design
pattern nicely.


As a practical matter, a casino allows numerous fairly complex side bets during the
game. We can evaluate those separately from the essential rules of the game. Many
of those bets (the propositions, field bets, and buying a number) are bets a player
simply makes during the point roll phase of the game. There's an additional come and
don't come pair of bets that establishes a point-within-a-point nested game. We'll stick
the the basic outline of the game for the following example.


We'll need a source of random numbers:


import random
def rng():
return (random.randint(1,6), random.randint(1,6))

Free download pdf