5 unstable releases
Uses new Rust 2024
| 0.3.2 | Sep 3, 2025 |
|---|---|
| 0.3.1 | Sep 3, 2025 |
| 0.3.0 | Sep 2, 2025 |
| 0.2.0 | Aug 30, 2025 |
| 0.1.0 | Aug 30, 2025 |
#305 in Configuration
143 downloads per month
62KB
653 lines
Pachislo Game Simulator
A Rust-based simulation library for Japanese pachislo (slot machine) games, featuring configurable probability systems, realistic game state management, and extensible user interfaces.
Features
- Comprehensive Game State Management: Support for Uninitialized, Normal, and Rush game modes with seamless transitions
- Advanced Lottery System: Realistic probability-based lottery with configurable win/loss rates and fake results
- Sophisticated Slot Result Generation: Multi-reel slot machine simulation with customizable symbols and patterns
- Extensible Command System: Flexible command pattern architecture for game control and flow management
- Trait-based Interface Architecture: Generic input/output system supporting multiple UI implementations
- Rush Mode Mechanics: Advanced rush continuation system with decay probability functions
- Ball Management System: Comprehensive ball tracking with configurable rewards and increments
Game Modes
Normal Mode
- Standard pachislo gameplay with configurable base win probability
- Ball consumption and management with incremental rewards
- Automatic transition to Rush mode upon winning lottery
- Support for fake win/lose results to enhance realism
Rush Mode
- Enhanced win probability during rush periods (default: 48% vs 16% in normal mode)
- Dynamic rush continuation system with decreasing probability over time
- Bonus ball distribution system with rush-specific increments
- Configurable rush continuation decay function
Architecture
The simulator is built around several core components:
Game<I, O>: Main game controller with generic input/output interfacesGameState: State machine managing game progression (Uninitialized → Normal → Rush)Lottery: Advanced probability-based system handling win/loss determination with fake resultsSlotProducer<T>: Configurable slot machine result generator supporting custom symbolsLaunchBallFlowProducer: Manages ball launch mechanics and start hole probabilityConfig: Comprehensive configuration system for all game parameters
Quick Start
use pachislo::{Game, CONFIG_EXAMPLE};
// Create game with your input/output implementations
let mut game = Game::new(CONFIG_EXAMPLE, your_input, your_output).unwrap();
// Run the game loop
game.run();
Configuration
The game supports extensive configuration through the Config struct:
pub struct Config {
pub balls: BallsConfig, // Ball management settings
pub probability: Probability, // Win/loss probabilities
}
Ball Configuration
BallsConfig {
init_balls: 1000, // Starting number of balls
incremental_balls: 15, // Balls awarded on normal win
incremental_rush: 300, // Additional balls during rush mode
}
Probability Configuration
Probability {
normal: SlotProbability {
win: 0.16, // Base win probability
fake_win: 0.3, // Fake win after actual win
fake_lose: 0.15, // Fake lose after actual lose
},
rush: SlotProbability {
win: 0.48, // Enhanced rush win probability
fake_win: 0.2, // Rush fake win probability
fake_lose: 0.05, // Rush fake lose probability
},
rush_continue: SlotProbability {
win: 0.8, // Rush continuation base probability
fake_win: 0.25, // Rush continuation fake win
fake_lose: 0.1, // Rush continuation fake lose
},
// Decay function: 0.6^(n-1) where n is rush count
rush_continue_fn: |n| 0.6f64.powi(n as i32 - 1),
}
Commands
The simulator supports the following command system:
StartGame: Initialize a new game session from uninitialized stateLaunchBallFlowProducer: Advanced ball launching with start hole probabilityFinishGame: End the current game session gracefullyCommand::FinishGame: Force terminate the game loop
Example: CLI Implementation
The project includes a complete CLI example demonstrating all features:
# Run the CLI example
cargo run --example cli
Controls:
s- Start new gamelorEnter- Launch ballq- Finish current gameq!- Force quit
Extending the Simulator
Custom Input/Output Implementation
Implement the UserInput<O> and UserOutput traits:
impl UserInput<MyOutput> for MyInput {
fn wait_for_input(&mut self) -> Command<Self, MyOutput> {
// Handle user input and return command
}
}
impl UserOutput for MyOutput {
fn default(&mut self, state: Transition) {
// Handle state transitions
}
fn finish_game(&mut self, state: &GameState) {
// Handle game completion
}
fn lottery_normal(&mut self, result: LotteryResult) {
// Display normal mode lottery results
}
fn lottery_rush(&mut self, result: LotteryResult) {
// Display rush mode lottery results
}
fn lottery_rush_continue(&mut self, result: LotteryResult) {
// Display rush continuation results
}
}
Custom Slot Symbols
Create slot machines with custom symbols:
let slot_producer = SlotProducer::new(3, vec!['🍒', '🍋', '🔔', '⭐']);
Project Structure
pachislo/src/lib.rs- Main library exports and example configgame.rs- Core game logic and state managementcommand.rs- Command pattern implementationconfig.rs- Configuration structuresinterface.rs- User input/output traitslottery.rs- Lottery probability systemslot.rs- Slot machine result generation
examples/cli.rs- Complete CLI implementation
tests/- Comprehensive test suiteCargo.toml- Project configuration
Dependencies
rand 0.9.1: High-quality random number generation for lottery and slot systems
Development
# Run tests
cargo test
# Run CLI example
cargo run --example cli
# Build documentation
cargo doc --open
# Check code formatting
cargo fmt --check
# Run clippy linting
cargo clippy
License
This project is licensed under the terms specified in the LICENSE file.
Contributing
Contributions are welcome! Please ensure all tests pass and follow the existing code style.
Dependencies
~375KB