mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-14 21:46:11 +00:00
[PR #1534] [CLOSED] feat: Added a Rock, Paper Scissors #2144
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/TheAlgorithms/C/pull/1534
Author: @davex-ai
Created: 11/24/2025
Status: ❌ Closed
Base:
master← Head:add-rock-paper-scissors📝 Commits (1)
0ff844bfeat: 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.
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.