pub trait Strategy {
// Required methods
fn offer_upcard(&mut self, view: &View<'_>) -> UpcardAction;
fn choose_draw(&mut self, view: &View<'_>) -> DrawAction;
fn play_turn(&mut self, view: &View<'_>) -> TurnAction;
fn choose_layoff(&mut self, view: &View<'_>) -> Option<Layoff>;
// Provided method
fn name(&self) -> &str { ... }
}Expand description
A decision procedure for one seat of gin rummy
Every method receives a View restricted to the information the seat
may legally see. Methods take &mut self so strategies can keep state —
an internal random number generator, an opponent model — and the trait is
object-safe, so the driver works with &mut dyn Strategy.
A strategy never applies its decisions itself; the Table driver
validates and applies them, rejecting illegal choices as
EngineError::IllegalAction.
Required Methods§
Sourcefn offer_upcard(&mut self, view: &View<'_>) -> UpcardAction
fn offer_upcard(&mut self, view: &View<'_>) -> UpcardAction
Take or pass the initial upcard
Sourcefn choose_draw(&mut self, view: &View<'_>) -> DrawAction
fn choose_draw(&mut self, view: &View<'_>) -> DrawAction
Draw from the stock or the discard pile
Not consulted on the forced stock draw after both players pass the
upcard — the driver draws from the stock directly, so implementations
may treat DrawAction::TakeDiscard as always available.
Sourcefn play_turn(&mut self, view: &View<'_>) -> TurnAction
fn play_turn(&mut self, view: &View<'_>) -> TurnAction
Discard, knock, or declare big gin
The drawn card is already in View::hand, which holds 11 cards;
View::taken_discard is the card that may not be shed this turn.
Sourcefn choose_layoff(&mut self, view: &View<'_>) -> Option<Layoff>
fn choose_layoff(&mut self, view: &View<'_>) -> Option<Layoff>
Lay one card off onto the knocker’s spread, or None to finish
Called repeatedly with a refreshed view — the spread grows with every
accepted layoff — until the strategy returns None.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".