Probability-guided number guessing simulator
Project description
Probability-Guided Number Guessing Simulator
A production-grade CLI application for playing number guessing games with intelligent probability-based hints and comprehensive game tracking.
๐ฏ Features
- Probability-Guided Hints: Smart hints based on Bayesian probability analysis
- Multiple Difficulty Levels: Easy, Medium, Hard, and Expert profiles
- Durable Storage: Atomic file operations with JSON storage
- Import/Export: CSV support for data portability
- Comprehensive Logging: Detailed logs for debugging and tracking
- Strict Validation: Clear error messages for all inputs
- Statistics Tracking: Detailed game statistics and performance metrics
- Simple & Clean Code: Easy to understand for learning purposes
๐ฆ Installation
Prerequisites
- Python 3.7 or higher
- No external dependencies (uses only Python standard library)
Install from Source
pip install -e .
After installation, the guess-sim command will be available globally.
๐ Quick Start
# Play a game with default settings (medium difficulty)
python -m guess_simulator.cli play
# Or if installed:
guess-sim play
# Play with specific difficulty
guess-sim play -d hard
# Play with custom range
guess-sim play --min 1 --max 500 -a 15
# Play with verbose output
guess-sim play -v
๐ Usage
Commands
Play a Game
guess-sim play [OPTIONS]
Options:
-d, --difficulty {easy,medium,hard,expert} Difficulty level
--min INTEGER Minimum number
--max INTEGER Maximum number
-a, --attempts INTEGER Maximum attempts
-s, --save Save game after completion
-v, --verbose Verbose output with probability info
Example:
guess-sim play -d expert -s -v
View Statistics
guess-sim stats [OPTIONS]
Options:
-v, --verbose Show detailed statistics and recent games
Example:
guess-sim stats -v
Export Data
guess-sim export [OPTIONS]
Options:
-o, --output PATH Output CSV file path (default: game_export.csv)
Example:
guess-sim export -o my_games.csv
Import Data
guess-sim import -i INPUT_PATH
Options:
-i, --input PATH Input CSV file path (required)
Example:
guess-sim import -i my_games.csv
Manage Configuration
guess-sim config [OPTIONS]
Options:
--list List all available profiles
--show PROFILE Show specific profile settings
Example:
guess-sim config --list
guess-sim config --show hard
๐ฎ Gameplay
When you start a game, you'll see:
============================================================
๐ฎ PROBABILITY-GUIDED NUMBER GUESSING SIMULATOR
============================================================
Difficulty: MEDIUM
Range: 1 - 100
Maximum Attempts: 10
Game ID: a1b2c3d4-e5f6-7890-abcd-ef1234567890
============================================================
Enter your guess (1-100): 50
๐ Too high! Try a lower number.
๐ Attempts: 1/10
Enter your guess (1-100): 25
๐ Too low! Try a higher number.
๐ก Hint: โจ๏ธ Hot! The number is between 26 and 49.
๐ Attempts: 2/10
Hint System
The game provides intelligent hints based on:
-
Temperature Feedback:
- ๐ฅ Very Hot (within 10% of range)
- โจ๏ธ Hot (within 25% of range)
- ๐ก๏ธ Warm (within 50% of range)
- โ๏ธ Cold (within 75% of range)
- ๐ง Very Cold (beyond 75% of range)
-
Probability-Based Range Narrowing:
- When possible numbers drop below threshold, shows exact range
- Displays remaining possibilities in verbose mode
โ๏ธ Configuration
Configuration is hardcoded in config.py with the following profiles:
Difficulty Profiles
| Profile | Range | Max Attempts | Hint Frequency |
|---|---|---|---|
| Easy | 1-50 | 15 | Every 2 guesses |
| Medium | 1-100 | 10 | Every 3 guesses |
| Hard | 1-200 | 8 | Every 4 guesses |
| Expert | 1-500 | 12 | Every 5 guesses |
Storage Settings
format: json (default for easy debugging)data_dir: Directory for storing game data (default: game_data)
๐ Game Statistics
The game tracks comprehensive statistics:
- Total games played
- Win/loss counts and percentages
- Average attempts per game
- Best and worst scores
- Guess history for each game
๐ Project Structure
guess_simulator/
โโโ __init__.py # Package initialization
โโโ cli.py # Command-line interface
โโโ config.py # Configuration management
โโโ game.py # Core game engine
โโโ logger.py # Logging system
โโโ storage.py # Data persistence
โโโ validator.py # Input validation
tests/
โโโ __init__.py
โโโ test_game.py # Game engine tests
โโโ test_storage.py # Storage tests
โโโ test_validator.py # Validation tests
โโโ test_integration.py # Integration tests
๐๏ธ Data Storage
File Structure
game_data/
โโโ games.json # All game records
โโโ statistics.json # Aggregated statistics
game.log # Application logs
Data Format
Games are stored in JSON format:
{
"game_id": "uuid",
"start_time": "2025-11-29T15:30:45",
"end_time": "2025-11-29T15:32:10",
"duration_seconds": 85.5,
"min_number": 1,
"max_number": 100,
"target_number": 42,
"max_attempts": 10,
"attempts": 7,
"guess_history": [50, 25, 37, 43, 40, 41, 42],
"won": true,
"finished": true
}
๐งช Testing
Run the test suite:
# Run all tests
python -m unittest discover tests
# Run specific test module
python -m unittest tests.test_game
# Run with verbose output
python -m unittest discover tests -v
Test Suite: 18 streamlined tests covering all core functionality
Test Coverage
- Unit Tests: Game logic, validation, storage
- Integration Tests: Complete workflows and system integration
- All tests run in ~0.1 seconds
Common Issues
Issue: Command not found after installation
# Solution: Use Python module syntax
python -m guess_simulator.cli play
Issue: Permission denied when saving
# Solution: Check directory permissions
chmod 755 game_data/
Issue: Corrupted data file
# Solution: Delete the corrupted file to start fresh
# Data files are located in game_data/ directory
๐ Design Trade-offs
Storage Format
- Choice: JSON for primary storage
- Rationale: Human-readable, easy debugging, excellent for learning
- Trade-off: Slightly larger file size vs binary formats
- Benefit: Students can open and inspect data files directly
Probability Algorithm
- Choice: Simple Bayesian range narrowing
- Rationale: Easy to understand for 1st-year students
- Trade-off: Not as sophisticated as ML models
- Benefit: Fast, deterministic, explainable
Testing Approach
- Choice: Focused test suite (18 tests)
- Rationale: Covers core functionality without overwhelming complexity
- Trade-off: Fewer edge cases tested
- Benefit: Easy to understand and maintain for beginners
๐จ Limits and Edge Cases
Input Limits
- Number Range: 1 to 2,147,483,647 (max int)
- Max Attempts: 1 to 1000
- String Length: 100 characters max
Edge Cases Handled
- โ Corrupted data files (graceful error handling)
- โ Concurrent access (atomic writes)
- โ Invalid user input (strict validation)
- โ Missing configuration (defaults provided)
- โ Disk full (graceful error handling)
- โ Large datasets (tested with 10,000+ games)
Known Limitations
- Windows: File rename not truly atomic (mitigated with temp files)
- Large ranges (>1M): Probability tracking uses significant memory
- Single-threaded: No async processing (keeps code simple)
๐ License
MIT License - Feel free to use for learning and projects!
๐จโ๐ป Author
Created as a 1st-year college project demonstrating:
- Production-grade Python development
- CLI application design
- Testing and documentation
- Software engineering best practices
๐ค Contributing
This is a learning project, but suggestions are welcome!
- Test your changes thoroughly
- Follow existing code style
- Add tests for new features
- Update documentation
๐ Learning Resources
This project demonstrates:
- argparse: CLI argument parsing
- logging: Professional logging practices
- json/csv: Data serialization
- pathlib: Modern file path handling
- unittest: Testing framework
- OOP principles: Classes, inheritance, encapsulation
- Design patterns: Singleton pattern in logger
- Input validation: Defensive programming
Happy Guessing! ๐ฏ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file guess_simulator-0.1.1.tar.gz.
File metadata
- Download URL: guess_simulator-0.1.1.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d7436af952457dca713be759d6f399c7bb662a77fd353a5db17a797c917792b
|
|
| MD5 |
52aa33f3c1a56b01924a8672c6870a9f
|
|
| BLAKE2b-256 |
3d05ccdda45a541c12fd9e9b9367f5ff12c1687f45ca63e068a3c004e3941a5e
|
File details
Details for the file guess_simulator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: guess_simulator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d184f7171bbfc9b54e42d5f3bc41fdb746ed8b562175e4ff75a3e6b4eb52e10e
|
|
| MD5 |
1a55167391408f8f36705d99bb005bbc
|
|
| BLAKE2b-256 |
f27468606f8300498a8dd84b2299a57bd286b59f2a87726b731593ec37e5033e
|