Skip to main content

Module order

Module order 

Source
Expand description

A candidate order made of ranked groups: the few commands worth trying first, out of hundreds of legal ones.

A bot that plans (TurnPlan, Rollout) tries only the first candidates commands of its Order. The legal order cut at ten holds one piece’s attack in every flavour and nothing else, and a planner that never tries its other pieces, a step towards the goal or the end of its turn stalls (game ADR-0095). ranked_order is the generic cure: the game tags each legal command with a Ranked group, value and key (or leaves it out), and gets back

  1. the groups in ascending order;
  2. in a group, the best value first (a stable sort: ties keep the game’s order);
  3. in a group, one per key first: the first command of each key comes before any second command of a key already listed (a round-robin: all firsts, then all seconds…); a command with no key is never held back;
  4. the last command (the end of the turn), if any, kept within the cap: it takes the place of the last of the first cap commands, so the cap never cuts it.

A deck-builder’s order is this alone: damage plays best first, one per target first, then draws, then the rest, ending the turn always kept. A grid game’s is TacticsOrder, built on it.

use shuyi_core::bots::{Ranked, ranked_order};

let plays = vec![
    Ranked::new("strike a", 0, (5, 0), Some('a')),
    Ranked::new("draw", 1, (0, 0), None),
    Ranked::new("burn a", 0, (4, 0), Some('a')),
    Ranked::new("strike b", 0, (3, 0), Some('b')),
];
let order = ranked_order(plays.clone(), Some("end turn"), 10);
assert_eq!(order, ["strike a", "strike b", "burn a", "draw", "end turn"]);
assert_eq!(ranked_order(plays, Some("end turn"), 3), ["strike a", "strike b", "end turn"]);

Structs§

Ranked
One command of a candidate order, as the game ranks it.

Functions§

ranked_order
The first cap commands of items in the order the module’s docs give: groups ascending, the best value first in a group, one per key first, and last, if any, in place of the last of them. cap 0 counts as 1.