Skip to content

Conversation

@nxora
Copy link

@nxora nxora commented Nov 24, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There's no rock papaer scissors game

1 participant