#wasmdome #wascc #api-bindings

wasmdome-mech-sdk

SDK for developing WebAssembly robots to compete autonomously in arenas

7 releases

0.0.7 Jul 29, 2020
0.0.6 Jul 13, 2020
0.0.4 May 20, 2020
0.0.3 Mar 4, 2020
0.0.1 Feb 26, 2020

#1411 in WebAssembly

Apache-2.0

17KB
187 lines

Assembly Mechs: Beyond WasmDome - Mech SDK

This is the SDK used by developers for building mechs to compete in the WasmDome. Developers building mechs that will compete for nothing less than the survival of the planet will do so by responding to turn events delivered by the game engine and return a vector of mech commands..

Here's an example of a mech that simply moves north and fires every turn (obviously you will want a more clever strategy if you want to win):

extern crate wasmdome_mech_sdk as mech;

use mech::*;

mech_handler!(handler);

pub fn handler(mech: impl MechInstruments) -> Vec<MechCommand> {
     vec![
          mech.request_radar(),
          mech.move_mech(GridDirection::North),
          mech.fire_primary(GridDirection::South)
     ]
}

lib.rs:

Assembly Mechs: Beyond WasmDome SDK

The year is 2020 and our containerized civilization is falling apart. A cruel and villainous DevOps demon named Boylur Plait has descended from the cloud to Earth to challenge mankind to a tournament.

To win this tournament, Assembly Mechs must compete in an absurdly over-dramatized contest. These mechs will challenge their creator's ability to write code that will outlast and defeat everything that the demon and its nearly infinite hordes pit against us. Humanity's only hope is to master a technology called WebAssembly, win the tournament, and prove to the cloud nemesis that this world is well protected.

How to Play

The game is played by your mech declaring a handler function. During each turn, the mech's handler will be invoked and it will be responsible for returning a list of commands. These commands can include requests to move, fire a weapon, perform a radar scan, etc. Commands cost action points and you need to take care that you do not exceed the maximum number of action points per turn (currently 4).

Your mech will have to make clever use of the limited resources and information available to it to devise a strategy for winning the match.

The mech interacts with its environment exclusively through the use of the MechInstruments trait.

Possible Mech Actions

The following is a list of actions a mech can take by using the appropriate methods in the Assembly Mech SDK:

Action AP Cost Description
move_mech 1 Moves the mech one grid unit in a given direction.
fire_primary 2 Fires the mech's primary weapon in a given direction. Primary weapons fire a single small projectile that will damage the first thing it encounters. Primary weapon range is available via sensor interrogation.
fire_secondary 4 Fires the mech's secondary weapon in a given direction. Secondary weapons fire an explosive projectile that damages the first thing it encounters, as well as producing splash damage that radiates out from the point of impact. Secondary weapon range is available via sensor interrogation.
radar_scan 1 Performs a full radar scan of the mech's surroundings, reporting on detected enemies and obstacles. The mech will receive the results of the scan at the beginning of the next turn.

The default, unaffected power of a mech is 4 units, meaning that within a single turn a mech may fire its secondary weapon once, move 4 times, or perform some other combination of actions. Accessing sensor values does not cost you anything.

Warnings

Take care not to exceed the maximum number of action points consumed in a given turn. At best, commands exceeding your power will fail, at worst (depending on the match rules) your mech might be penalized for the attempt

Collision damage is real, and your mech's hull will lose structural integrity when colliding with other mechs and with walls

Example

extern crate wasmdome_mech_sdk as mech;

use mech::*;

mech_handler!(handler);

// Respond to a request to take a turn
pub fn handler(mech: impl MechInstruments) -> Vec<MechCommand> {
    // Respond with up to 4 action points worth of actions
    vec![
        mech.request_radar(),
        mech.move_mech(GridDirection::North),
        mech.fire_primary(GridDirection::South),
    ]
}

Dependencies

~2.2–3.5MB
~65K SLoC