pub struct Game<I, O, F: FnMut(usize) -> f64 = fn(usize) -> f64, R = ThreadRng>{ /* private fields */ }Expand description
The main game controller that manages the pachislot game state and flow.
This struct orchestrates all game components including state management, user input/output handling, lottery system, and command processing. It processes one command at a time from user input in a simplified game loop without command queuing.
§Type Parameters
I: User input handler implementingUserInput<O>O: User output handler implementingUserOutputF: Probability function type implementingFnMut(usize) -> f64R: Random number generator implementingRng
Implementations§
Source§impl<I, O, F, R> Game<I, O, F, R>
impl<I, O, F, R> Game<I, O, F, R>
Sourcepub fn new(config: Config<F>, input: I, output: O) -> Result<Self, ConfigError>
pub fn new(config: Config<F>, input: I, output: O) -> Result<Self, ConfigError>
Creates a new Game instance with the specified configuration and I/O handlers.
§Arguments
config: Game configuration including probabilities and ball settingsinput: User input handleroutput: User output handler
§Returns
Ok(Game)if the configuration is validErr(ConfigError)if the configuration contains invalid values
§Examples
use pachislo::{Game, CONFIG_EXAMPLE};
// Assuming you have input and output handlers
let game = Game::new(CONFIG_EXAMPLE, input, output)?;Source§impl<I, O, F, R> Game<I, O, F, R>
impl<I, O, F, R> Game<I, O, F, R>
Sourcepub fn run_step(&mut self) -> ControlFlow<()>
pub fn run_step(&mut self) -> ControlFlow<()>
Executes a single step of the game loop.
This method waits for user input, processes the returned command, and updates the game state accordingly. It handles user input, executes commands, and manages state transitions in a simplified loop without command queuing.
§Returns
ControlFlow::Continue(())if the game should continue runningControlFlow::Break(())if the game should terminate
Sourcepub fn run_step_with_command(
&mut self,
command: Command<I, O, F, R>,
) -> ControlFlow<()>
pub fn run_step_with_command( &mut self, command: Command<I, O, F, R>, ) -> ControlFlow<()>
Runs a single step of the game with a given command.
This method processes the provided command, updates the game state, and handles any necessary state transitions. It is useful for testing or integrating with external systems that provide commands.
§Parameters
command: The command to execute during this step.
§Returns
ControlFlow::Continue(())if the game should continue runningControlFlow::Break(())if the game should terminate
Sourcepub fn run(&mut self)
pub fn run(&mut self)
Runs the main game loop until termination.
This method continuously calls run_step() until the game decides to terminate.
Use this for a complete game session from start to finish.
Sourcepub fn start(&mut self) -> Result<(), AlreadyStartedError>
pub fn start(&mut self) -> Result<(), AlreadyStartedError>
Starts the game by initializing it with the configured number of balls.
§Returns
Ok(())if the game was successfully startedErr(AlreadyStartedError)if the game is already running
Sourcepub fn finish(&mut self) -> Result<(), UninitializedError>
pub fn finish(&mut self) -> Result<(), UninitializedError>
Finishes the current game session and resets to uninitialized state.
§Returns
Ok(())if the game was successfully finishedErr(UninitializedError)if the game was not running
Sourcepub fn launch_ball(&mut self) -> Result<(), UninitializedError>
pub fn launch_ball(&mut self) -> Result<(), UninitializedError>
Launches a ball in the game.
This decrements the available ball count and may trigger state transitions (e.g., from Rush mode back to Normal mode when rush balls are exhausted).
§Returns
Ok(())if the ball was successfully launchedErr(UninitializedError)if the game is not running
Sourcepub fn cause_lottery(&mut self)
pub fn cause_lottery(&mut self)
Triggers a lottery event based on the current game state.
The lottery behavior depends on whether the game is in Normal or Rush mode:
- In Normal mode: Uses normal lottery probabilities
- In Rush mode: Uses enhanced rush probabilities and handles continuation logic
Winning a lottery may trigger rush mode or continue an existing rush sequence.