rustyscreeps / screeps-starter-rust

Starter Rust AI for Screeps, the JavaScript-based MMO game
MIT License
121 stars 47 forks source link

Add example of getting random values, use them for creep name #36

Open shanemadden opened 1 year ago

shanemadden commented 1 year ago

I finally bothered to get a proof of concept going of getting randomness the 'right' way within Screeps WASM - it's a little tricky since the js feature on the getrandom crate assumes we have interfaces we don't, so going down that path is a trap, and we need a custom randomness function.

This replaces the additional part of the creep name with a random value instead of an incrementor - arguably this makes the example bot worse since it risks failing to spawn a creep when it could before , but also it's...

  1. a common enough feature that people want in their bots,
  2. extremely low risk of actually causing issues since people aren't likely multi-rooming on the example bot unmodified, and
  3. a bit wordy to document the setup for since you're adding two crate dependencies (but one is only to turn on a feature) then calling a macro on the function with the right signature to register

    ..so it seems like having this as part of the example would be an overall good/not too much extra complexity.