The whole concept for a game came to me this summer while learning Processing from Daniel Schiffman’s YouTube course called The Coding Train. My game uses the random Walker code that Schiffman wrote as a sort of chance element to decide the fate of each player. I originally wrote the the game in Processing (code here) but had to port it over to p5.js later down the line.
The porting process from Processing to p5 was difficult regarding the way each deal with objects and classes. The norms are quite different and as often times in code there are a few different ways to go about it. I ended up removing much of the class language and making discreet functions and variables to simplify things. Here is a link to my final p5 sketch.
I wanted to use the dice rolling as sort of an extra “real world” layer so that you could weight the Walker to go in a certain direction - an idea that was floated in Schiffman’s original examples. I liked the idea that one had some control over the randomness, sort of like Black Jack at a casino. (I am quite the optimist when it comes to my chances when gambling, for the worse sometimes…).
So to get the dice data into my sketch, I first tried to use machine learning and image classification and a web cam. I recently attended a talk that Google employee Irene Alvarado had recently given at ITP’s Machine Learning meet up. She showed us Google’s Teachable Machine Boilerplate which I saw might fit my purposes. I took that code and tried to train it to learn what each possible combination of dice looked like (code here), but I had no way to save the model that I had trained. It would lose all the data if I refreshed the browser. So I set up a meeting with ITP Faculty Yining Shi who encouraged me to check out ml5’s image classifier in p5. This ended up being a simpler option as Dan Schiffman has a great video on how to save a model once you’ve trained it.
Now, I was able to save and load the model with no issues, however… image classification was not the best option for recognizing dice as each dice does not significantly change the amount of pixels in relation to the whole picture. Image classification models work better when the photos are significantly different from one another, as opposed to a picture with only a handful of pixel difference, like a dice roll of 2 or 3…
Luckily, I found a p5 blob detection sketch online which, with a lot of help from Yining, I was able to adapt for my purposes. We tweaked the sketch to look only for black blobs and I made the game board with no black portions, which I discovered was necessary after much trial and error.
Here are some videos of me explaining how the game itself works and how I calibrated the blob detection.
A Walker, Texas Ranger-themed board game using blob detection in p5.js to detect a pair of dice. This was a final project for Intro To Computational Media at NYU's ITP masters program.