Skip to main content

A modular framework for Rock-Paper-Scissors game.

Project description

Modular Framework for the Rock-Paper-Scissors Game.

Rock Paper Scissors image

A solo game of "Rock, Paper, Scissors" against the computer, implemented in modern Python.

Purpose

This project provides a modular and extensible framework for creating and experimenting with the Rock-Paper-Scissors game and its variants.

While the default game implements the classic three-choice version (Rock, Paper, Scissors) with a simple Terminal interface, the architecture supports:

  • Adding more choices with cyclic rules (e.g., Rock-Paper-Scissors-Lizard-Batman).
  • Adding a more complex or graphical interface.
  • Customising input handling and game logic.
  • Adding more players.
  • Adding more advanced strategies for the computer player.
  • Defining new rules and behaviors.

Overview

A dynamic implementation of "Rock, Paper, Scissors" against the computer, with support for additional choices. The game uses cyclic rules to determine the winner, ensuring every option beats some choices and is beaten by an equal number of other choices, thus there must be an odd number of choices.

Features

  • Play the classic version of "Rock, Paper, Scissors."
  • Extend the game with custom rules, more choices, or alternative user interface.
  • Unit tests (pytest) are provided to validate game logic.

How It Works

Rather than hard coded "Scissor beats Paper" rules, the game generates rules dynamically from a list of choices, following the rules:

  1. Each item beats (n-1)//2 predecessors and is beaten by (n-1)//2 successors, where n is the total number of choices.
  2. The total number of choices (DEFAULT_CHOICE_NAMES) must always be odd.
  3. Choices cannot start with the letter 'Q' (reserved for "Quit").
  4. All choices must start with a unique letter.

Example Custom Configuration

An example configuration with five options:

DEFAULT_CHOICE_NAMES = ('Rock', 'Batman', 'Paper', 'Lizard', 'Scissors')

The corresponding rules would be:

  • Rock blunts Scissors: Rock wins.
  • Rock crushes Lizard: Rock wins.
  • Batman vaporizes Rock: Batman wins.
  • Batman smashes Scissors: Batman wins.
  • Paper disproves Batman: Paper wins.
  • Paper wraps Rock: Paper wins.
  • Lizard eats Paper: Lizard wins.
  • Lizard poisons Batman: Lizard wins.
  • Scissors decapitate Lizard: Scissors win.
  • Scissors cut Paper: Scissors win.
  • Draw: Both choose the same option.

If you make changes to DEFAULT_CHOICE_NAMES, ensure that you run test_default_choices.py.

Getting Started

Prerequisites

  • Python 3.10.11 or later.
  • Pytest (for running unit tests)

See the pyproject.toml file for full details.

Running the game

It is not necessary to install this game to run it, though instructions for installing are provided in the Installation section.

The quickest way to run the latest version of the game is to simply download the raw .py file from the GitHub Repository and run it from a terminal window:

python3 /path/to/rsp.py

Cloning this repository:

git clone https://github.com/JamzTyson/Rock_Scissors_Paper.git

Running the game from the cloned repository:

Navigate to the project directory:

cd rock_scissors_paper_framework

And then launch the game with:

python3 rsp.py

Installing the Game

Installing from PyPi

The recommended way to install the game is to install for the current user with pipx.

pipx install rock-scissors-paper-framework

Note: The PyPI package name is rock-scissors-paper-framework, but the package is imported as rock_scissors_paper_framework in your Python code. After installation, the main entry point for the game is the rsp command or rsp.py.

If you prefer local development or customisation, install the package within a virtual environment:

# Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate  # On Windows, use: venv\Scripts\activate

# Install the package using pip (or pipx):
pip install rock-scissors-paper-framework

 # Run the application:
rsp

 # Deactivate the virtual environment when finished:
deactivate

How to Play

  1. Start the game by running rsp.py
  2. When prompted, choose an option by typing its initial letter (e.g., R for Rock, S for Scissors). The input is case-insensitive.
  3. The computer selects its option randomly.
  4. The winner is determined based on the predefined rules.
  5. Type Q to quit the game.

Note: If the game has been installed, the rsp.py file can be run using the command:

$ rsp

Example Session:

Player: 0 | Computer: 0

[R]ock, [P]aper, [S]cissors, or [Q] to quit:

Player enters R, S, or P (case-insensitive):

r
You = Rock : Computer = Scissors : YOU WIN
Player: 1 | Computer: 0

Default Rules:

  • Rock blunts Scissors: Rock wins.
  • Scissors cut Paper: Scissors win.
  • Paper wraps Rock: Paper wins.
  • Draw: Both choose the same option.

Contributing

Contributions are welcome!

If you encounter any bugs, please open an issue on the GitHub repository.

If you have ideas for new features, extended rules, or bug fixes, feel free to submit a pull request. Please ensure your changes are well-documented and are accompanied by pytests (if applicable).

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author: JamzTyson

For inquiries, reach out through GitHub issues or discussions.

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

rock_scissors_paper_framework-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

rock_scissors_paper_framework-1.0.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for rock_scissors_paper_framework-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a10a5f82fc800279f2834d7357f3bc009cd10bc7ed94ad785295f6439a063ccb
MD5 2c279703815a32ac5782ad8198e2e948
BLAKE2b-256 8b6323cd5f9ff881fad6b971d0561268c68439d3f69a61a753f0f689f5935f77

See more details on using hashes here.

Provenance

The following attestation bundles were made for rock_scissors_paper_framework-1.0.0.tar.gz:

Publisher: python-publish.yml on JamzTyson/Rock_Scissors_Paper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for rock_scissors_paper_framework-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c53e3557f72a7e8fae6f55d628286d502eaecacf89da4240645e259698bf52fd
MD5 8afefa9ecaad34ceae8f773f4efbd29b
BLAKE2b-256 3ccdf8434dfcba84037fec00e8601a06f74655898411f82e1ddca8fede289fae

See more details on using hashes here.

Provenance

The following attestation bundles were made for rock_scissors_paper_framework-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on JamzTyson/Rock_Scissors_Paper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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