[PR #1534] [CLOSED] feat: Added a Rock, Paper Scissors #2144

Open
opened 2026-01-29 15:29:30 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/TheAlgorithms/C/pull/1534
Author: @davex-ai
Created: 11/24/2025
Status: Closed

Base: masterHead: add-rock-paper-scissors


📝 Commits (1)

  • 0ff844b feat: Added a Rock, Paper Scissors

📊 Changes

1 file changed (+165 additions, -0 deletions)

View changed files

games/rock_paper_scissors.c (+165 -0)

📄 Description

Description (summary)
This PR adds a new Rock–Paper–Scissors command-line game implemented in C. The implementation follows the same structure and style as the existing Hangman template (clean comments, game_instance struct, modular functions). Features include:

Player vs Computer gameplay

Configurable number of rounds

“Play again?” loop to restart without exiting

ASCII art for Rock / Paper / Scissors

Clear, minimal code comments and readable control flow

Simple input validation and score tracking

Motivation / Why

Provides a second example program using the same template style as hangman for consistency and learning.

Useful for teaching program structure, random seeding, and simple game loops.

Adds a lightweight demo project that can be compiled and run without dependencies.

Files added / modified

rps/rps.c — new file: full Rock–Paper–Scissors implementation (main, new_game, play_round, picture, etc.)

(optional) rps/README.md — short usage instructions (if you want me to add this I can include it)

No changes to existing hangman files.

Behavioral changes / Compatibility

No breaking changes to existing code. New program is isolated under rps/.

Build tools unaffected; to compile manually: gcc -o rps rps/rps.c or add to existing Makefile if desired.

How to test / QA steps

Compile: gcc -o rps rps/rps.c

Run: ./rps

Enter number of rounds (e.g., 3) when prompted.

For each round, enter 0 (Rock), 1 (Paper) or 2 (Scissors).

Observe ASCII art, per-round results, and final match result.

When match finishes, respond y/n when prompted with Play again? to verify the loop restarts and resets scores.

Try invalid inputs (e.g., 5, -1, letters) and confirm input validation prompts again.

Note: current implementation checks numeric range; non-numeric input behavior depends on terminal—if you want robust handling for non-numeric input we can add a fgets() + strtol() wrapper.

How many rounds do you want to play? 3

---- Round 1 ----
Choose your move:
[0] Rock
[1] Paper
[2] Scissors
Enter choice: 0

You chose: Rock
Computer chose: Scissors

Your move:
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)

Computer move:
    _______
---'   ____)____
          ______)
       __________)

🟢 You win this round!
Score → You: 1 | Computer: 0

Play again? (y/n):


Implementation notes / decisions

RNG seeded per new_game() with srand(time(NULL)) so each match varies.

Input is validated for numeric range (0–2). If you prefer full string-based validation (to safely handle non-numeric input), I can replace scanf("%d", &player) with fgets() + strtol() parsing.

ASCII art taken from common rock-paper-scissors examples and printed for both player and computer.

Follow-ups / possible improvements (future PRs)

Add Makefile entry for building rps and integration into existing build/test pipeline.

Add README.md in rps/ with usage, compile instructions, and sample output.

Add "best-of-N" convenience helper (auto-calculate rounds required to win).

Improve input robustness: accept rock/paper/scissors text, or keyboard shortcuts.

Add unit tests around any parsing/helper functions (if refactored to be testable).

Related issues / tickets

Closes: #1533


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/TheAlgorithms/C/pull/1534 **Author:** [@davex-ai](https://github.com/davex-ai) **Created:** 11/24/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `add-rock-paper-scissors` --- ### 📝 Commits (1) - [`0ff844b`](https://github.com/TheAlgorithms/C/commit/0ff844bed539ab173b0a0731e861892683c051e5) feat: Added a Rock, Paper Scissors ### 📊 Changes **1 file changed** (+165 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `games/rock_paper_scissors.c` (+165 -0) </details> ### 📄 Description Description (summary) This PR adds a new Rock–Paper–Scissors command-line game implemented in C. The implementation follows the same structure and style as the existing Hangman template (clean comments, game_instance struct, modular functions). Features include: Player vs Computer gameplay Configurable number of rounds “Play again?” loop to restart without exiting ASCII art for Rock / Paper / Scissors Clear, minimal code comments and readable control flow Simple input validation and score tracking Motivation / Why Provides a second example program using the same template style as hangman for consistency and learning. Useful for teaching program structure, random seeding, and simple game loops. Adds a lightweight demo project that can be compiled and run without dependencies. Files added / modified rps/rps.c — new file: full Rock–Paper–Scissors implementation (main, new_game, play_round, picture, etc.) (optional) rps/README.md — short usage instructions (if you want me to add this I can include it) No changes to existing hangman files. Behavioral changes / Compatibility No breaking changes to existing code. New program is isolated under rps/. Build tools unaffected; to compile manually: gcc -o rps rps/rps.c or add to existing Makefile if desired. How to test / QA steps Compile: gcc -o rps rps/rps.c Run: ./rps Enter number of rounds (e.g., 3) when prompted. For each round, enter 0 (Rock), 1 (Paper) or 2 (Scissors). Observe ASCII art, per-round results, and final match result. When match finishes, respond y/n when prompted with Play again? to verify the loop restarts and resets scores. Try invalid inputs (e.g., 5, -1, letters) and confirm input validation prompts again. Note: current implementation checks numeric range; non-numeric input behavior depends on terminal—if you want robust handling for non-numeric input we can add a fgets() + strtol() wrapper. ```yaml How many rounds do you want to play? 3 ---- Round 1 ---- Choose your move: [0] Rock [1] Paper [2] Scissors Enter choice: 0 You chose: Rock Computer chose: Scissors Your move: _______ ---' ____) (_____) (_____) (____) ---.__(___) Computer move: _______ ---' ____)____ ______) __________) 🟢 You win this round! Score → You: 1 | Computer: 0 Play again? (y/n): ``` Implementation notes / decisions RNG seeded per new_game() with srand(time(NULL)) so each match varies. Input is validated for numeric range (0–2). If you prefer full string-based validation (to safely handle non-numeric input), I can replace scanf("%d", &player) with fgets() + strtol() parsing. ASCII art taken from common rock-paper-scissors examples and printed for both player and computer. Follow-ups / possible improvements (future PRs) Add Makefile entry for building rps and integration into existing build/test pipeline. Add README.md in rps/ with usage, compile instructions, and sample output. Add "best-of-N" convenience helper (auto-calculate rounds required to win). Improve input robustness: accept rock/paper/scissors text, or keyboard shortcuts. Add unit tests around any parsing/helper functions (if refactored to be testable). Related issues / tickets Closes: #1533 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 15:29:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#2144