Raspberry Pi Powered D20 Dice Testing Rig

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Raspberry Pi Powered D20 Dice Testing Rig

Post by /RaspberryPi »

Image Tabletop gamers (that is D&D style Role-Playing Games for you non-gamers) often make use of dice to add some chaos to the game's plot. The twenty-sided die (d20) is often used to this end and just as often gamers get superstitious about their die. When a player rolls well during a game the die is "loaded" and when they roll poorly the die is "cursed." I have been gaming for many years and have heard some version of this argument many, many times, so I decided to find out if game dice are actually, physically "fair."
Fair is tough to define, but I decided to use a "Goodness of Fit" test to determine if the die is behaving in a reasonably expected manner. After some research I decided to roll a d20 1000 times to determine if it was fair. This seemed....unpleasant. So I built "Fortuna."
Behind the touch screen is a Raspberry Pi 3b with a bit of python on it to complete the following steps.
  1. Activate a mosfet to power a 12 volt solenoid underneath the rolling cup. This fires the die vertically about 4-5 inches. The system then waits two seconds for the die to settle down.
  2. Snap a picture with a Picam and label it with the die serial number.
  3. Store the picture in a serial numbered directory on an SMB share so I can get it over to my Mac
  4. Feed pictures to custom machine learning system to "read" the numbers on the top and determine the value for that roll. Enter this into a results file.
  5. More custom Python code to run "Goodness of Fit" against the results and spit out a spreadsheet with the results. I have attached a couple of good and bad results graphs for your viewing pleasure.
From end to end, including cool down time for the solenoid (I went cheap so it tends to overheat as I did not get an always-on solenoid. Too expensive.) the entire process takes about an hour.
The rolling rig is mostly 3d printed custom parts, but the dome is what makes the whole thing work. It is a microscope light that allows for fine-tuning of light that is very soft. Metal dice were my test dice of choice and they are so shiny I had to mute the light a great deal to prevent blinding the camera. You have to tweak it between dice of different colors, but it does work quite well.
Struggles with the setup included learning about flyback on the solenoid and how that will fry the mosfet. Once I got a diode in the circuit it went much better.
The major issue was training the machine learning system to recognize the die faces. I had to feed the system 25,000 tagged images from the machine so it could identify the faces. Luckily it really only took a few thousand to bootstrap the system and then as I fed it more images, it got more accurate. Still, I had to manually check each image to make sure it is accurate. I know there are data sets of d20s on the Internet, but they did not work because I strip the images down to black and white and the images I collect are a bit unusual due to the lighting conditions. I basically created an image recognition system that only works with this rig, lighting and camera. Hence the amount of work. Probably not a great idea, but it is up to 99% accuracy.
I learned a great deal from the project, both hardware and software. That said, I mostly learned that dice companies lie. They market sharp edged, precision edged, cnc-milled, liquid filled, metal dice as better than cheap-ass plastic dice beat to death in a tumbling machine you buy by the pound at conventions. It does not matter. Some passed, some failed. Cost did not mean anything. Manufacturer did not matter. I had expensive metal dice with laser cut, anodized numbers fail and, this still annoys me, the best die I ever found was a 10 cent die from a bulk bin at Gencon. It scored nearly perfect. Overall about 30% of the dice fell outside the P-value I used (.05) and were destroyed.
Was all this work necessary? Probably not. In fact I had more than a few gamers tell me they do not really care if the dice are "fair." On a personal level I believe that the dice should be reasonably fair, otherwise constant failure or success will negatively impact a game.
Anyway, just wanted to share a somewhat odd project I have been tinkering with.

Fortuna in all her glory
The rolling cup.

A good die

A bad die. A very bad die.


submitted by /u/vicpylon
[link] [comments]

More...
Post Reply

Return to “Raspberry Pi Forum”