The Elixir binding
The generated Elixir facade shares the Erlang binding's in-process NIF.
Facts are functions of the robot handle, records are maps, controls take a
map of fields, and an absent result is :undefined. on_start/1 returns
memory; on_turn/2 returns its next value. The core owns every helper and
the tracker.
Install after the Erlang binding with make install SDK=/opt/clunkyard/sdk.
Run with elixir -pa /opt/clunkyard/sdk/bindings/erlang -pa /opt/clunkyard/sdk/bindings/elixir bot.exs.
A tiny robot
defmodule Tiny do
alias Clunkyard, as: C
def on_turn(r, state) do
target = C.sensors_nearest(r)
if target == :undefined do
C.drive_set(r, %{throttle: 0.75, turn: 0.25})
C.scanner_set(r, %{heading: C.me_heading(r), arc: 40})
C.status_set(r, %{text: "SEARCH", value: C.scanner_last(r).arc})
else
power = C.gun_power_for_flight_time(r, target.range, 1)
aim = C.gun_lead(r, target, power)
C.gun_aim(r, if(aim == :undefined, do: %{heading: target.bearing, pitch: target.elevation}, else: %{heading: aim.heading, pitch: aim.pitch}))
if C.gun_can_fire(r, power, 10), do: C.gun_fire(r, %{power: power})
C.drive_set(r, %{throttle: 0.5, turn: C.angles_clamp(C.angles_angle_diff(target.bearing, C.me_heading(r)), -1, 1)})
C.scanner_set(r, %{heading: target.bearing, arc: 10})
C.status_set(r, %{text: "TRACK", value: target.range})
end
state
end
end
Clunkyard.run(Tiny)
make test SDK=... checks the actual generated API against every core
vector, including exact floating-point results and act lines. Core errors
raise a language error carrying their status. A core fault during input
sends its empty act and continues with the next state. User exceptions are
logged and send the controls already set. Use the binding’s forfeit helper
to give up a match; play runs protocol lines in memory for tests.
Names
Every entry of the robot API 2.0.0 in Elixir. names.md has every language side by side.
| Canonical | Form | Elixir |
|---|---|---|
match.mode |
property | Clunkyard.match_mode |
match.ruleset |
property | Clunkyard.match_ruleset |
match.control |
property | Clunkyard.match_control |
match.robots |
property | Clunkyard.match_robots |
match.is_3d |
property | Clunkyard.match_is_3d |
match.tick_rate |
property | Clunkyard.match_tick_rate |
match.max_ticks |
property | Clunkyard.match_max_ticks |
match.robot_id |
call | Clunkyard.match_robot_id |
clock.tick |
property | Clunkyard.clock_tick |
clock.seconds |
property | Clunkyard.clock_seconds |
clock.remaining_ticks |
property | Clunkyard.clock_remaining_ticks |
arena.size |
property | Clunkyard.arena_size |
arena.gravity |
property | Clunkyard.arena_gravity |
arena.terrain_kind |
property | Clunkyard.arena_terrain_kind |
arena.ground_height |
call | Clunkyard.arena_ground_height |
me.health |
property | Clunkyard.me_health |
me.position |
property | Clunkyard.me_position |
me.velocity |
property | Clunkyard.me_velocity |
me.heading |
property | Clunkyard.me_heading |
me.pitch |
property | Clunkyard.me_pitch |
me.roll |
property | Clunkyard.me_roll |
me.angular_velocity |
property | Clunkyard.me_angular_velocity |
me.attitude |
property | Clunkyard.me_attitude |
me.grounded |
property | Clunkyard.me_grounded |
me.altitude |
property | Clunkyard.me_altitude |
me.applied |
property | Clunkyard.me_applied |
battery.charge |
property | Clunkyard.battery_charge |
battery.capacity |
property | Clunkyard.battery_capacity |
battery.regen |
property | Clunkyard.battery_regen |
battery.sustainable_drive |
property | Clunkyard.battery_sustainable_drive |
battery.compute |
property | Clunkyard.battery_compute |
battery.drive_cost |
call | Clunkyard.battery_drive_cost |
drive.hover_lift |
property | Clunkyard.drive_hover_lift |
drive.set |
control | Clunkyard.drive_set |
drive.forces |
control | Clunkyard.drive_forces |
drive.get |
call | Clunkyard.drive_get |
gun.aim_now |
property | Clunkyard.gun_aim_now |
gun.cooldown_ticks |
property | Clunkyard.gun_cooldown_ticks |
gun.spread |
property | Clunkyard.gun_spread |
gun.max_power |
property | Clunkyard.gun_max_power |
gun.damage_scale |
property | Clunkyard.gun_damage_scale |
gun.can_fire |
call | Clunkyard.gun_can_fire |
gun.shot_speed |
call | Clunkyard.gun_shot_speed |
gun.shot_cost |
call | Clunkyard.gun_shot_cost |
gun.reload_ticks |
call | Clunkyard.gun_reload_ticks |
gun.shot_damage |
call | Clunkyard.gun_shot_damage |
gun.power_for_speed |
call | Clunkyard.gun_power_for_speed |
gun.power_for_flight_time |
call | Clunkyard.gun_power_for_flight_time |
gun.lead |
call | Clunkyard.gun_lead |
gun.lead_point |
call | Clunkyard.gun_lead_point |
gun.aim |
control | Clunkyard.gun_aim |
gun.fire |
control | Clunkyard.gun_fire |
gun.get |
call | Clunkyard.gun_get |
scanner.last |
property | Clunkyard.scanner_last |
scanner.proximity_range |
property | Clunkyard.scanner_proximity_range |
scanner.reach |
call | Clunkyard.scanner_reach |
scanner.arc_for_reach |
call | Clunkyard.scanner_arc_for_reach |
scanner.set |
control | Clunkyard.scanner_set |
scanner.get |
call | Clunkyard.scanner_get |
sensors.contacts |
property | Clunkyard.sensors_contacts |
sensors.nearest |
property | Clunkyard.sensors_nearest |
sensors.cues |
property | Clunkyard.sensors_cues |
sensors.contact |
call | Clunkyard.sensors_contact |
sensors.position_of |
call | Clunkyard.sensors_position_of |
tracker.cue |
property | Clunkyard.tracker_cue |
tracker.nearest_bearing_rate |
property | Clunkyard.tracker_nearest_bearing_rate |
tracker.velocity |
call | Clunkyard.tracker_velocity |
tracker.position |
call | Clunkyard.tracker_position |
tracker.last_seen |
call | Clunkyard.tracker_last_seen |
tracker.configure |
call | Clunkyard.tracker_configure |
nav.zone |
property | Clunkyard.nav_zone |
nav.zone.margin |
call | Clunkyard.nav_zone_margin |
nav.zone.contains |
call | Clunkyard.nav_zone_contains |
nav.zone.distance_from |
call | Clunkyard.nav_zone_distance_from |
nav.storm |
property | Clunkyard.nav_storm |
nav.storm.margin |
call | Clunkyard.nav_storm_margin |
nav.storm.contains |
call | Clunkyard.nav_storm_contains |
nav.storm.distance_from |
call | Clunkyard.nav_storm_distance_from |
nav.hill |
property | Clunkyard.nav_hill |
nav.hill.margin |
call | Clunkyard.nav_hill_margin |
nav.hill.contains |
call | Clunkyard.nav_hill_contains |
nav.hill.distance_from |
call | Clunkyard.nav_hill_distance_from |
nav.pickups |
property | Clunkyard.nav_pickups |
nav.nearest_pickup |
call | Clunkyard.nav_nearest_pickup |
nav.field_distance |
call | Clunkyard.nav_field_distance |
score.me |
property | Clunkyard.score_me |
score.best |
property | Clunkyard.score_best |
score.armour |
property | Clunkyard.score_armour |
angles.normalize |
call | Clunkyard.angles_normalize |
angles.angle_diff |
call | Clunkyard.angles_angle_diff |
angles.bearing_to |
call | Clunkyard.angles_bearing_to |
angles.elevation_to |
call | Clunkyard.angles_elevation_to |
angles.direction |
call | Clunkyard.angles_direction |
angles.distance |
call | Clunkyard.angles_distance |
angles.clamp |
call | Clunkyard.angles_clamp |
status.set |
control | Clunkyard.status_set |
status.get |
call | Clunkyard.status_get |
raw.number |
call | Clunkyard.raw_number |
raw.text |
call | Clunkyard.raw_text |
raw.has |
call | Clunkyard.raw_has |
raw.flag |
call | Clunkyard.raw_flag |
raw.count |
call | Clunkyard.raw_count |
raw.line |
call | Clunkyard.raw_line |
raw.extra |
call | Clunkyard.raw_extra |
session.event |
property | Clunkyard.session_event |
session.next |
call | Clunkyard.session_next |
session.send |
call | Clunkyard.session_send |
session.forfeit |
call | Clunkyard.session_forfeit |
session.log |
call | Clunkyard.session_log |
session.feed |
call | Clunkyard.session_feed |
session.reply |
call | Clunkyard.session_reply |