Skip to main content

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:

  1. 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)
  2. 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!

  1. Test your changes thoroughly
  2. Follow existing code style
  3. Add tests for new features
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

guess_simulator-0.1.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

guess_simulator-0.1.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

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

Hashes for guess_simulator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0d7436af952457dca713be759d6f399c7bb662a77fd353a5db17a797c917792b
MD5 52aa33f3c1a56b01924a8672c6870a9f
BLAKE2b-256 3d05ccdda45a541c12fd9e9b9367f5ff12c1687f45ca63e068a3c004e3941a5e

See more details on using hashes here.

File details

Details for the file guess_simulator-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for guess_simulator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d184f7171bbfc9b54e42d5f3bc41fdb746ed8b562175e4ff75a3e6b4eb52e10e
MD5 1a55167391408f8f36705d99bb005bbc
BLAKE2b-256 f27468606f8300498a8dd84b2299a57bd286b59f2a87726b731593ec37e5033e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page