warriorjs 0,1,0,0,0,0,0,1 eslint travis-ci npm

Game written in JavaScript for learning JavaScript and artificial intelligence.

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

You play as a warrior climbing a tall tower to [insert something motivating here] at the top level. On each floor, you need to write JavaScript to instruct the warrior to battle enemies, rescue captives, and reach the stairs.

Travis npm styled with prettier Gitter


$ npm install -g warriorjs

Note on Installation

Node.js needs to be installed in your computer before running the npm command. The recommended installation method is through the official installer.


$ warriorjs

That’s it! This will create a warriorjs directory in your current location, where you will find a Player.js file in your profile’s directory containing the Player class:

class Player {
  playTurn(warrior) {
    // Cool code goes here

Note on CLI

Run $ warriorjs --help to see the options you can use to customize the game.


Your objective is to fill the playTurn method with commands to instruct the warrior what to do. With each level, your abilities will grow along with the difficulty. See the README in your profile’s directory 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 {
  playTurn(warrior) {
    if (warrior.feel().isEnemy()) {
    } else {


Once you are done editing Player.js, save the file and run the warriorjs command again to start playing the level. The play happens through a series of turns. On each one, your playTurn method is called along with any enemy’s.

You cannot 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 Player.js file, improve your code, and try again.

Once you pass a level (by reaching the stairs), the profile README will be updated for the next level. Alter the Player.js file and run warriorjs again to play the next level.


Your objective is to not only reach the stairs, 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.


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 at a time, and your objective is to find the square with the stairs. Here is an example level map and key:

║C s>║
║ S s║
║C @ ║

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


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.

Note on Abilities

Many abilities can be performed in the following directions: forward, backward, left and right. You have to pass a string with the direction as the first argument, e.g. warrior.walk('backward');.


An action is something that affects the game in some way. Only one action can be performed per turn, so choose wisely.

Here is the complete list of actions:


Move in given direction (forward by default).


Attack a unit in given direction (forward by default).


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


Rescue a captive from his chains (earning 20 points) in given direction (forward by default).


Rotate left, right or backward (default).


Shoot your bow & arrow in given direction (forward by default).


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


Detonate a bomb in a given direction (forward by default) which damages that space and surrounding 4 spaces (including yourself).


Kills you and all surrounding units. You probably don’t want to do this intentionally.


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 and to aid you in choosing the proper action.

Here is the complete list of senses:


Return a Space for the given direction (forward by default).


Return an integer representing your current health.


Return an array of up to three Spaces in the given direction (forward by default).


Return the direction the stairs are from your location.


Pass a Space as an argument, and the direction to that space will be returned.


Pass a Space as an argument, and it will return an integer representing the distance to that space.


Return an array of all spaces which have units in them.

Note on Senses

Since what you sense will change each turn, you should record what information you gather for use on the next turn. For example, you can determine if you are being attacked if your health has gone down since the last turn.


A space is an object representing a square in the level. Whenever you sense an area, often one or multiple spaces (in an array) will be returned.

You can call methods on a space to gather information about what is there. Here are the various methods that are available to you:


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


Determine if stairs are at that location.


Determine if an enemy unit is at this location.


Determine if a captive is at this location.


Return true if this is the edge of the level. You can’t walk here.


Return true if this space contains a bomb which will explode in time.

Note on Spaces

You will often call these methods directly after a sense. For example, the feel sense returns one Space. You can call isCaptive() on this to determine if a captive is in front of you:


Epic mode

Once you reach the top of the tower, you will enter Epic mode. When running warriorjs again, it will run your current Player.js through all levels in the tower without stopping.

Your warrior will most likely not succeed the first time around, so use the -l option on levels you are having difficulty or want to fine-tune the scoring.

$ warriorjs -l 4

Once your warrior reaches the top again, you will receive an average grade, along with a grade for each level. The grades from best to worst are S, A, B, C, D and F. Try to get S on each level for the ultimate score!

Tips & hints


  • 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 (while keeping an eye on your health). Also, try to use far-ranged weapons whenever possible (such as the bow).

  • Remember, you’re working in JavaScript here. Don’t simply fill up the playTurn method with a lot of code. Organize it with methods and classes.

  • Senses are cheap, so use them liberally. Store the sensed information to help you better determine what actions to take in the future.

  • Running warriorjs while you are in your profile directory will auto-select that profile so you don’t have to each time.

  • 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 far-ranged senses (such as look and listen) to determine if there are any enemies left.


  • If you want some code to be executed at the beginning of each level, define a constructor in the Player class, like this:
class Player {
  constructor() {
    // This code will be executed only once, at the beginning of the level
    this._health = 20;

  playTurn(warrior) {
    // Cool code goes here
  • If you just want to initialize a property, like _health in the example above, you can make use of Class Instance Fields:
class Player {
  _health = 20;

  playTurn(warrior) {
    // Cool code goes here
isEnemyInSight(warrior) {
  const unit = warrior.look().find(space => !space.isEmpty());
  return unit && unit.isEnemy();
  • In the example above, you can see the Arrow functions in use. Make sure to take a look at them too!


This game was originally developed by @ryanb to teach the Ruby language. Special thanks to him for the original ruby-warrior.



Related Repositories



Game written in JavaScript for learning JavaScript and artificial intelligence. ...



The bowels of WarriorJS ...

Top Contributors

olistic LeonardoVal


package version
bluebird ^3.5.0
chalk ^1.1.3
ejs ^2.5.6
fs-extra ^3.0.1
glob ^7.1.1
inquirer ^3.0.6
warriorjs-engine ^1.0.0
yargs ^8.0.1
dev babel-cli ^6.24.1
babel-eslint ^7.2.3
babel-preset-env ^1.4.0
babel-preset-stage-2 ^6.24.1
eslint ^3.0.1
eslint-config-airbnb-base ^11.2.0
eslint-plugin-import ^2.2.0
jest ^20.0.1
prettier ^1.3.1
rimraf ^2.6.1


-   v3.0.0 zip tar
-   v2.2.0 zip tar
-   v2.1.0 zip tar
-   v2.0.1 zip tar
-   v2.0.0 zip tar
-   v1.2.2 zip tar
-   v1.2.1 zip tar
-   v1.2.0 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.0 zip tar
-   v0.8.1 zip tar