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.
A 9x9 2D Array representing your current vision. This matrix is updated each turn and contains information about tiles within your line of sight.
scan() to get the most up-to-date vision data.
Your character's position in the vision matrix. You are always located at matrix[8][4].
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');
}
Moves your character in the specified direction relative to your current facing.
Parameters:
direction - One of: 'forward', 'backward', 'left', 'right'
'forward': Move in the direction you're facing'backward': Move opposite to your facing'left': Move to your left (strafe, doesn't change facing)'right': Move to your right (strafe, doesn't change facing)facing direction. Use turn()
to change your facing before moving forward.
// Example: Move forward, then strafe left
move('forward');
move('left');
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'
'left': Rotate 90° counterclockwise'right': Rotate 90° clockwise'back': Rotate 180° (face opposite direction)turn() and move() in the same turn.
The turn happens instantly, then movement occurs.
// Example: Turn right, then move forward
turn('right');
move('forward');
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)
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 |
Available modes:
| Mode | Range | Damage Multiplier | Description |
|---|---|---|---|
'thrust' |
Front (1 tile), Front (2 tiles) | 1.2x | Long-range attack, penetrates 2 tiles |
// 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
}
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]). |
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. |
// Simple random movement
var dirs = ['forward', 'left', 'right'];
var rand = Math.floor(Math.random() * dirs.length);
move(dirs[rand]);
// 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');
}
}
// 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 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
}
scan() at the beginning of each turn to assess your surroundings.turn() and move() in the same turn.Hacker Royale IO - API Documentation v1.0