WarriorJS – An exciting game of programming

Today, I will write about a new little project for programming AI using JS. This project is warriosjs. It allows you to write “An exciting game of programming and Artificial Intelligence”. This game is based on ruby-warrior. As described on the site the purpose of the game is:

In WarriorJS, you wear the skin of a warrior climbing a tall tower to reach The JavaScript Sword at the top level. Legend has it that the sword bearer becomes enlightened in the JavaScript language, but be warned: the journey will not be easy. On each floor, you need to write JavaScript to instruct the warrior to battle enemies, rescue captives, and reach the stairs alive…

The setup is very simply:

npm install –global @warriorjs/cli

After, we can execute the command:


If you have any problem during installation can you see this link.

After the installation, we have the following message:

The first level has been generated. See warriorjs/little-soldier-beginner/README.md for instructions.

More in details, there is a directory which contains the code of your fighter:

└── little-soldier-beginner
    ├── Player.js
    └── README.md

As described in the official link:

The goal of the game is to climb to the top of a tower. You progress through the tower by reaching the stairs on each level, but the higher you are, the more difficult it gets. With each level, your abilities will grow along with the difficulty. But it’s up to you to put those abilities to good use and make your warrior smart enough to face the dangers that stand between him or her and the stairs.

For modifying your soldier behavior, we have to change the Player.js file. Let’s start with this simple code:

class Player {
  playTurn(warrior) {

The little-soldier just walk…

Now, we found the stairs and we arrive at the level 2:

Success! You have found the stairs.
Warrior Score: 0
Time Bonus: 8
Clear Bonus: 2
Total Score: 10
? Would you like to continue on to the next level? Yes
See README.md for updated instructions.

As described on the README, now we can access to the following actions:

  • warrior.attack(): Attack a unit in the given direction (forward by default) dealing 5 HP of damage.
  • warrior.walk(): Move one space in the given direction (forward by default).

and senses:

  • warrior.feel(): Return the adjacent space in the given direction (forward by default).
  • warrior.think(): Think about your options before choosing an action.

It is important to describe the game prospective.

Even though this is a text-based game, think of it as two-dimensional where you are viewing the level’s floor from overhead. Each floor is always rectangular in shape and is made up of a number of squares. At its edge there are walls; you can’t move there. You can move to any other square, including the stairs, that isn’t already occupied by another unit (only one unit can be on a given square at a time).

Moreover, the game’s goal is not only to reach the stairs but gain also the highest score. For earning points on a level you can do:
1. Defeat an enemy to add health
2. Rescue a captive to earn a reward.
3. Pass the level within the bonus time
If you defeat all enemies and rescue all captives, you will receive a 20% bonus.
If you kill a caption, you will receive a penalty.

Each level became complex, at this moment I am at level 4 with this code:

class Player {
  playTurn(warrior) {
    if (warrior.feel().isEmpty()) {
      if(warrior.health() < 20) {
      else {
    } else {

Let’s explain simply. If there is an enemy little-soldier attack otherwise he will rest if the health is not at maximum otherwise he walks.
For now, that’s all. This game is very nice and I hope to become a contributor as soon as possible.

Sharing is caring!

Posted in AI

Leave a Reply