Build a Wordle-style game in React
Company: Ramp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
## Task
Implement a simplified **Wordle-style** game as a small React app. **No styling/CSS is required** (plain HTML output is fine).
## Game rules (assume Wordle-like defaults)
- The secret word is a fixed **5-letter** English word (you may hardcode it, or pass it in as a prop).
- The player has at most **6 attempts** to guess the word.
- Each guess must be exactly **5 letters** (A–Z). Reject/ignore invalid submissions.
- After each submitted guess, show per-letter feedback:
- **Correct**: the letter is in the correct position.
- **Present**: the letter exists in the secret word but in a different position.
- **Absent**: the letter does not exist in the secret word.
- Letter matching should handle duplicates correctly (e.g., if the secret has one `A`, only one `A` in the guess can be marked as Correct/Present).
## UI/Interaction requirements
- Allow the user to type a guess (e.g., an input box) and submit (e.g., Enter key or a button).
- Display the history of guesses, each with its feedback (text labels are fine, e.g., `C/P/A` per character).
- End state:
- If the user guesses the secret word, show a “You win” message and stop accepting further guesses.
- If the user uses all attempts without guessing correctly, show a “Game over” message and reveal the secret word.
## Clarifications
- You may assume a single round (no need for restart unless you want to add it).
- No backend is required.
- No external UI libraries required.
## Example
Secret: `CRANE`
Guess: `CANDY`
Feedback (conceptually): `C=Correct`, `A=Present`, `N=Present`, `D=Absent`, `Y=Absent`
Quick Answer: This question evaluates proficiency in React-based front-end development, including state and component management, user interaction handling, and algorithmic skills for string comparison and duplicate-letter matching.
Implement the core game engine behind a simplified Wordle-style React app. Write a function that simulates one round of the game.
The function receives a secret 5-letter word and a list of submitted guesses in order. Process guesses until the player wins or 6 valid guesses have been accepted.
Rules:
- A valid guess is exactly 5 alphabetic characters. Invalid guesses are ignored and do not use an attempt.
- Comparison is case-insensitive.
- For each accepted guess, produce a 5-character feedback string using:
- 'C' = correct letter in the correct position
- 'P' = letter exists in the secret word but in a different position
- 'A' = letter does not exist in the secret word
- Duplicate letters must be handled correctly. A guessed letter can only be marked as Correct/Present as many times as it appears in the unmatched part of the secret.
- Stop accepting guesses after a win or after 6 valid guesses.
Return a dictionary with:
- 'history': a list of (GUESS, FEEDBACK) tuples for each accepted guess, using uppercase guesses
- 'status': 'win', 'game_over', or 'incomplete'
- 'secret': the secret word only when status is 'game_over'; otherwise None
Constraints
- secret is a 5-letter English word containing only alphabetic characters
- 0 <= len(guesses) <= 10^4
- Only guesses of length 5 containing letters A-Z count toward the 6-attempt limit
- Processing stops immediately after a win or after 6 valid guesses
Examples
Input: ('CRANE', ['crane'])
Expected Output: {'history': [('CRANE', 'CCCCC')], 'status': 'win', 'secret': None}
Explanation: The first valid guess matches the secret exactly, so the player wins immediately.
Input: ('APPLE', ['ALLEY'])
Expected Output: {'history': [('ALLEY', 'CPAPA')], 'status': 'incomplete', 'secret': None}
Explanation: A is correct, the first L is present, the second L is absent because only one unmatched L remains in the secret, E is present, and Y is absent.
Hints
- Use a two-pass approach for each guess: first mark exact matches, then use remaining letter counts to mark present letters.
- Keep a separate counter for valid guesses, since invalid submissions should be ignored and must not consume an attempt.