If you’re reading this article, you’re wasting valuable time that could be spent building robots, in ruby, that battle each other to the death. I can hear you already: “Does such a thing actually exist??” Well no, not really. But there are two consolation prizes:
- it will exist in the very near future, and
- until it does, I’ve created a simplified version to whet your appetite.
“Rubots” is the word you use when you’re referring to Ruby Robots but don’t want to waste precious rubot-coding time pronouncing the full phrase. My goal is simple: to create Ruby-based games where you can code your own player classes to battle against the sample players provided, other players you’ve created, or for the most fun: players created by your Rubyist friends!
The popularity of Rails has brought many people to the Ruby camp. Sadly, many of these people don’t learn how to code Ruby outside of the Rails environment. I got my start through Rails, and there were times I wasn’t sure where one ends and the other begins. I want to get programmers comfortable coding pure Ruby, and there’s no better way than the promise of digital violence.
My first iteration of this concept is a Rubot implementation of the classic game theory exercise, Prisoner’s Dilemma. The gist is that you’re one of two prisoners who have been placed in separate rooms and questioned by the authorities for a crime. You have to decide whether to cooperate with your partner in crime by not saying anything, or betray them by cutting a deal. There are different rewards/consequences based on how each of the two players decides to act.
You can download it here:
The README is pretty comprehensive, so I won’t rehash all of it here. The basic idea is that you create player classes that decide whether to cooperate with, or betray, their opponents. The game is played in multiple turns, so you can base your decision on how you and your opponent have behaved in previous turns, or any other criteria you want to consider. Maybe your prisoner gets grumpy around nap time, and from 2-4pm it only betrays its opponent :)
This is meant to be played tournament style, and so I’ve included a basic round-robin script that loads all player classes in the project directory and pits them against each other in a battle royale. This is a great activity for Ruby groups, especially among beginners. Player classes inherit from a prefabbed parent class, and simple strategies can be implemented with even a basic understanding of the language.
Enjoy, and please provide feedback. This will be the first of (hopefully) many games offered in this same style. Rubots unite!