repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_005.rb | towers/intermediate/level_005.rb | # -----
# | S|
# |@> SC|
# -----
description "You can feel the stairs right next to you, but are you sure you want to go up them right away?"
tip "You'll get more points for clearing the level first. Use warrior.feel.stairs? and warrior.feel.empty? to determine where to go."
clue "If going towards a unit is the s... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_002.rb | towers/intermediate/level_002.rb | # ----
# |@s |
# | sS>|
# ----
description "Another large room, but with several enemies blocking your way to the stairs."
tip "Just like walking, you can attack! and feel in multiple directions (:forward, :left, :right, :backward)."
clue "Call warrior.feel(direction).enemy? in each direction to make sure there isn... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_008.rb | towers/intermediate/level_008.rb | # -------
# |@ Ss C>|
# -------
description "You discover a satchel of bombs which will help when facing a mob of enemies."
tip "Detonate a bomb when you see a couple enemies ahead of you (warrior.look). Watch out for your health too."
clue "Calling warrior.look will return an array of Spaces. If the first two conta... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_006.rb | towers/intermediate/level_006.rb | # ------
# |Cs >|
# |@ sC |
# ------
description "What's that ticking? Some captives have a timed bomb at their feet!"
tip "Hurry and rescue captives first that have space.ticking?, they'll soon go!"
clue "Avoid fighting enemies at first. Use warrior.listen and space.ticking? and quickly rescue those captives."
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_004.rb | towers/intermediate/level_004.rb | # ----
# |C s |
# | @ S|
# |C s>|
# ----
description "Your ears become more in tune with the surroundings. Listen to find enemies and captives!"
tip "Use warrior.listen to find spaces with other units, and warrior.direction_of to determine what direction they're in."
clue "Walk towards an enemy or captive with warri... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_007.rb | towers/intermediate/level_007.rb | # -----
# | sC >|
# |@ s C|
# | s |
# -----
description "Another ticking sound, but some sludge is blocking the way."
tip "Quickly kill the sludge and rescue the captive before the bomb goes off. You can't simply go around them."
clue "Determine the direction of the ticking captive and kill any enemies blocking th... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_003.rb | towers/intermediate/level_003.rb | # ---
# |>s |
# |s@s|
# | C |
# ---
description "You feel slime on all sides, you're surrounded!"
tip "Call warrior.bind!(direction) to bind an enemy to keep him from attacking. Bound enemies look like captives."
clue "Count the number of enemies around you. Bind an enemy if there are two or more."
time_bonus 50
ac... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_001.rb | towers/intermediate/level_001.rb | # ------
# | |
# |@ |
# | |
# | > |
# ------
description "Silence. The room feels large, but empty. Luckily you have a map of this tower to help find the stairs."
tip "Use warrior.direction_of_stairs to determine which direction stairs are located. Pass this to warrior.walk! to walk in that directio... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/intermediate/level_009.rb | towers/intermediate/level_009.rb | # ----
# |ssC>|
# |@sss|
# |ssC |
# ----
description "Never before have you seen a room so full of sludge. Start the fireworks!"
tip "Be careful not to let the ticking captive get caught in the flames. Use warrior.distance_of to avoid the captives."
clue "Be sure to bind the surrounding enemies before fighting. Chec... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_005.rb | towers/beginner/level_005.rb | # -------
# |@ CaaSC|
# -------
description "You hear cries for help. Captives must need rescuing."
tip "Use warrior.feel.captive? to see if there is a captive and warrior.rescue! to rescue him. Don't attack captives."
clue "Don't forget to constantly check if you're taking damage. Rest until your health is full if ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_002.rb | towers/beginner/level_002.rb | # --------
# |@ s >|
# --------
description "It is too dark to see anything, but you smell sludge nearby."
tip "Use warrior.feel.empty? to see if there is anything in front of you, and warrior.attack! to fight it. Remember, you can only do one action (ending in !) per turn."
clue "Add an if/else condition using w... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_008.rb | towers/beginner/level_008.rb | # -------
# |@ Cww>|
# -------
description "You hear the mumbling of wizards. Beware of their deadly wands! Good thing you found a bow."
tip "Use warrior.look to determine your surroundings, and warrior.shoot! to fire an arrow."
clue "Wizards are deadly but low in health. Kill them before they have time to attack."... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_006.rb | towers/beginner/level_006.rb | # --------
# |C @ S aa|
# --------
description "The wall behind you feels a bit further away in this room. And you hear more cries for help."
tip "You can walk backward by passing ':backward' as an argument to walk!. Same goes for feel, rescue! and attack!. Archers have a limited attack distance."
clue "Walk backwar... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_004.rb | towers/beginner/level_004.rb | # -------
# |@ Sa S>|
# -------
description "You can hear bow strings being stretched."
tip "No new abilities this time, but you must be careful not to rest while taking damage. Save a @health instance variable and compare it on each turn to see if you're taking damage."
clue "Set @health to your current health at t... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_007.rb | towers/beginner/level_007.rb | # ------
# |>a S @|
# ------
description "You feel a wall right in front of you and an opening behind you."
tip "You are not as effective at attacking backward. Use warrior.feel.wall? and warrior.pivot! to turn around."
time_bonus 30
ace_score 50
size 6, 1
stairs 0, 0
warrior 5, 0, :east do |u|
u.add_abilities :... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_003.rb | towers/beginner/level_003.rb | # ---------
# |@ s ss s>|
# ---------
description "The air feels thicker than before. There must be a horde of sludge."
tip "Be careful not to die! Use warrior.health to keep an eye on your health, and warrior.rest! to earn 10% of max health back."
clue "When there is no enemy ahead of you call warrior.rest! until h... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_001.rb | towers/beginner/level_001.rb | # --------
# |@ >|
# --------
description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
time_bonus 15
ace_score 10
size 8, 1
stairs 7, 0
warrior 0, 0, :east do |u|
u.add_abilities :walk... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/towers/beginner/level_009.rb | towers/beginner/level_009.rb | # -----------
# |>Ca @ S wC|
# -----------
description "Time to hone your skills and apply all of the abilities that you have learned."
tip "Watch your back."
clue "Don't just keep shooting the bow while you are being attacked from behind."
time_bonus 40
ace_score 100
size 11, 1
stairs 0, 0
warrior 5, 0, :east
u... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/features/support/env.rb | features/support/env.rb | require "cucumber"
require "rspec"
require File.dirname(__FILE__) + "/../../lib/ruby_warrior"
Before { RubyWarrior::Config.reset }
After { FileUtils.rm_rf "towers/short" }
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/features/support/mockio.rb | features/support/mockio.rb | class MockIO
class Timeout < Exception
end
def initialize(receiver = nil)
@buffer = ""
@receiver = receiver || MockIO.new(self)
end
def gets
1000.times do |n|
sleep 0.01 if n > 800 # throttle if it seems to be taking a while
unless @buffer.empty?
content = @buffer
@bu... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/features/step_definitions/common_steps.rb | features/step_definitions/common_steps.rb | Given /^a directory at "([^\"]*)"$/ do |path|
Dir.mkdir(path) unless File.exist? path
end
Given /^no directory at "([^\"]*)"$/ do |path|
Dir.rmdir(path) if File.exist? path
end
When /^I copy fixture "([^\"]*)" to "([^\"]*)"$/ do |from, to|
FileUtils.cp_r("spec/fixtures/" + from, to)
end
Then /^I should find fi... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/features/step_definitions/interaction_steps.rb | features/step_definitions/interaction_steps.rb | Given /^a profile named "([^\"]*)" on "([^\"]*)"$/ do |name, tower|
step "I run rubywarrior"
step 'I answer "y" to "create one?"'
step 'I choose "' + tower + '" for "tower"'
step 'I answer "' + name + '" to "name"'
step 'I should see "generated"'
end
Given /^no profile at "([^\"]*)"$/ do |path|
RubyWarrior... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/spec_helper.rb | spec/spec_helper.rb | require "rubygems"
require "rspec"
require File.dirname(__FILE__) + "/../lib/ruby_warrior"
RSpec.configure do |config|
config.before(:each) { RubyWarrior::Config.reset }
config.raise_errors_for_deprecations!
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/fixtures/walking_player.rb | spec/fixtures/walking_player.rb | class Player
def play_turn(warrior)
warrior.walk!
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/fixtures/short-tower/level_002.rb | spec/fixtures/short-tower/level_002.rb | # --
# |@>|
# --
description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
time_bonus 15
ace_score 17
size 2, 1
stairs 1, 0
warrior 0, 0, :east do |u|
u.add_abilities :walk!
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/fixtures/short-tower/level_001.rb | spec/fixtures/short-tower/level_001.rb | # --
# |@>|
# --
description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
time_bonus 15
ace_score 17
size 2, 1
stairs 1, 0
warrior 0, 0, :east do |u|
u.add_abilities :walk!
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/turn_spec.rb | spec/ruby_warrior/turn_spec.rb | require "spec_helper"
describe RubyWarrior::Turn do
describe "with actions" do
before(:each) { @turn = RubyWarrior::Turn.new({ walk!: nil, attack!: nil }) }
it "should have no action performed at first" do
expect(@turn.action).to be_nil
end
it "should be able to perform action and recall it" ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/floor_spec.rb | spec/ruby_warrior/floor_spec.rb | require "spec_helper"
describe RubyWarrior::Floor do
describe "2x3" do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 2
@floor.height = 3
end
it "should be able to add a unit and fetch it at that position" do
unit = RubyWarrior::Units::Base.new
@floor.add(u... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/space_spec.rb | spec/ruby_warrior/space_spec.rb | require "spec_helper"
describe RubyWarrior::Space do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 2
@floor.height = 3
end
describe "with empty space" do
before(:each) { @space = @floor.space(0, 0) }
it "should not be enemy" do
expect(@space).to_not be_enemy
end
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/position_spec.rb | spec/ruby_warrior/position_spec.rb | require "spec_helper"
describe RubyWarrior::Position do
before(:each) do
@unit = RubyWarrior::Units::Base.new
@floor = RubyWarrior::Floor.new
@floor.width = 6
@floor.height = 5
@floor.add(@unit, 1, 2, :north)
@position = @unit.position
end
it "should rotate clockwise" do
expect(@posi... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/ui_spec.rb | spec/ruby_warrior/ui_spec.rb | require "spec_helper"
describe RubyWarrior::UI do
before(:each) do
@ui = RubyWarrior::UI
@config = RubyWarrior::Config
@out = StringIO.new
@in = StringIO.new
@config.out_stream = @out
@config.in_stream = @in
end
it "should add puts to out stream" do
@ui.puts "hello"
expect(@out.s... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/core_additions_spec.rb | spec/ruby_warrior/core_additions_spec.rb | require "spec_helper"
describe String do
it "should wrap text at white space when over a specific character length" do
expect("foo bar blah".hard_wrap(10)).to eq("foo bar\nblah")
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/player_generator_spec.rb | spec/ruby_warrior/player_generator_spec.rb | require "spec_helper"
describe RubyWarrior::PlayerGenerator do
before(:each) do
@level = RubyWarrior::Level.new(RubyWarrior::Profile.new, 15)
@generator = RubyWarrior::PlayerGenerator.new(@level)
end
it "should know templates path" do
expect(@generator.templates_path).to eq(File.expand_path("../../.... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/game_spec.rb | spec/ruby_warrior/game_spec.rb | require "spec_helper"
describe RubyWarrior::Game do
before(:each) { @game = RubyWarrior::Game.new }
# GAME DIR
it "should make game directory if player says so" do
allow(RubyWarrior::UI).to receive(:ask).and_return(true)
expect(Dir).to receive(:mkdir).with("./rubywarrior")
@game.make_game_directory... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/level_spec.rb | spec/ruby_warrior/level_spec.rb | require "spec_helper"
require "set"
describe RubyWarrior::Level do
before(:each) do
@profile = RubyWarrior::Profile.new
@floor = RubyWarrior::Floor.new
@level = RubyWarrior::Level.new(@profile, 1)
@level.floor = @floor
allow(@level).to receive(:failed?).and_return(false)
end
it "should consi... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/profile_spec.rb | spec/ruby_warrior/profile_spec.rb | require "spec_helper"
describe RubyWarrior::Profile do
before(:each) { @profile = RubyWarrior::Profile.new }
it "should have warrior name" do
@profile.warrior_name = "Joe"
expect(@profile.warrior_name).to eq("Joe")
end
it "should start level number at 0" do
expect(@profile.level_number).to be_zer... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/tower_spec.rb | spec/ruby_warrior/tower_spec.rb | require "spec_helper"
describe RubyWarrior::Tower do
before(:each) { @tower = RubyWarrior::Tower.new("path/to/tower") }
it "should consider last part of path as name" do
expect(@tower.name).to eq("tower")
end
it "should use name when converting to string" do
expect(@tower.to_s).to eq(@tower.name)
e... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/level_loader_spec.rb | spec/ruby_warrior/level_loader_spec.rb | require "spec_helper"
describe RubyWarrior::LevelLoader do
describe "with profile" do
before(:each) do
@profile = RubyWarrior::Profile.new
@level = RubyWarrior::Level.new(@profile, 1)
@loader = RubyWarrior::LevelLoader.new(@level)
end
it "should be able to add description, tip and clue... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/form_spec.rb | spec/ruby_warrior/abilities/form_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Form do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 2
@floor.height = 3
@warrior = RubyWarrior::Units::Warrior.new
@floor.add(@warrior, 0, 0, :east)
@form = RubyWarrior::Abilities::Form.new(@warrior)
end
it "shoul... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/walk_spec.rb | spec/ruby_warrior/abilities/walk_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Walk do
before(:each) do
@space = double(empty?: true, unit: nil)
@position = double(relative_space: @space, move: nil)
@walk = RubyWarrior::Abilities::Walk.new(double(position: @position, say: nil))
end
it "should move position forward when cal... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb | spec/ruby_warrior/abilities/direction_of_stairs_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::DirectionOfStairs do
before(:each) do
@position = double
@distance = RubyWarrior::Abilities::DirectionOfStairs.new(double(position: @position, say: nil))
end
it "should return relative direction of stairs" do
allow(@position).to receive(:relativ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/direction_of_spec.rb | spec/ruby_warrior/abilities/direction_of_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::DirectionOf do
before(:each) do
@position = double
@distance = RubyWarrior::Abilities::DirectionOf.new(double(position: @position, say: nil))
end
it "should return relative direction of given space" do
allow(@position).to receive(:relative_direc... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/listen_spec.rb | spec/ruby_warrior/abilities/listen_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Listen do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 2
@floor.height = 3
@warrior = RubyWarrior::Units::Warrior.new
@floor.add(@warrior, 0, 0)
@listen = RubyWarrior::Abilities::Listen.new(@warrior)
end
it "should... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/rescue_spec.rb | spec/ruby_warrior/abilities/rescue_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Rescue do
before(:each) do
@warrior = RubyWarrior::Units::Warrior.new
@rescue = RubyWarrior::Abilities::Rescue.new(@warrior)
end
it "should rescue captive" do
captive = RubyWarrior::Units::Captive.new
captive.position = double
expect(@re... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/feel_spec.rb | spec/ruby_warrior/abilities/feel_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Feel do
before(:each) do
@unit = double(position: double, say: nil)
@feel = RubyWarrior::Abilities::Feel.new(@unit)
end
it "should get object at position from offset" do
expect(@unit.position).to receive(:relative_space).with(1, 0)
@feel.per... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/pivot_spec.rb | spec/ruby_warrior/abilities/pivot_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Pivot do
before(:each) do
@position = double
@pivot = RubyWarrior::Abilities::Pivot.new(double(position: @position, say: nil))
end
it "should flip around when not passing arguments" do
expect(@position).to receive(:rotate).with(2)
@pivot.per... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/distance_of_spec.rb | spec/ruby_warrior/abilities/distance_of_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::DistanceOf do
before(:each) do
@position = double
@distance = RubyWarrior::Abilities::DistanceOf.new(double(position: @position, say: nil))
end
it "should return distance from stairs" do
allow(@position).to receive(:distance_of).with(:space).and... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/rest_spec.rb | spec/ruby_warrior/abilities/rest_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Rest do
before(:each) do
@warrior = RubyWarrior::Units::Warrior.new
@rest = RubyWarrior::Abilities::Rest.new(@warrior)
end
it "should give 10% health back" do
allow(@warrior).to receive(:max_health).and_return(20)
@warrior.health = 10
@r... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/bind_spec.rb | spec/ruby_warrior/abilities/bind_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Bind do
before(:each) { @bind = RubyWarrior::Abilities::Bind.new(double(say: nil)) }
it "should bind recipient" do
receiver = RubyWarrior::Units::Base.new
allow(@bind).to receive(:unit).and_return(receiver)
@bind.perform
expect(receiver).to be... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/base_spec.rb | spec/ruby_warrior/abilities/base_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Base do
before(:each) do
@unit = double
@ability = RubyWarrior::Abilities::Base.new(@unit)
end
it "should have offset for directions" do
expect(@ability.offset(:forward)).to eq([1, 0])
expect(@ability.offset(:right)).to eq([0, 1])
expect... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/health_spec.rb | spec/ruby_warrior/abilities/health_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Health do
before(:each) do
@warrior = RubyWarrior::Units::Warrior.new
@health = RubyWarrior::Abilities::Health.new(@warrior)
end
it "should return the amount of health" do
@warrior.health = 10
expect(@health.perform).to eq(10)
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/attack_spec.rb | spec/ruby_warrior/abilities/attack_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Attack do
before(:each) do
@attacker = double(position: double, attack_power: 3, say: nil)
@attack = RubyWarrior::Abilities::Attack.new(@attacker)
end
it "should subtract attack power amount from health" do
receiver = RubyWarrior::Units::Base.ne... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/explode_spec.rb | spec/ruby_warrior/abilities/explode_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Explode do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 2
@floor.height = 3
@captive = RubyWarrior::Units::Captive.new
@floor.add(@captive, 0, 0)
@explode = RubyWarrior::Abilities::Explode.new(@captive)
end
it "sho... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/throw_spec.rb | spec/ruby_warrior/abilities/throw_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Detonate do
before(:each) do
@floor = RubyWarrior::Floor.new
@floor.width = 3
@floor.height = 3
@warrior = RubyWarrior::Units::Warrior.new
@floor.add(@warrior, 0, 0, :south)
@detonate = RubyWarrior::Abilities::Detonate.new(@warrior)
end... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/look_spec.rb | spec/ruby_warrior/abilities/look_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Look do
before(:each) do
@unit = double(position: double, say: nil)
@feel = RubyWarrior::Abilities::Look.new(@unit)
end
it "should get 3 objects at position from offset" do
expect(@unit.position).to receive(:relative_space).with(1, 0).and_return... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/abilities/shoot_spec.rb | spec/ruby_warrior/abilities/shoot_spec.rb | require "spec_helper"
describe RubyWarrior::Abilities::Shoot do
before(:each) do
@shooter = double(position: double, shoot_power: 2, say: nil)
@shoot = RubyWarrior::Abilities::Shoot.new(@shooter)
end
it "should shoot only first unit" do
receiver = double(alive?: true)
expect(receiver).to receive... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/thick_sludge_spec.rb | spec/ruby_warrior/units/thick_sludge_spec.rb | require "spec_helper"
describe RubyWarrior::Units::ThickSludge do
before(:each) { @sludge = RubyWarrior::Units::ThickSludge.new }
it "should have 24 max health" do
expect(@sludge.max_health).to eq(24)
end
it "should appear as S on map" do
expect(@sludge.character).to eq("S")
end
it "should have ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/warrior_spec.rb | spec/ruby_warrior/units/warrior_spec.rb | require "spec_helper"
class Player
def turn(warrior)
end
end
describe RubyWarrior::Units::Warrior do
before(:each) { @warrior = RubyWarrior::Units::Warrior.new }
it "should default name to warrior" do
expect(@warrior.name).to eq("Warrior")
@warrior.name = ""
expect(@warrior.name).to eq("Warrior")... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/sludge_spec.rb | spec/ruby_warrior/units/sludge_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Sludge do
before(:each) { @sludge = RubyWarrior::Units::Sludge.new }
it "should have attack action" do
expect(@sludge.abilities.keys).to include(:attack!)
end
it "should have feel sense" do
expect(@sludge.abilities.keys).to include(:feel)
end
it... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/golem_spec.rb | spec/ruby_warrior/units/golem_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Golem do
before(:each) { @golem = RubyWarrior::Units::Golem.new }
it "should execute turn proc when playing turn" do
proc = Object.new
expect(proc).to receive(:call).with(:turn)
@golem.turn = proc
@golem.play_turn(:turn)
end
it "should set ma... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/base_spec.rb | spec/ruby_warrior/units/base_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Base do
before(:each) { @unit = RubyWarrior::Units::Base.new }
it "should have an attack power which defaults to zero" do
expect(@unit.attack_power).to be_zero
end
it "should consider itself dead when no position" do
expect(@unit.position).to be_nil
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/archer_spec.rb | spec/ruby_warrior/units/archer_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Archer do
before(:each) { @archer = RubyWarrior::Units::Archer.new }
it "should have look and shoot abilities" do
expect(@archer.abilities.keys.to_set).to eq(%i[shoot! look].to_set)
end
it "should have shoot power of 3" do
expect(@archer.shoot_power)... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/captive_spec.rb | spec/ruby_warrior/units/captive_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Captive do
before(:each) { @captive = RubyWarrior::Units::Captive.new }
it "should have 1 max health" do
expect(@captive.max_health).to eq(1)
end
it "should appear as C on map" do
expect(@captive.character).to eq("C")
end
it "should be bound by ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/spec/ruby_warrior/units/wizard_spec.rb | spec/ruby_warrior/units/wizard_spec.rb | require "spec_helper"
describe RubyWarrior::Units::Wizard do
before(:each) { @wizard = RubyWarrior::Units::Wizard.new }
it "should have look and shoot abilities" do
expect(@wizard.abilities.keys.to_set).to eq(%i[shoot! look].to_set)
end
it "should have shoot power of 11" do
expect(@wizard.shoot_power... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/templates/player.rb | templates/player.rb | class Player
def play_turn(warrior)
# add your code here
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior.rb | lib/ruby_warrior.rb | $: << File.dirname(__FILE__)
require "set"
require "ruby_warrior/core_additions"
require "ruby_warrior/runner"
require "ruby_warrior/game"
require "ruby_warrior/profile"
require "ruby_warrior/ui"
require "ruby_warrior/config"
require "ruby_warrior/player_generator"
require "ruby_warrior/level_loader"
require "ruby_w... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/level_loader.rb | lib/ruby_warrior/level_loader.rb | module RubyWarrior
class LevelLoader
def initialize(level)
@floor = RubyWarrior::Floor.new
@level = level
@level.floor = @floor
end
def description(desc)
@level.description = desc
end
def tip(tip)
@level.tip = tip
end
def clue(clue)
@level.clue = clue... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/ui.rb | lib/ruby_warrior/ui.rb | module RubyWarrior
class UI
class << self
def puts(msg)
Config.out_stream.puts(msg) if Config.out_stream
end
def puts_with_delay(msg)
result = puts(msg)
sleep(Config.delay) if Config.delay
result
end
def print(msg)
Config.out_stream.print(msg... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/game.rb | lib/ruby_warrior/game.rb | module RubyWarrior
class Game
def start
UI.puts "Welcome to Ruby Warrior"
if File.exist?(Config.path_prefix + "/.profile")
@profile = Profile.load(Config.path_prefix + "/.profile")
else
if File.exist?(Config.path_prefix + "/ruby-warrior")
FileUtils.mv(Config.path_prefi... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/core_additions.rb | lib/ruby_warrior/core_additions.rb | class String
def camelize
gsub(/(?:^|_)(.)/) { $1.upcase }
end
def constantize
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
Object.module_eval("::#{$1}", __FILE__, __LINE__)
end
def underscore
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/floor.rb | lib/ruby_warrior/floor.rb | module RubyWarrior
class Floor
attr_accessor :width, :height, :grid
attr_reader :stairs_location
def initialize
@width = 0
@height = 0
@units = []
@stairs_location = [-1, -1]
end
def add(unit, x, y, direction = nil)
@units << unit
unit.position = Position.new(... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/tower.rb | lib/ruby_warrior/tower.rb | module RubyWarrior
class Tower
attr_reader :path
def initialize(path)
@path = File.join(File.expand_path("../../../towers/", __FILE__), path)
end
def name
File.basename(path)
end
alias_method :to_s, :name
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/runner.rb | lib/ruby_warrior/runner.rb | require "optparse"
module RubyWarrior
class Runner
def initialize(arguments, stdin, stdout)
@arguments = arguments
@stdin = stdin
@stdout = stdout
@game = RubyWarrior::Game.new
end
def run
Config.in_stream = @stdin
Config.out_stream = @stdout
Config.delay = 0.6
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/position.rb | lib/ruby_warrior/position.rb | module RubyWarrior
class Position
attr_reader :floor
DIRECTIONS = %i[north east south west]
RELATIVE_DIRECTIONS = %i[forward right backward left]
def initialize(floor, x, y, direction = nil)
@floor = floor
@x = x
@y = y
@direction_index = DIRECTIONS.index(direction || :north)
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/config.rb | lib/ruby_warrior/config.rb | module RubyWarrior
class Config
class << self
attr_accessor :delay, :in_stream, :out_stream, :practice_level
attr_writer :path_prefix, :skip_input
def path_prefix
@path_prefix || "."
end
def skip_input?
@skip_input
end
def reset
%i[@path_prefix ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/profile.rb | lib/ruby_warrior/profile.rb | require "base64"
module RubyWarrior
class Profile
attr_accessor :score,
:epic_score,
:current_epic_score,
:average_grade,
:current_epic_grades,
:abilities,
:level_number,
:last_level_numb... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/level.rb | lib/ruby_warrior/level.rb | module RubyWarrior
class Level
attr_reader :profile, :number
attr_accessor :description, :tip, :clue, :warrior, :floor, :time_bonus, :ace_score
def self.grade_letter(percent)
if percent >= 1.0
"S"
elsif percent >= 0.9
"A"
elsif percent >= 0.8
"B"
elsif perc... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/space.rb | lib/ruby_warrior/space.rb | module RubyWarrior
class Space
def initialize(floor, x, y)
@floor, @x, @y = floor, x, y
end
def wall?
@floor.out_of_bounds? @x, @y
end
def warrior?
unit.kind_of? Units::Warrior
end
def golem?
unit.kind_of? Units::Golem
end
def player?
warrior? || g... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/player_generator.rb | lib/ruby_warrior/player_generator.rb | require "rubygems"
require "fileutils"
require "erb"
module RubyWarrior
class PlayerGenerator
def initialize(level)
@level = level
end
def level
@level
end
def previous_level
@previous_level ||= Level.new(level.profile, level.number - 1)
end
# TODO refactor and test t... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/turn.rb | lib/ruby_warrior/turn.rb | module RubyWarrior
class Turn
attr_reader :action
def initialize(abilities)
@action = nil
@senses = {}
abilities.each do |name, sense|
if name.to_s =~ /\!$/
add_action(name)
else
add_sense(name, sense)
end
end
end
private
def ... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/distance_of.rb | lib/ruby_warrior/abilities/distance_of.rb | module RubyWarrior
module Abilities
class DistanceOf < Base
def description
"Pass a Space as an argument, and it will return an integer representing the distance to that space."
end
def perform(space)
@unit.position.distance_of(space)
end
end
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/direction_of_stairs.rb | lib/ruby_warrior/abilities/direction_of_stairs.rb | module RubyWarrior
module Abilities
class DirectionOfStairs < Base
def description
"Returns the direction (:left, :right, :forward, :backward) the stairs are from your location."
end
def perform
@unit.position.relative_direction_of_stairs
end
end
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/explode.rb | lib/ruby_warrior/abilities/explode.rb | module RubyWarrior
module Abilities
class Explode < Base
attr_accessor :time
def description
"Kills you and all surrounding units. You probably don't want to do this intentionally."
end
def perform
if @unit.position
@unit.say "explodes, collapsing the ceiling an... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/listen.rb | lib/ruby_warrior/abilities/listen.rb | module RubyWarrior
module Abilities
class Listen < Base
def description
"Returns an array of all spaces which have units in them."
end
def perform
@unit.position.floor.units.map { |unit| unit.position.space unless unit == @unit }.compact
end
end
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/form.rb | lib/ruby_warrior/abilities/form.rb | module RubyWarrior
module Abilities
class Form < Base
def description
"Forms a golem in given direction taking half of invoker's health. The passed block is executed for each golem turn."
end
def perform(direction = :forward, &block)
verify_direction(direction)
if space(... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/pivot.rb | lib/ruby_warrior/abilities/pivot.rb | module RubyWarrior
module Abilities
class Pivot < Base
ROTATION_DIRECTIONS = %i[forward right backward left]
def description
"Rotate :left, :right or :backward (default)"
end
def perform(direction = :backward)
verify_direction(direction)
@unit.position.rotate(ROTA... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/rest.rb | lib/ruby_warrior/abilities/rest.rb | module RubyWarrior
module Abilities
class Rest < Base
def description
"Gain 10% of max health back, but do nothing more."
end
def perform
if @unit.health < @unit.max_health
amount = (@unit.max_health * 0.1).round
amount = @unit.max_health - @unit.health if (@... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/shoot.rb | lib/ruby_warrior/abilities/shoot.rb | module RubyWarrior
module Abilities
class Shoot < Base
def description
"Shoot your bow & arrow in given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
receiver = multi_unit(direction, 1..3).compact.first
if rece... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/base.rb | lib/ruby_warrior/abilities/base.rb | module RubyWarrior
module Abilities
class Base
def initialize(unit)
@unit = unit
end
def offset(direction, forward = 1, right = 0)
case direction
when :forward
[forward, -right]
when :backward
[-forward, right]
when :right
[r... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/feel.rb | lib/ruby_warrior/abilities/feel.rb | module RubyWarrior
module Abilities
class Feel < Base
def description
"Returns a Space for the given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
space(direction)
end
end
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/health.rb | lib/ruby_warrior/abilities/health.rb | module RubyWarrior
module Abilities
class Health < Base
def description
"Returns an integer representing your health."
end
def perform
@unit.health
end
end
end
end
| ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/bind.rb | lib/ruby_warrior/abilities/bind.rb | module RubyWarrior
module Abilities
class Bind < Base
def description
"Binds a unit in given direction to keep him from moving (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
receiver = unit(direction)
if receiver
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/attack.rb | lib/ruby_warrior/abilities/attack.rb | module RubyWarrior
module Abilities
class Attack < Base
def description
"Attacks a unit in given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
receiver = unit(direction)
if receiver
@unit.say "attacks... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/rescue.rb | lib/ruby_warrior/abilities/rescue.rb | module RubyWarrior
module Abilities
class Rescue < Base
def description
"Rescue a captive from his chains (earning 20 points) in given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
if space(direction).captive?
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/look.rb | lib/ruby_warrior/abilities/look.rb | module RubyWarrior
module Abilities
class Look < Base
def description
"Returns an array of up to three Spaces in the given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
[1, 2, 3].map { |amount| space(direction, amount)... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/direction_of.rb | lib/ruby_warrior/abilities/direction_of.rb | module RubyWarrior
module Abilities
class DirectionOf < Base
def description
"Pass a Space as an argument, and the direction (:left, :right, :forward, :backward) to that space will be returned."
end
def perform(space)
@unit.position.relative_direction_of(space)
end
end... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/walk.rb | lib/ruby_warrior/abilities/walk.rb | module RubyWarrior
module Abilities
class Walk < Base
def description
"Move in the given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
if @unit.position
@unit.say "walks #{direction}"
if space(direc... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/abilities/detonate.rb | lib/ruby_warrior/abilities/detonate.rb | module RubyWarrior
module Abilities
class Detonate < Base
def description
"Detonate a bomb in a given direction (forward by default) which damages that space and surrounding 4 spaces (including yourself)."
end
def perform(direction = :forward)
verify_direction(direction)
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/units/archer.rb | lib/ruby_warrior/units/archer.rb | module RubyWarrior
module Units
class Archer < Base
def initialize
add_abilities :shoot!, :look
end
def play_turn(turn)
%i[forward left right].each do |direction|
turn
.look(direction)
.each do |space|
if space.player?
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
ryanb/ruby-warrior | https://github.com/ryanb/ruby-warrior/blob/a062c16548d8629bd084ec275beac7f9ff6bcc85/lib/ruby_warrior/units/wizard.rb | lib/ruby_warrior/units/wizard.rb | module RubyWarrior
module Units
class Wizard < Base
def initialize
add_abilities :shoot!, :look
end
def play_turn(turn)
%i[forward left right].each do |direction|
turn
.look(direction)
.each do |space|
if space.player?
... | ruby | MIT | a062c16548d8629bd084ec275beac7f9ff6bcc85 | 2026-01-04T15:48:10.335348Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.