pub struct LocalSession<G: Game> { /* private fields */ }Expand description
An in-memory game: owns a Game and its state, and applies requests to
them directly. No file, socket, or other I/O, and no serialization: the
typed Request/Response pass straight through.
This is the authority. A crate::FileSession is a thin wrapper that
loads one of these, submits a single request, and saves it back; a
long-lived server would hold one across many requests.
A committed chance node (PlayerId::CHANCE active) is resolved
automatically from chance, so submit only ever returns control at a
player decision or a terminal state, never stuck on a deck deal a client
cannot make. chance is seeded from the match seed but offset, so it does
not share a stream with the game’s own in-state generator.
Implementations§
Source§impl<G: Game> LocalSession<G>
impl<G: Game> LocalSession<G>
Sourcepub fn new(game: G, state: G::State, seed: u64) -> Self
pub fn new(game: G, state: G::State, seed: u64) -> Self
Starts a session over game at state, at version 0, with the chance
sampler seeded from seed. Any chance node the opening position starts
on (e.g. an initial deal) is resolved immediately.
Sourcepub const fn resume(
game: G,
state: G::State,
version: u64,
chance: Prng,
) -> Self
pub const fn resume( game: G, state: G::State, version: u64, chance: Prng, ) -> Self
Resumes a session at a previously saved state, version, and chance
sampler, e.g. from a crate::FileSession save file. Does not
re-resolve chance: a saved position is always left at a player decision
or terminal, never mid-chance.
Sourcepub const fn state(&self) -> &G::State
pub const fn state(&self) -> &G::State
Returns the current authoritative state, e.g. to persist or inspect it.
Sourcepub const fn version(&self) -> u64
pub const fn version(&self) -> u64
Returns the current version: the number of actions (player and chance) applied so far.
Sourcepub fn into_parts(self) -> (G, G::State, u64, Prng)
pub fn into_parts(self) -> (G, G::State, u64, Prng)
Consumes the session, returning its parts for persistence.