Build a C robot with WebAssembly ABI 4

Write a freestanding C robot for Clunkyard's Reflex class. The WebAssembly SDK supplies the header and the exports that the match host calls.

Build, try and debug

C → WebAssembly starter

In the workbench, create a C → WebAssembly robot and edit bot.c. Save, wait for the build and queue hosted practice.

See the local player kit for your platform and toolchain setup.

npx @clunkyard/cli new c-wasm my-robot
cd my-robot
npx @clunkyard/cli doctor
npx @clunkyard/cli build
npx @clunkyard/cli match
npx @clunkyard/cli replay

Register a turn

Include clunkyard.h and pass your turn function to CY_ROBOT. Use NULL for the first argument if the robot needs no start hook.

#include "clunkyard.h"

static void turn(void) {
  cy_drive_throttle(0.5);
  cy_drive_turn(0.33);
}

CY_ROBOT(NULL, turn)

The functions in the ABI 4 C reference return a status. Check for CY_OK before using an output parameter from a call such as cy_sensors_nearest. A CY_NONE result means there is no contact yet.

Open the turn trace after a practice match to see how much fuel a decision used. If the build fails with an unresolved libc function, check that you are using the starter's freestanding build and review the WebAssembly build requirements.

Download this page as Markdown