Expand description
Threat areas over a square grid: the tiles a piece can strike next
turn (strike_area, strike_area_from), which threats reach a
tile and whether it is safe (Threats), how much danger a tile
stands in by the game’s own forecast (Threats::danger), and how far
a piece would walk from a tile to the nearest of some goals
(GoalDistance). It is the danger zone a player reads: a bot that
plays like a person keeps out of it, a roguelike draws a monster’s
reach as an overlay, a tower-defense game shows a tower’s coverage.
On them, TacticsOrder lists the few commands a planning bot tries
first: every piece’s best strike, then each piece’s step towards the
goals and its step to safety, and the end of the turn always kept
(OrderHooks, Kind).
§Rules
- Ranges. A strike range is an inclusive pair of Manhattan
distances,
(min, max), asPos::manhattancounts them; a pair withmin > maxis empty. A piece’sRangesare all of its weapons, spells or arcs. - Areas. A piece strikes every tile of the grid within one of its
ranges of a tile it can stop on, and the stop tiles themselves when
it has any range at all: a piece that can strike threatens where it
can stand. Which tiles it can stop on is the game’s: most often the
tiles of its
Reach(reachable) that no other piece holds. A piece that never moves strikes from where it stands (strike_area_from). - Every threat counts.
Threats::dangeradds up the forecast of every threat that reaches a tile; it never guesses which one the other side will choose. A bot that knows the danger zone and the forecasts a player reads, and never whom the other side will strike, plays fair. - Cost. Building an area walks a diamond around each stop tile,
row by row, clipped to the grid: stops × (rows × ranges + the tiles
in range).
Threats::reachesandThreats::safelook up one bit per threat and allocate nothing.
A piece at P on a 5 × 5 grid stops on the o tiles (and on its own)
and strikes at 1 to 2. Its area is every tile but the three .:
stops area
. . . . . x x x x .
. o o . . x x x x x
. o P o . x x x x x
. . o . . x x x x x
. . . . . . x x x .use shuyi_core::{Pos, TileSet, strike_area};
let mut stops = TileSet::new(5, 5);
for (x, y) in [(2, 2), (1, 1), (2, 1), (1, 2), (3, 2), (2, 3)] {
stops.insert(Pos::new(x, y));
}
let area = strike_area(&stops, &[(1, 2)]);
assert_eq!(area.len(), 25 - 3);
for (x, y) in [(4, 0), (0, 4), (4, 4)] {
assert!(!area.contains(Pos::new(x, y)));
}Structs§
- Danger
- The danger at one tile:
Threats::danger’s sums of theStrikes of every threat that reaches it. - Goal
Distance - How far a piece would walk from a tile to the nearest of some goals,
with one
flow_fieldper movement kindK, built on first use and kept. Stepping onto a goal’s own tile is free and always allowed: a goal is often a tile another piece stands on. - Strike
- The game’s forecast of one threat’s strike on whoever stands on a tile. Expected values are in hundredths of a point: a hit chance in percent times the damage.
- Tactics
Order - A planner’s candidate order for grid games, in eight steps (the
module’s docs): every piece’s best strike, the game’s pick, its extras,
each piece’s advance and hold, the other strikes, the rest, and the end
of the turn within
cap. - Threat
- One piece that threatens tiles: the game’s id for it and the tiles it can strike next turn.
- Threats
- The threats of one side, in the game’s order. Answers which reach a tile, whether a tile is safe, the danger zone, and the danger at a tile by the game’s forecast.
Enums§
- Kind
- What a legal command is to a
TacticsOrder.Pis the game’s id of a piece.
Traits§
- Order
Hooks - What a
TacticsOrderasks the game, once perordercall. The game’s hooks hold the state’sThreatsandGoalDistance, built inprepare.
Functions§
- strike_
area - The tiles a piece that can stop on
stopsstrikes withranges: every tile of the set’s grid within one ofrangesof a stop tile, and the stop tiles themselves whenrangesis not empty. Emptyrangesstrike nothing. See the module docs for the cost. - strike_
area_ from - The tiles a piece that never moves, standing on
at, strikes withrangeson awidth × heightgrid:strike_areawithatits only stop. A tile outside the grid strikes nothing.
Type Aliases§
- Ranges
- A piece’s strike ranges: inclusive pairs of Manhattan distances
(min, max). A pair withmin > maxis empty.