Thursday, April 9, 2009

The lowly math of cribbage...

From The Lowly Mathematician:

"Today, I want to talk about card games… On a recent trip home, I had an opportunity to teach my fiance how to play one of my favorite card games. Cribbage. If you are unaware, cribbage is a game in which each player (or team, as the case may be) attempts to score the most points during several rounds. The goal is to be the first team to 121 points. The scoring system and play are somewhat complex, so I’ll just direct you to the wikipedia entry [1] for cribbage, but suffice to say that the game is quite fun. I’ll assume that the reader understands the scoring rules for cribbage for the rest of this post.

While we were playing, we came across several hands which were very difficult to count. For instance, consider the hand:

A-H 2-H 3-H 4-H (5-H)

where - is a card in the hand, and (X-Y) is the cut-card. This hand has the peculiar — and at first unnoticed — property of being worth 12 points. Though it’s not necessarily apparent. The obvious run and flush give 10 points easily, but the sum of all the cards is fifteen, something that is not readily seen, since there are so many cards involved in the sum. This and other odd hands led me to realize that it was probably best for me — especially since we play at night, when my brain is not at its finest — to leave the tedious task of counting these “weird” hands to a computer. The issue was — where to get such a program. Certainly such things exist. But that requires reconnaissance and time, time that I could be spending doing something more interesting.

Like writing my own.

Therefore, I present to you, in only around 200 lines of Haskell, a full library for playing card-like structures, complete with shuffling, dealing, and permutation-irrelevant equality, as well as a cribbage score counter which uses this library for counting cribbage scores…"

Read full post here.

No comments: