Yare-Rust
A library for making bots for yare with Rust.
How it works
You make a Rust library and compile to wasm. Then you use the wasm2yareio script to generate a JavaScript yare bot. The result can be copied into the game.
Setup
You will need Rust, and some additional tools.
Create a new Rust library.
Put this in your Cargo.toml
.
[]
= ["cdylib"]
[]
= "0.1"
[]
= "s"
= true
Then copy wasm2yareio.js
from the linked submodule into your project and
install a dependency. Make sure your Node is up-to-date.
Example
This is an example bot. You need to define an external function called tick
that has one parameter. This will be called every tick.
pub extern "C"
You should make safe wrappers for these function so that you don't have to have unsafe
blocks in your bot code.
For example, you could do something like this:
use CString;
use spirit;
use player;
/// Your own Spirit struct with all the information you want.
/// Parse all spirits into your own Spirit structs.
// No unsafe block needed here!
pub extern "C"
Check out this template for an example of how you can structure your code!
Building
To build your yare bot, you first need to compile to wasm. Use this:
Then you want to pass it through wasm2yareio.
It is also recommended that you install the tampermonkey script to automatically upload your code to yare.io: Click to install.
Headless
This library comes with a headless implementation of the game by dbenson24. It is not complete, but it is useful for regression tests or possibly machine learning.
To use it, you will need to enable the "headless"
feature. You will most likely
run want to do this when testing. The command might look like this:
The test should look something like this:
Make sure your bots are thread-safe if you run multiple tests. If you play against yourself, make sure you do not write to the same mutable statics.
Furthermore, there are undocumented ffi bindings to run the headless simulation from other languages.