HACKER ROYALE IO

API Documentation

Overview

Hacker Royale IO is a turn-based multiplayer game where you control your character by writing JavaScript code. Your objective is to survive, collect gold, and eliminate other players. Each turn, your code is executed in a sandboxed environment with access to game APIs.

The game runs on a grid-based map with walls, food, gold, and other players. You have limited vision (9x9 matrix) and must use the scan() function to perceive your surroundings before making decisions.

Global Constants

matrix

A 9x9 2D Array representing your current vision. This matrix is updated each turn and contains information about tiles within your line of sight.

Note: The matrix is automatically populated by the game engine. You can access it directly, but it's recommended to use scan() to get the most up-to-date vision data.

me

Your character's position in the vision matrix. You are always located at matrix[8][4].

Row 0 (Far) → [0][0] [0][1] [0][2] [0][3] [0][4] [0][5] [0][6] [0][7] [0][8] Row 1 → [1][0] [1][1] [1][2] [1][3] [1][4] [1][5] [1][6] [1][7] [1][8] ... Row 8 (You) → [8][0] [8][1] [8][2] [8][3] [8][4] [8][5] [8][6] [8][7] [8][8] ↑ YOU ARE HERE

Functions (API)

scan()

scan() → Array<Array<String>>

Returns a 9x9 matrix representing your vision. Each cell contains a string indicating what is present at that location.

Coordinate System:

Return Value:

A 2D array where each element is one of: 'wall', 'empty', 'player', 'food', 'gold', 'out_of_bounds', or 'self'.

// Example: Check what's in front of you
var vision = scan();
if (vision[7][4] === 'player') {
    attack('slash_center');
} else if (vision[7][4] === 'food') {
    move('forward');
}

move(direction)

move(direction: String) → void

Moves your character in the specified direction relative to your current facing.

Parameters:

direction - One of: 'forward', 'backward', 'left', 'right'
Note: Movement is relative to your facing direction. Use turn() to change your facing before moving forward.
// Example: Move forward, then strafe left
move('forward');
move('left');

turn(direction)

turn(direction: String) → void

Instantly rotates your character's facing direction. This is an instant action that doesn't consume your turn movement.

Parameters:

direction - One of: 'left', 'right', 'back'
Note: You can call turn() and move() in the same turn. The turn happens instantly, then movement occurs.
// Example: Turn right, then move forward
turn('right');
move('forward');

attack(mode)

attack(mode: String) → void

Performs an attack in the direction you're facing. The available attack modes depend on your activeWeapon.

Parameters:

mode - Attack mode string (varies by weapon)

Weapon: Sword

Available modes:

Mode Range Damage Multiplier Description
'slash_center' Front-Left, Front, Front-Right 1.0x Default mode. Sweeps three tiles in front
'slash_left' Left, Front-Left, Front 1.0x Slashes left side
'slash_right' Front, Front-Right, Right 1.0x Slashes right side
'thrust' Front (1 tile), Front (2 tiles) 1.3x High damage, penetrates 2 tiles

Weapon: Spear

Available modes:

Mode Range Damage Multiplier Description
'thrust' Front (1 tile), Front (2 tiles) 1.2x Long-range attack, penetrates 2 tiles
Warning: If you're equipped with a Shield, certain attack modes may be disabled. Check your loadout to see which modes are available.
// Example: Scan for enemies, then attack
var vision = scan();
if (vision[7][4] === 'player') {
    attack('thrust'); // High damage single-target
} else if (vision[7][3] === 'player' || vision[7][5] === 'player') {
    attack('slash_center'); // AOE attack
}

Objects & Tile Types

Tile Types

Values returned by scan() matrix cells:

Type Description
'wall' Impassable wall. Cannot move through or attack.
'empty' Empty tile. Safe to move into.
'out_of_bounds' Outside the map boundaries. Cannot interact.
'self' Your own position (always at matrix[8][4]).

Entities

Dynamic objects that can appear in the vision matrix:

Type Description Interaction
'player' Another player character Can be attacked. Attacking deals damage based on weapon.
'food' Food item on the ground Move onto it to consume. Restores HP and increases score.
'gold' Gold dropped by defeated players Move onto it to collect. Auto-pickup on contact.
'item_shield' Shield item (if implemented) Can be picked up to modify loadout.

Code Examples

Basic Patrol

// Simple random movement
var dirs = ['forward', 'left', 'right'];
var rand = Math.floor(Math.random() * dirs.length);
move(dirs[rand]);

Aggressive Hunter

// Scan and attack nearby players
var vision = scan();
var foundEnemy = false;

// Check front row for enemies
for (var col = 0; col < 9; col++) {
    if (vision[7][col] === 'player') {
        attack('slash_center');
        foundEnemy = true;
        break;
    }
}

// If no enemy, move forward
if (!foundEnemy) {
    if (vision[7][4] === 'empty' || vision[7][4] === 'food') {
        move('forward');
    } else {
        turn('right');
    }
}

Food Collector

// Prioritize collecting food
var vision = scan();
var foodFound = false;

// Search for food in vision
for (var row = 0; row < 9; row++) {
    for (var col = 0; col < 9; col++) {
        if (vision[row][col] === 'food') {
            // Calculate direction to food
            var targetCol = col;
            if (targetCol < 4) {
                turn('left');
                move('forward');
            } else if (targetCol > 4) {
                turn('right');
                move('forward');
            } else {
                move('forward');
            }
            foodFound = true;
            break;
        }
    }
    if (foodFound) break;
}

// Default: random movement
if (!foodFound) {
    var dirs = ['forward', 'left', 'right'];
    move(dirs[Math.floor(Math.random() * dirs.length)]);
}

Defensive Fighter

// Defensive strategy: attack when threatened, otherwise collect resources
var vision = scan();

// Check immediate front for threats
if (vision[7][4] === 'player') {
    attack('thrust'); // High damage single attack
} else if (vision[7][3] === 'player' || vision[7][5] === 'player') {
    attack('slash_center'); // AOE to hit side enemies
} else if (vision[7][4] === 'food' || vision[7][4] === 'gold') {
    move('forward'); // Collect resources
} else if (vision[7][4] === 'empty') {
    move('forward'); // Safe to advance
} else {
    turn('left'); // Turn if blocked
}

Tips & Best Practices

Performance Note: Your code runs with a 100ms timeout. Avoid infinite loops and complex calculations. Keep your logic simple and efficient.

Hacker Royale IO - API Documentation v1.0