This document provides essential information for AI agents working on the Dice Project. Follow these guidelines to maintain consistency and ensure high-quality contributions.
The Dice Project is a lightweight Python CLI tool that simulates rolling one to six dice and displays the results using ASCII art.
- Primary Language: Python 3.x
- Main Entry Point:
dice.py - Architecture: Procedural script with functional decomposition.
To run the interactive CLI:
python dice.pyThere is currently no formal test suite. When adding tests:
- Framework: Use
pytest(standard for this project). - Running all tests:
pytest - Running a single test file:
pytest path/to/test_file.py - Running a specific test:
pytest path/to/test_file.py::test_function_name
Maintain PEP 8 compliance. Recommended tools:
- Linting:
flake8 dice.pyorruff check dice.py - Formatting:
black dice.py
- Simplicity: Keep the logic straightforward. Avoid over-engineering for a single-file utility.
- Readability: Prioritize clear, descriptive names over brevity.
- Functions: Use
snake_case(e.g.,generate_dice_faces_diagram). - Variables: Use
snake_case(e.g.,roll_results). - Constants: Use
SCREAMING_SNAKE_CASE(e.g.,DICE_ART,DIE_HEIGHT). - Internal Helpers: Prefix with a single underscore (e.g.,
_get_dice_faces).
- Place standard library imports at the top of the file.
- Keep them alphabetized within their group.
- Example:
import random import sys
- Use triple-quoted docstrings for all functions.
- The first line should be a concise summary.
- Follow with a more detailed explanation if the function's logic or parameters aren't trivial.
- Example:
def roll_dice(num_dice): """Return a list of random integers between 1 and 6.""" # implementation
- Indentation: 4 spaces.
- Line Length: Max 79-88 characters (standard PEP 8 / Black).
- Vertical Spacing: Two blank lines between top-level functions.
- Use
parse_inputto validate user input. - For fatal CLI errors, print a user-friendly message and use
raise SystemExit(1). - Avoid broad
except Exception:blocks; catch specific exceptions.
- All dice representations are stored in the
DICE_ARTdictionary. - Each entry is a tuple of strings representing the rows of the die.
- Maintain the alignment and character usage (┌, ┐, └, ┘, │, ●) when modifying art.
- Currently, the script executes its main logic at the bottom of the file.
- Refactoring Target: When modifying
dice.py, consider wrapping the execution logic in anif __name__ == "__main__":block to allow for better testability and modularity.
- All user inputs must be stripped and validated against expected values before processing.
- The
parse_inputfunction is the gatekeeper for valid dice counts.
- Cursor Rules: No specific
.cursorrulesor.cursor/rules/detected. - Copilot Instructions: No
.github/copilot-instructions.mddetected. - Standard Guidelines: Default to standard Python best practices (PEP 8, PEP 257).
- Check for side effects: Ensure changes to
DICE_ARTdon't breakgenerate_dice_faces_diagram. - Maintain ASCII alignment: Use
DIE_HEIGHTandDIE_WIDTHconstants to ensure the diagram remains rectangular. - Self-Verification: After making changes, run
python dice.pyand test with various inputs (1, 6, and invalid strings) to ensure the CLI still behaves as expected.
- Ensure that helper functions remain "private" (prefixed with
_) if they are not intended for external use. - Maintain the docstring style and clarity.
- Follow PEP 8 style conventions
- Add type hints to all new and modified functions
- Prefer specific exception types over bare
exceptclauses - Use context managers for file I/O and database connections
- Write descriptive error messages that include the offending value
Note: This file is intended for AI agents. If you are a human, feel free to update these guidelines as the project evolves.