49714 Programming for Online Prototypes
· 9 members
A hands on introduction to building online products and services through code
The intent of this project was to create a zero-UI application building off of the rest of the course material for 49-714 Programming for Online Prototypes. For this project, I made an SMS-based bot that can play Mastermind via text. As the cover picture indicates, the intent is to provide additional functionality such as tic-tac-toe, chess, or other games. The bot has a bit of personality and cheesy dialogue to support it calling itself "GameTron Automaton 4000."
This bot was used to practice programming in Ruby, as well as to gain familiarity with Sinatra, Heroku, ad Twilio to create web services that others can use. While this bot has limited functionality at this time, it is still intended to be a fun distraction for students.
1.) https://github.com/zottwickel/Mastermind This is a simple project where the computer picks a color and the user tries to guess it. Because the code has a length of one, the evaluation does not have a function for determining if an element is correct but in the wrong order.
2.) https://github.com/JonathanYiv/mastermind This is a more exhaustive and robust version of the first precedent and even uses the gem “colorize” to provide colored output in the command line.
3.) https://github.com/SadieD/oop_with_ruby/tree/master/mastermind this version works with numbers from 1-6 instead of colors.
I started by mapping out what I wanted the bot to do, shown in the diagram below. I later decided that since I had to add numbers on the Twilio website to verify them anyway, there wasn't much benefit to including a signup process, even if I had the code from an earlier project a few weeks prior. The sign-up screen would probably benefit from some formatting anyway, and then I wouldn't have a zero-UI project.
After exploring some technical precedents, I began reverse-engineering Jonathan Yiv's command-line version of Mastermind (starting point #2 above) to figure out how it worked and to simplify it so that when it came time to test it, I wouldn't have to play the entire game to see if it was working.
A lot of the functionality ended up being incompatible with my design philosophy of using this in an SMS setting. Having a computer make guesses is fine for iterating within a command line interface but would likely annoy users on their phones. Also, the colored output in the command line is great, but without a way to change the font color of a text message or a consistent spacing compatible with every phone, I had to omit this feature in the SMS version. Still, I kept the command line interface output in the code to help with testing things locally.
Originally, I was planning on putting sequences of four colors from a wider palette back into the game. Feedback from users indicated that they were more concerned about the bot's personality, some confusing responses and instructions, and general "quality of life" improvements such as interpreting emoji and using abbreviations rather than requiring colors typed out in full. Instead of putting more colors in, which was easy enough to do at this point, or generalizing the length of the secret code or the the number of turns in the game, I chose to focus on providing more conversational responses than I had intended when I completed a "Bot Personality" activity earlier in the design process.
There were some challenges in understanding the starting point in GitHub, as well as translating it to an SMS-compatible program by implementing Twilio. Credit goes to Daragh Byrne for suggesting the use of session variables to store information about the game, which made retrieving the information a lot easier. I was worried that I would have to use a bunch of flags to determine how far the user was into a game, which would have been cumbersome to keep track of while debugging.
The current product is capable of playing Mastermind by selecting two colors from a palette of five. The colors can be repeated, although this is toggled in the code by commenting the following lines:
# keep picking colors until one that is not already within "selected_colors" has been picked
random = color_spectrum.sample
The user has twelve guesses, and can enter them by typing out the name of the colors or by using single-letter abbreviations or colored heart emoji. The bot can provide up to two hints per game, and has special messages if it's about to win or if the user guesses the correct code within two turns. It keeps track of the user's best score and doesn't like when the user sends it the poo emoji.
Some of these are results or messages that most users might not see in normal play and it isn't worth the conversational awkwardness to have the bot announce that it can do such things prior to playing the game. Rather, it is better for the user to appreciate the functionality when such cases arise. Other than the instructions and the game over responses, I wanted to keep the text length short, in case the user would want to scroll up to look at previous guesses. A video of the solution is shown below:
NOTE: After clicking on the video, expand it by clicking in the upper-right corner. Otherwise, half of the screen will be cut off.
In the future, I might recommend some functional improvements, such as adding more colors, more personality, and maybe more support for things like emoji (special response dialogue for emoji-only mode, or representing the results with a certain number of hint emoji rather than "You have 1 color in the wrong spot"). Maybe further down the line, a two-player version would allow one person to select a code for another. I think the most appreciated thing would be being able to handle guesses more smoothly, either with or without spaces, with commas, or with other spelling corrections. The emoji menu on an iPhone, for example, doesn't have a space bar, so users have to switch back to the regular keyboard just to insert the space.
There are advantages and disadvantages to turning games like Mastermind into zero-UI interfaces. On one hand, it doesn't require any command line knowledge or programming knowledge like the GitHub precedents did. On the other hand, it can be fun to play with the physical pieces of the game, or to see the actual board which can be simulated in the command line but doesn't appear in texts. The lack of SMS font color variability and the varying space in message screens made this impossible to do, but maybe a future student will find a clever way to do this.
Finally, thanks to Daragh Byrne for providing the code for interacting with Twilio via message and media and helping to debug the code to work with the existing methods provided by Jonathan Yiv (https://github.com/JonathanYiv/mastermind). It was fun to work on implementing an old game in a new way.