Skip to main content

A production-grade CLI for probability-guided number guessing games

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: JSON storage with robust file operations
  • 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
  • Maximum Compatibility: Works with Python 2.7+ and all Python 3.x versions
  • Basic Dependencies Only: Uses only core Python standard library modules

๐Ÿ“ฆ Installation

Prerequisites

  • Python 2.7+ or Python 3.x (any version)
  • No external dependencies (uses only basic Python standard library)
  • Maximum compatibility - works on virtually any Python installation

Install from Source

# Clone or download the project
cd Project_Source

# Install in development mode (editable install)
pip install -e .
# Or if pip is not available, use:
pip3 install -e .

# Or install normally
pip install .   # Use pip3 if pip is not available

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: game-1701516845123-456789
============================================================

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": "game-1701516845123-456789",
  "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

๐Ÿ”ง Troubleshooting

See TROUBLESHOOTING.md for detailed troubleshooting guide.

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

Simplified Dependencies

  • Choice: Basic Python standard library only (no pathlib, datetime, uuid, typing)
  • Rationale: Maximum compatibility across Python versions (2.7+ and all 3.x)
  • Trade-off: Slightly more verbose code (e.g., os.path.join() vs Path() / file)
  • Benefit: Works on any Python installation without version constraints

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)
  • โœ… Invalid user input (strict validation)
  • โœ… Missing configuration (defaults provided)
  • โœ… Disk full (graceful error handling)
  • โœ… Large datasets (tested with 10,000+ games)

Known Limitations

  • Large ranges (>1M): Probability tracking uses significant memory
  • Single-threaded: No async processing (keeps code simple)
  • No static type checking (typing module not used for maximum compatibility)

๐Ÿ“„ 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
  • os module: File and directory operations
  • time module: Timestamp handling and formatting
  • unittest: Testing framework
  • OOP principles: Classes, inheritance, encapsulation
  • Design patterns: Singleton pattern in logger
  • Input validation: Defensive programming
  • Compatibility: Writing cross-version Python code

๐Ÿ”ง Technical Details

Python Modules Used

The project uses only basic Python standard library modules for maximum compatibility:

Core Modules:

  • argparse - Command-line interface
  • sys - System operations
  • os - File/directory operations
  • json - Data persistence
  • csv - Import/export functionality
  • logging - Application logging
  • random - Random number generation
  • time - Timestamp management
  • unittest - Test framework

Modules NOT Used (for compatibility):

  • โŒ pathlib - Replaced with os.path
  • โŒ datetime - Replaced with time module
  • โŒ uuid - Custom ID generator using time + random
  • โŒ typing - No type hints (works on Python 2.7+)
  • โŒ tempfile - Fixed test directories
  • โŒ shutil - Custom directory removal

This design choice ensures the project runs on Python 2.7 through Python 3.13+ without any modifications!


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

omar_ayush_guess_simulator-1.0.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

omar_ayush_guess_simulator-1.0.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file omar_ayush_guess_simulator-1.0.0.tar.gz.

File metadata

File hashes

Hashes for omar_ayush_guess_simulator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb005b2bdf3daa69cabfae0ace0505188b4022eb814cb88e6bfd4118787b7cb5
MD5 17f28bf047251edf5ae00b914ae61656
BLAKE2b-256 3f6213a684508e60427e51cf64d3b4bc395e264e2306682b0cb54c875e87e1fb

See more details on using hashes here.

File details

Details for the file omar_ayush_guess_simulator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for omar_ayush_guess_simulator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 866100c6cb67aa5ae60dd28128f8b5858b476f24844ff6217e50b963683fd4a0
MD5 7183ae31598e8527be7348154d59d8bd
BLAKE2b-256 a46cb58d755ba221519462410a45fe243bfd185221de8c92d75838b2b727c23c

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