yahtzee_engine/strategy.rs
1//! The decision procedure a bot (or human front end) implements.
2
3use crate::{Category, TurnAction, View};
4
5/// A decision procedure for playing a turn.
6///
7/// The engine asks [`choose_action`](Self::choose_action) while rolls
8/// remain and [`choose_category`](Self::choose_category) after the third
9/// roll, when only scoring is possible — an illegal reroll is
10/// unrepresentable there. The trait is object-safe, so tables can mix
11/// strategies via `&mut dyn Strategy`.
12pub trait Strategy {
13 /// Decides with rolls remaining: hold and reroll, or score now.
14 fn choose_action(&mut self, view: &View<'_>) -> TurnAction;
15
16 /// Decides after the final roll: which category to score.
17 fn choose_category(&mut self, view: &View<'_>) -> Category;
18
19 /// A short display name for logs and arenas.
20 fn name(&self) -> &str {
21 "unnamed"
22 }
23}