Skip to content
@AlgorithmicGames

Algorithmic Games

Platform for match making between algorithms.

Algorithmic Games

Algorithmic Games is a platform for competitive programming and match making between algorithms. Users can make their own participants to compete in any of the existing arenas, or make their own custom arena and challenge other users to join. Algorithmic Games was previously known as "AI-Tournaments", where "AI" in the name refers to playing against the computer on old video games, like "Hard AI" or "Hard CPU".

See the section Participate if you want to join an arena, then analyze how others have solved the arena until better documentation has been written.

Community

If you want to join the discussions, head on over to the Community handbook and read where we are.

Participate

To participate in an arena you need to create a public GitHub repository and apply three topics: AlgorithmicGames, AlgorithmicGames-Participant and the full repository name of the arena (ExampleOwner--ExampleArena). The repository also has to have a file in root called participant.js, this is the file that will be called by the arena. The repository's name will represent the participant's name, except if it starts with AlgorithmicGames-Participant- then that part is omitted.

Develop environment

For both developing arenas and participants.
Supported console logs:

  • log
  • warn
  • error
  • info
  • debug
  • table

You can define setups by adding the URLs to an arena (arena.js along with the arena's replay page) and joinables to test with before publishing them on GitHub.

Explanation

Key Description Example
arena.url URL to an arena.
⚠️ Do not include arena.js.
"http://127.0.0.1:8080/Community-Arena/" or "https://raw.githubusercontent.com/AlgorithmicGames/Worm-Arena/main/"
arena.name
Optional
Displayed name.
Name defaults to URL if left empty.
"New-Community-Arena"
arena.replay URL to replay view. "http://127.0.0.1:8080/Community-Arena-Replay/"
arena.settings
Optional
Prefigured settings. {"general":{"seed":"example"}}
joinables Joinables for the setup.
Array of URL strings or JSON objects (url, optional name, team, color, type).
["http://127.0.0.1:8080/Community-Arena-Test-Participants/participant-1.js",{"url":"http://127.0.0.1:8080/Community-Arena/interface/","name":"Human","type":"interface","team":1}]

The development environment also includes some extra dials and features to help with quality assurance.

Joinable types

Each entry in joinables is either a URL string (treated as a sandboxed participant) or an object with a type field:

type Role
participant Default. participant.js runs in an engine262 Web Worker (same sandbox as production matches).
participant-with-console Same sandbox; console.* calls are captured into the match log.
interface HTML page opened in a popup on the host machine; uses InterfaceHelper.js.
interface-p2p Same protocol as interface, but the page runs on a remote browser tab at /join (PeerJS relay).

Participant

Participants are algorithms implemented in participant.js. During a match the arena loads that script into engine262 inside a dedicated Web Worker and exchanges messages through worker handles from participant.addWorker() (worker.postMessage, worker.kill).

Interface

An interface is a normal web page (often interface/index.html beside the arena) that joins a match through InterfaceHelper.js instead of engine262. It is suited to human players, custom visuals, and tooling that needs the DOM — not to bypassing the participant sandbox or running training loops inside the match worker.

Arenas may list built-in human interfaces in properties.json under header.defaultHumanInterfaces (see Kalaha and Worm). In Setups, set "type": "interface" or "interface-p2p" on the joinable object.

After the page loads, the coordinator sends init data (settings, opponents, …), then arena traffic as { type: 'Post', message, workerSlot?, messageIndex?, systemMessage? }. When systemMessage is true, message is a system command — for example { type: 'WorkerAdded', slot } when the arena calls participant.addWorker() again on the same page, or 'Kill' when a worker is torn down.

Arena scripts spawn workers with participant.addWorker().then((worker) => worker.postMessage(…)). Slot 0 is started at match bootstrap; the first addWorker() returns that worker’s handle, and each further call allocates the next slot. Reuse the same worker handle (for example cache the promise on participant.payload) when messaging the same slot repeatedly.

Load InterfaceHelper.js, register handlers, then call InterfaceHelper.signalReady() (or postMessage(null, '*') to the opener) so the match can start:

InterfaceHelper.onInit((init, workerAdded) => {
	const settings = init.settings
	const opponents = init.opponents
	workerAdded((worker) => {
		worker.onMessage = (message) => message.respond({/* … */})
		worker.onKilled = () => {/* slot torn down */}
	})
})
InterfaceHelper.signalReady()

Use worker.respond for replies outside an onMessage handler (for example after a click).

Private repositories

Read here.

File header

The arena.js and participant.js optional file header has to be valid JSON otherwise it is omitted. The header can be placed anywhere in the file, but at the top is recommended as a standardization.

/**
{}
**/
/**{}**/
/**{
	"example": true
}**/

Dependencies

To load libraries like jQuery and others, copy the files to the repository and add them to the file header. The files have to be referenced locally. Dependencies are loaded in listed order.

/**{
	"dependencies": [
		"exampleLib.js",
		"other/exampleLib.js"
	]
}**/

Special thanks

User written JavaScript

Algorithmic Games executes user-written JavaScript in the web browser, which is usually seen as a security concern (Cross-site scripting). Participant and arena logic runs in engine262 inside Web Workers; interfaces are separate pages that only talk to the match through postMessage.

If you find a way to break out of the sandbox and access client data or other participant scripts, please report it! Reporters of confirmed security holes will get a honorable mention once the hole is fixed.

Post scriptum

If Algorithmic Games happens to be used in any scientific research, please do tell if something is published! 😃

If you have any doubts, you can request permission here.

Pinned Loading

  1. Participant-Template Participant-Template Public template

    JavaScript

  2. Arena-Template Arena-Template Public template

    JavaScript

  3. Replay-Template Replay-Template Public template

    JavaScript

Repositories

Showing 10 of 10 repositories

Top languages

Loading…

Most used topics

Loading…