feat: add adaptive AI opponent with difficulty levels and interactive UI enhancements#607
Conversation
…-bell-92#526) - Web (js/projects/rock-paper-scissor.js): - Implement Markov-chain + frequency blend adaptive AI engine - AI observes player history (last 20 moves) to predict next move - Plays counter-move 75% of time, random 25% for balanced gameplay - Add live 'Computer Brain Analysis' glassmorphic dashboard panel showing: AI mode, player favourite, predicted move, counter-move, confidence %, and round-result history dots - Persist player history in localStorage across page reloads - Fix: remove duplicate getRockPaperScissorHTML/initRockPaperScissor from projects.js so modular file is correctly loaded - Preserve all existing features: stats grid, keyboard shortcuts, comp-card reveals, streak/best-score tracking - Python CLI (games/Rock-Paper-Scissor/Rock-Paper-Scissor.py): - Same blended Markov + frequency prediction engine - 70% adaptive counter / 30% random for fairness - Print 'Computer Brain' status block each round once MIN_ADAPTIVE moves are recorded (favourite move, prediction, confidence, mode) - Show most-played move in statistics summary
…ctHTML The old registry had two blocks: 1. Lines 9-32: eagerly-invoked (called immediately on object creation) 2. Lines 33-67: lazy arrow functions (called only when modal opens) Duplicate keys meant JS used the second block's value — but the first block still executed ALL functions eagerly, meaning any single broken or missing function (e.g. getsnakeGameHTML with wrong casing) would throw a TypeError and crash the entire projects object for every game click, leaving every modal blank. Fix: consolidate into one clean registry of lazy arrow functions only.
- Redesigned Rock Paper Scissors with animated arena, shake-reveal computer choice, clash effects, color-coded results, difficulty tabs (Easy/Medium/Hard), live tendency bar, and adaptive AI - Removed duplicate RPS functions from projects.js (now solely in js/projects/rock-paper-scissor.js) - Fixed dual search input bug: renamed hero search to heroSearchInput, synced both inputs for filtering - Fixed snake game: removed broken nested restartGame() that shadowed the outer function, made Start Game button properly reset state
…ping tester, search, and RPS features
|
@Mudita-Singh is attempting to deploy a commit to the Anuj's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Mudita-Singh why did you changed snake game file if this PR addresses only RPS game |
|
@steam-bell-92 Thanks for pointing that out. The changes in the Snake game file were not intended as a feature change for this PR. While resolving merge conflicts, I retained the existing fixes related to the Snake game (start/restart functionality and movement controls) to avoid regressions. No new Snake game functionality was introduced as part of this PR , the primary focus remains the Rock Paper Scissors adaptive AI and UI enhancements. If you'd prefer, I can remove the unrelated Snake file changes and keep this PR strictly scoped to the RPS implementation. |
|
🎉 Thank you for your contribution! Your Pull Request has been merged successfully. We appreciate the time and effort you put into improving this project. Contributions like yours help the repository grow and stay useful for everyone. If you'd like to contribute again, please check the open issues and make sure you are assigned before opening another Pull Request. Thanks again for your support! 🙌 |
Summary
This PR transforms Rock Paper Scissors from a purely random-choice game into a more interactive and strategic experience.
Previously, the computer selected its moves entirely at random:
computerChoice = choices[Math.floor(Math.random() * choices.length)];
The new implementation introduces adaptive move selection based on player history, configurable difficulty levels, and several UI/UX improvements that make the game feel more responsive and engaging while maintaining fair gameplay.
🎯 Adaptive Computer Opponent
Replaced purely random move generation with a history-based adaptive strategy.
Computer analyzes recent player choices and predicts likely future moves.
Selects counter moves with a difficulty-dependent probability.
Falls back to randomness when insufficient history is available.
⚖️ Difficulty Levels
Added Easy, Medium, and Hard difficulty modes.
Easy: Mostly random behavior.
Medium: Moderate adaptation (35% counter chance).
Hard: Stronger adaptation (55% counter chance).
Default difficulty changed from Hard to Medium for a more balanced experience.
Increased adaptation threshold from 3 rounds to 5 rounds to reduce premature pattern detection.
✨ Interactive Redesign
Difficulty tabs (Easy / Medium / Hard).
Animated computer move reveal.
Clash effects (💥 🤝 💀).
Color-coded result animations.
Live Rock/Paper/Scissors tendency tracking.
Button lockout during animations.
Keyboard hints (R / P / S).
Compact modal-friendly layout.
Testing
Verified adaptive behavior across all difficulty levels.
Verified random fallback logic.
Tested win/loss/tie outcomes.
Tested animation flow and button lockout.
Tested tendency bar updates.
Tested keyboard shortcuts.
Tested responsive layout.
Fixes #526.
📸 Screenshots
Enhanced Rock Paper Scissors Interface