Skip to content

Pig Dice Digital

You'll turn Pig, the oldest push-your-luck dice game, into software with the rules enforced by code and a computer opponent to play against.

About

Pig is a dice game: roll to build up a turn total, lose it all if you roll a 1, and hold to bank what you've got. It takes thirty seconds to explain and an evening to code properly, with a real turn structure, a computer opponent and a win condition. It's the first step toward turning any tabletop game into software, which is harder than it looks.

At a glance

Per requirement
15 XP
Completion bonus
75 XP
Requirements
5
Takes
One evening
Skill level
Novice (never tried it)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own

Requirements

  1. 1
    Write the rules of Pig in under 80 words before you touch any code. Roll a die and add it to your turn total. Roll a 1 and you lose the turn total. Hold to bank it. First to 100 wins. Writing the rules down first stops you from coding your way into a corner. Take a photo of the written rules. Photo
  2. 2
    Build a two-player version where the turn passes correctly. Give it roll and hold buttons, and show the turn total, both scores and whose turn it is on screen. The roll-a-1 case is where the bugs live, so test it hard. Record three turns, including one that gets lost on a 1. Video
  3. 3
    Add a computer opponent that uses a fixed hold-at-20 strategy. Holding at 20 is the well-known decent strategy. Make the computer visibly take its turn with a short delay between rolls so the player can follow along. Record the computer playing a turn. Video
  4. 4
    Add a win screen and a game log that lists every roll. A scrolling log makes rules disputes impossible. Take a screenshot of a finished game with the log showing the winning turn. Photo
  5. 5
    Play ten games against your bot and keep a tally. Hold at 20 should beat a careless human. If you win nine out of ten, your bot probably has a bug. Take a screenshot of the tally, and write one line on whether you'd change the bot. Photo