feat: Added a Rock, Paper Scissors#1534
Closed
davex-ai wants to merge 1 commit intoTheAlgorithms:masterfrom
Closed
feat: Added a Rock, Paper Scissors#1534davex-ai wants to merge 1 commit intoTheAlgorithms:masterfrom
davex-ai wants to merge 1 commit intoTheAlgorithms:masterfrom
Conversation
Contributor
|
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Contributor
|
Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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