rust-sc2
Rust implementation of StarCraft II API
The library aims to be simple and easy to use, being very fast and functional at the same time. However, it provides both high and low level abstractions. This lib is inspired by python-sc2 lib, so people might find it easy to switch to rust-sc2. It was originally created because other rust libs were old, not functional and low level.
Feel free to ask questions in #rust
channel of these Discord servers:
Getting started
Install Rust >= 1.42.0
Warning: Compilation is broken in rustc 1.45.0 - 1.46.0, you'll get following error:
thread 'rustc' has overflowed its stack
error: could not compile `rust-sc2`.
Add to dependencies in Cargo.toml:
[]
= "1.1.0"
Or if you want developer version directly from github:
[]
= { = "https://github.com/UltraMachine/rust-sc2" }
The simplest competetive bot in less than 30 lines:
use *;
;
For more advanced examples see examples
folder.
Optional features
"rayon"
- enables parallelism and makes all types threadsafe"serde"
- adds implementation ofSerialize
,Deserialize
to ids, Race, GameResult, ...
Making bot step by step
First of all, import rust-sc2 lib:
use *;
Create your bot's struct (Can be Unit or C-like):
;
Then implement Player
trait for your bot:
// You mustn't call any of these methods by hands, they're for API only
Also you might want to add method to construct it:
If your bot implements Default
you can simply call MyBot::default()
, but if you want more control over initializer:
The rest is to run it: