function MyRobot(team,id) { const nextAngle = function() { return lastAngle+=0.1; } const randomAngle = function() { return Math.random()*2*Math.PI-Math.PI; } let lastAngle = randomAngle(); let lastGoodAngle = null; let lastGoodDistance = null; let dir = 0; let dist = -1; let a=0; return function({scan,fire,state}) { if(state.canScan) { if(dist<0) { a = nextAngle(); } dist = scan(a,0.2); if(dist>0) { lastGoodAngle = a; lastGoodDistance = dist; } } if(lastGoodAngle !== null && state.canFire) fire(lastGoodAngle,lastGoodDistance) if(Math.random()<0.005) dir+=Math.PI return {angle:dir+=Math.random()*0.2-0.1} } }


simulation speed
opponent:
robots per team:

Robot Battle Documentation

Game Overview

Welcome to the Robot Battle Game! This documentation serves as a guide to help you understand and utilize the programming interface provided to control your robots in intense battles against each other. The game revolves around designing intelligent strategies for your robots to outwit and defeat their opponents.

Game Overview

In the Robot Battle Game, you will create and program your own robots to engage in thrilling combat within a virtual arena. Each robot will be controlled by a JavaScript function that determines its actions during the battle. The objective is to develop the most effective algorithm to destroy your opponents and emerge victorious.

Your robots will have access to various functions and information to aid in their decision-making. These functions include scanning the environment for enemy robots, firing bombs to eliminate targets, and retrieving vital details about the robot's current state. By leveraging these capabilities, you can devise intelligent strategies to outmaneuver your adversaries and deliver devastating blows.

Programming Interface

The programming interface exposes three essential variables: scan, fire, and state. The scan function allows your robot to gather information about the nearby enemies, while the fire function enables you to launch bombs at specific angles and distances. The state object provides valuable insights into the robot's position, the dimensions of the arena, and the availability of scanning and firing actions.

To control the behavior of your robot, you must define a function that takes a single argument—a destructured object containing scan, fire, and state—and returns an object specifying the direction the robot should move in the current turn.

Strategy and Tactics

The key to success in the Robot Battle Game lies in developing effective strategies and tactics. You must carefully analyze the environment, make smart decisions based on available information, and continuously adapt your robot's behavior to outwit opponents.

Experiment with different algorithms, iterate on your code, and refine your strategies to maximize your robot's combat effectiveness. Observe how your robots fare in battle and fine-tune their behavior to exploit enemy weaknesses. Remember, the ultimate goal is to become the supreme champion of the Robot Battle Game!


Example Robot

function() {
    // Function for controlling the robot's behavior
    const nextAngle = function() {
        // Returns the next angle to scan
        return lastAngle += 0.05;
    }
    const randomAngle = function() {
        // Returns a random angle
        return Math.random() * 2 * Math.PI - Math.PI;
    }

    let lastAngle = randomAngle();
    let lastGoodAngle = null;
    let lastGoodDistance = null;
    let dir = 0;

    return function({scan, fire, state}) {
        if (state.canScan) {
            let a = nextAngle();
            let dist = scan(a, 0.5);

            if (dist > 0) {
                lastGoodAngle = a;
                lastGoodDistance = dist;
            }
        }
        if (lastGoodAngle !== null && state.canFire)
            fire(lastGoodAngle, lastGoodDistance);

        if (Math.random() < 0.005) dir += Math.PI;

        return { angle: dir += Math.random() * 0.2 - 0.1 };
    }
}
  

Functions

scan(angle, width)

Returns the distance of the closest enemy within the specified scan range or null if scan is not available yet (takes time to recharge).

fire(angle, distance)

Fires a bomb in the specified direction and at the specified distance. Returns true if the firing succeeded or null if you need to wait for recharge.

state

Returns information about the robot's current state.

Return Value

The function can return an object { angle: value } that represents the direction in which the robot will move in the current turn. If no angle is defined, the robot will stay in its current position.

Game inspired by jrobots which in turn was inspired by crobots. Thanks to ChatGPT for the documentation. Thanks to ACE Editor for the editor. It's me for the rest