Skip to content

Game written in Ruby for learning Ruby and artificial intelligence.

License

Notifications You must be signed in to change notification settings

severin/ruby-warrior

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Warrior

This is a game designed to teach the Ruby language and artificial intelligence in a fun, interactive way.

You play as a warrior climbing a tall tower to reach the precious Ruby at the top level. On each floor, you need to write a Ruby script to instruct the warrior how to get to the stairs. You have some idea of what each floor contains, but you never know for sure what will happen. You must give the Warrior enough artificial intelligence to find his own way.

Playing Turns

Once you run the “rubywarrior” command, it will create a ruby-warrior directory in your current directory. In here you will find a tower folder with a level folder inside. Open the player.rb file in there to edit your class. You should see something like this:

class Player
  def play_turn(warrior)
    # your code goes here
  end
end

Your objective is to fill this “play_turn” method with commands to instruct the warrior what to do. With each level your abilities will grow along with the difficulty. See the README for details on what abilities your warrior has available on the current level.

Here is a simple example which will instruct the warrior to attack if he feels an enemy, otherwise he will walk forward.

class Player
  def play_turn(warrior)
    if warrior.feel.enemy?
      warrior.attack!
    else
      warrior.walk!
    end
  end
end

Once you are done, save the file and run the “rubywarrior” command again to start playing the level. The play happens through a series of turns. On each one, your “play_turn” method is called along with the enemy’s. You cannot interact with it or change your code in the middle of a level. You must take into account everything that may happen on that level and give your warrior the proper instructions from the start.

Losing all of your health will cause you to fail the level. You are not punished by this, you simply need to go back to your class, improve your code, and try again.

Once you pass a level (by reaching the stairs), a new level folder will be created and your player files will be copied across. Remember to check out that level’s new README file to see what abilities you have.

Scoring

Your objective is to not only reach the goal, but to get the highest score you can. There are many ways you can earn points on a level.

  • defeat an enemy to add his max health to your score

  • rescue a captive to earn 20 points

  • pass the level within the bonus time to earn the amount of bonus time remaining

  • defeat all enemies and rescue all captives to receive a 20% overall bonus

A total score is kept as you progress through the levels. When you pass a level, that score is added to your total.

Perspective

Even though this is a text-based game, think of it as two-dimensional where you are viewing from overhead. Each level is always rectangular in shape and is made up of a number of squares. Only one unit can be on a given square, and your objective is to find the square with the stairs. Here is an example level map and key.

 ----
|C sC|
| S s|
|C>@ |
 ----

> = Stairs
@ = Warrior (20 HP)
s = Sludge (12 HP)
S = Thick Sludge (24 HP)
C = Captive (1 HP)

Commanding the Warrior

When you first start, your warrior will only have a few abilities, but with each level your abilities will grow. A warrior has two kinds of abilities: actions and senses.

An action is something that effects the game in some way. You can easily tell an action because it ends in an exclamation mark. Only one action can be performed per turn, so choose wisely. Here are some examples of actions.

warrior.walk!
  Move in given direction (forward by default).

warrior.attack!
  Attack the unit in given direction (forward by default).

warrior.rest!
  Gain 10% of max health back, but do nothing more.

warrior.bind!
  Bind unit in given direction to keep him from moving (forward by default).

warrior.rescue!
  Rescue a captive from his chains (earning 50 points) in given direction (forward by default).

A sense is something which gathers information about the floor. You can perform senses as often as you want per turn to gather information about your surroundings to aid you in choosing the proper action. Senses do NOT end in an exclamation mark.

warrior.feel
  Returns a Space for the given direction (forward by default).

warrior.health
  Returns an integer representing your health.

warrior.distance
  Returns the number of spaces the stairs are away.

warrior.listen
  Returns an array of all spaces which have units in them.

Since what you sense will change each turn, you should record what information you gather to use on the next turn. This way, for example, you can determine which direction an enemy is moving, or if you are losing health.

Spaces

Whenever you sense an area, often one space or multiple spaces (in an array) will be returned. A space is an object representing a square in the level. You can call methods on a space to gather information about what is there. Here are the various methods you can call on a space.

space.empty?
  If true, this means that nothing (except maybe stairs) is at this location and you can walk here.

space.stairs?
  Determine if stairs are at that location

space.enemy?
  Determine if an enemy unit is at this location.

space.captive?
  Determine if a captive is at this location.

space.wall?
  Returns true if this is the edge of the level. You can't walk here.

space.ticking?
  Returns true if this space contains a bomb which will explode in time.

You will often call these methods directly after a sense. For example, the “feel” sense returns one space. You can call “captive?” on this to determine if a captive is in front of you.

warrior.feel.captive?

Tips

If you ever get stuck on a level, review the README documentation and be sure you’re trying each ability out. If you can’t keep your health up, be sure to “rest” when no enemy is around - and keep an eye on your health. Also, try to use far-ranged weapons whenever possible (bow and bomb).

Remember, you’re working in Ruby here. Don’t simply fill up the “play_turn” method with lots of code. Make methods and classes to help organize things. Your level’s directory is set up as a load path so you can load whatever other ruby files you want in there from your player.rb file.

You will know the size of the level, but you have no idea where you are placed. use the look ability to find out where the walls are to give you some idea.

If you’re aiming for points, remember to sweep the area. Even if you’re close to the stairs, don’t go in until you’ve gotten everything (if you have the health). Use listen to find out what units are nearby.

About

Game written in Ruby for learning Ruby and artificial intelligence.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%