ruby-warrior: Learn Ruby by Writing an AI for a Tower-Climbing Game
GitHub describes it as Game written in Ruby for learning Ruby.. The repository metadata lists Ruby as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.
At a glance
- What is it?
- ruby-warrior is a command-line Ruby game where you program a warrior to climb a tower by writing a Ruby class. Each floor requires conditionals, state tracking, and method selection, making it a practical introduction to Ruby logic for beginners. The last push to the repository was on 2024-03-27.
- Who is it for?
- ruby-warrior is a good starting point for programmers who want to learn Ruby through concrete problems rather than exercises. Each floor forces you to write Ruby code that handles real conditionals, sense the environment, and maintain state across turns.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Probably not. The repository last received commits 30 months ago, on March 27, 2024.
- What is it written in?
- Mainly Ruby, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 1, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What ruby-warrior Is and Who It Targets
ruby-warrior is a game where the player writes Ruby code, not a game where the player plays with standard controls. You install the gem, initialize a profile, and then edit a single Ruby file called player.rb to instruct the warrior what to do on each turn. The README describes the goal as 'a game designed to teach the Ruby language in a fun and interactive way.' The audience is someone who knows enough Ruby to write a class with a method but has not yet worked with conditionals, state, or object method calls in a real program. The game forces you to learn by failing: if your warrior loses all health, you revise player.rb and try again. There is no feedback loop other than the game output. The gem runs from the command line using the rubywarrior command.
How the Turn-Based Game Loop Works
Each floor of the tower runs as a series of turns. On every turn, the game calls your play_turn method with a warrior object as the argument. You examine the warrior's surroundings with senses, choose an action, and the game advances one step. You cannot change your code during a level. The warrior must be given enough logic up front to survive whatever the floor contains. The README explains this design directly: 'You must give the Warrior enough artificial intelligence up-front to find his own way.' When the warrior reaches the stairs, the floor is complete. Losing all health fails the level. There is no penalty for failure beyond needing to fix the code and replay the level. The README's example of a simple warrior makes the loop concrete: call feel to sense the adjacent space, call enemy? on the space to check for an enemy, then call attack! or walk! based on the result.
Installing and Starting the Game
Installation uses the standard gem command:
gem install rubywarriorAfter installation, run the rubywarrior command to create a profile. This places a rubywarrior directory in the current working location with a profile subdirectory containing player.rb. The initial player.rb contains:
class Player
def play_turn(warrior)
# your code goes here
end
endFill in play_turn and run rubywarrior again to play the level. Each level's available abilities are listed in a README file inside the profile directory, updated automatically as levels advance. The README notes that as of version 0.2.0, the gem works with Ruby 3.3; if running an older Ruby version, an older gem version may be required.
Actions, Senses, and the Space API
Actions end with an exclamation mark and change the game state. Only one action can be taken per turn. The core actions from the README are: walk! (move in a direction, forward by default), attack! (attack the adjacent unit), rest! (recover 10% of max health), bind! (immobilize an adjacent unit), and rescue! (free a captive, earning 20 points). Senses return information without consuming the action. feel returns a Space object for the given direction. health returns an integer. distance returns the number of spaces to the stairs. listen returns an array of all spaces containing units. Space objects expose methods like empty?, stairs?, enemy?, captive?, wall?, ticking?, and golem?. The ticking? method detects a bomb. Because one turn only allows one action, handling multiple priorities (rescuing a captive while an enemy approaches from another direction) requires state management across turns. The README recommends recording sensed information to track changes between turns, such as detecting when health has decreased to infer an attack.
Scoring, Epic Mode, and Replay
Reaching the stairs is the minimum goal; maximizing score requires more. The README's scoring system awards points for defeating enemies (their max health added to your score), rescuing captives (20 points each), finishing within the bonus time (remaining bonus time added to score), and clearing the floor completely (a 20% overall bonus for defeating all enemies and rescuing all captives). A total score accumulates across all levels. After reaching the top of the tower, the player can re-run the entire tower in what the README calls Epic Mode, where the goal is to replay all levels and optimize the warrior's strategy for the highest total score. This replay loop encourages more careful programming than the first run, where just reaching the stairs on each level is sufficient. The README's advice is explicit: 'Don't be too concerned about scoring perfectly in the beginning.' The level map representation in the README shows the floor layout using ASCII characters where @ is the warrior, > is the stairs, s is a Sludge enemy, S is a Thick Sludge enemy, and C is a captive. Understanding the map format helps when planning how the warrior should handle each encounter.
The Golem: Controlling a Second Unit
Some levels unlock the ability to create a golem, a separate unit that the player also controls. The golem's turn logic is defined in a block:
warrior.form! do |golem|
golem.attack! if golem.feel.enemy?
endComplex golem logic can be moved into its own class. Multiple golems can be created per level, but the README notes a specific cost: each golem created takes half of the warrior's max health. Creating multiple golems is therefore a trade-off between having additional controlled units and reducing the warrior's survivability. The golem follows the same actions and senses API as the warrior, so skills learned for the warrior transfer directly. The Space API's golem? method lets the warrior detect whether a golem is occupying a given space, which matters when the warrior and golem need to coordinate movement on the floor.
Maintenance Status and Alternatives
The last push to the ruby-warrior repository was on 2024-03-27. The README notes that version 0.2.0 added Ruby 3.3 compatibility, so the gem runs on current Ruby. No new levels, features, or framework changes should be expected. The README itself has not been updated with new content; the tower structure (floors, enemies, captives, scoring rules) is fixed. For developers who want a similar concept with more active development, Exercism is an alternative: it offers Ruby tracks with practice exercises and community feedback, though it does not use the same game metaphor. CodinGame is another option for code-based games, supporting Ruby among many languages, though its exercises are not specifically Ruby tutorials. ruby-warrior's distinctive value is the single-file, turn-based simulation model that requires no external service.
Editorial conclusion
ruby-warrior is a good starting point for programmers who want to learn Ruby through concrete problems rather than exercises. Each floor forces you to write Ruby code that handles real conditionals, sense the environment, and maintain state across turns. The game has not had a commit since 2024-03-27. Version 0.2.0 added Ruby 3.3 support, according to the README. Expect no new levels or framework updates: this is a complete, self-contained learning artifact.
Frequently asked questions
What Ruby version does ruby-warrior support?
According to the README, version 0.2.0 of the gem added Ruby 3.3 support. If you have difficulty running it with an older version of Ruby, the README suggests trying an older version of the gem.
How many levels does ruby-warrior have?
The README does not document the total number of levels. The game structure adds new abilities and profile README content at each level, and the towers/ directory in the repository contains the level definitions, but the exact count is not stated in the available material.
Can ruby-warrior be extended with custom towers?
The repository includes a towers/ directory, which suggests the level structure is file-based. The README does not document a process for adding custom towers, and the gem's maintenance status (last push 2024-03-27) means no official guidance on this is expected.