Skip to main content

Game

Struct Game 

Source
pub struct Game<I, O, F: FnMut(usize) -> f64 = fn(usize) -> f64, R = ThreadRng>
where I: UserInput<O, F, R>, O: UserOutput, R: Rng,
{ /* 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 implementing UserInput<O>
  • O: User output handler implementing UserOutput
  • F: Probability function type implementing FnMut(usize) -> f64
  • R: Random number generator implementing Rng

Implementations§

Source§

impl<I, O, F, R> Game<I, O, F, R>
where I: UserInput<O, F, R>, O: UserOutput, F: FnMut(usize) -> f64, R: Rng + Default,

Source

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 settings
  • input: User input handler
  • output: User output handler
§Returns
  • Ok(Game) if the configuration is valid
  • Err(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)?;
Examples found in repository?
examples/cli.rs (line 17)
12fn main() {
13    let input = CuiInput::new(START_HOLE_PROBABILITY_EXAMPLE);
14
15    let output = CuiOutput::new();
16
17    let mut game = Game::new(CONFIG, input, output).unwrap();
18
19    game.run();
20}
Source§

impl<I, O, F, R> Game<I, O, F, R>
where I: UserInput<O, F, R>, O: UserOutput, F: FnMut(usize) -> f64, R: Rng,

Source

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 running
  • ControlFlow::Break(()) if the game should terminate
Source

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 running
  • ControlFlow::Break(()) if the game should terminate
Source

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.

Examples found in repository?
examples/cli.rs (line 19)
12fn main() {
13    let input = CuiInput::new(START_HOLE_PROBABILITY_EXAMPLE);
14
15    let output = CuiOutput::new();
16
17    let mut game = Game::new(CONFIG, input, output).unwrap();
18
19    game.run();
20}
Source

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 started
  • Err(AlreadyStartedError) if the game is already running
Source

pub fn finish(&mut self) -> Result<(), UninitializedError>

Finishes the current game session and resets to uninitialized state.

§Returns
  • Ok(()) if the game was successfully finished
  • Err(UninitializedError) if the game was not running
Source

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 launched
  • Err(UninitializedError) if the game is not running
Source

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.

Source

pub fn state(&self) -> &GameState

Returns a reference to the current game state.

§Returns

A reference to the current GameState (Uninitialized, Normal, or Rush).

Source

pub fn output(&self) -> &O

Returns a reference to the output handler.

§Returns

A reference to the user output handler for external access.

Auto Trait Implementations§

§

impl<I, O, F, R> Freeze for Game<I, O, F, R>
where I: Freeze, O: Freeze, R: Freeze, F: Freeze,

§

impl<I, O, F, R> RefUnwindSafe for Game<I, O, F, R>

§

impl<I, O, F, R> Send for Game<I, O, F, R>
where I: Send, O: Send, R: Send, F: Send,

§

impl<I, O, F, R> Sync for Game<I, O, F, R>
where I: Sync, O: Sync, R: Sync, F: Sync,

§

impl<I, O, F, R> Unpin for Game<I, O, F, R>
where I: Unpin, O: Unpin, R: Unpin, F: Unpin,

§

impl<I, O, F, R> UnsafeUnpin for Game<I, O, F, R>

§

impl<I, O, F, R> UnwindSafe for Game<I, O, F, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V