user can choose a difficulty level when playing stockfish - #8
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 48 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe computer game now supports five typed Stockfish difficulty levels. Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| apps/client/src/constants/stockfish.ts | Defines internally consistent difficulty keys with Elo values within Stockfish’s supported range, resolving the prior unsupported-value issue. |
| apps/client/src/pages/computerGame.tsx | Initializes difficulty with the valid easy key and passes the selected value through the game and sidebar, resolving the prior invalid-default issue. |
| apps/client/src/hooks/game/useStockfish.ts | Applies the selected Elo through UCI options and restarts searches when difficulty changes; no eligible blocking defect was established. |
| apps/client/src/hooks/game/useComputerGame.ts | Propagates the typed difficulty value from the page to the Stockfish hook. |
| apps/client/src/components/chessSidebar.tsx | Renders options directly from the difficulty map, keeping selectable values aligned with the typed configuration. |
| apps/client/tsconfig.json | Adds TypeScript resolution for the new constants alias. |
| apps/client/vite.config.ts | Adds the matching Vite runtime alias for the constants directory. |
Reviews (3): Last reviewed commit: "fix build error" | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/client/src/components/chessSidebar.tsx`:
- Around line 5-14: Update the SideBar component props so setDifficulty and
difficulty remain optional for online-game callers such as playerGame.tsx, and
render the difficulty selector only when both values are available. Preserve the
existing selector behavior for computer games.
- Around line 36-47: Give the difficulty select in the chess sidebar an
accessible name by adding a visible label associated with it via matching id/for
attributes, or an explicit aria-label/aria-labelledby. Keep the existing
difficulty value and change handling unchanged.
In `@apps/client/src/constants/stockfish.ts`:
- Around line 1-6: The difficulties configuration uses unsupported Elo values
for beginner and easy. Update the `difficulties` entries to use Stockfish
18-supported `UCI_Elo` values between 1320 and 3190, or switch those weaker
levels to a supported Stockfish strength control while preserving distinct
difficulty behavior.
In `@apps/client/src/hooks/game/useStockfish.ts`:
- Around line 55-62: Update the Stockfish search lifecycle in the effect
handling `stockfish.postMessage` and its cleanup: track the active search with
an id/state and retain its message handler after cleanup sends stop, ignoring or
completing the replacement only when the cancelled search’s bestmove arrives
before starting the new search. Stabilize the onMove callback via a ref so
rerenders do not reinstall the handler for the same search, while preserving
normal turn and game-over behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2b652247-3b26-44e2-9d22-3ce4340a875b
📒 Files selected for processing (7)
apps/client/src/components/chessSidebar.tsxapps/client/src/constants/stockfish.tsapps/client/src/hooks/game/useComputerGame.tsapps/client/src/hooks/game/useStockfish.tsapps/client/src/pages/computerGame.tsxapps/client/tsconfig.jsonapps/client/vite.config.ts
Note
Add difficulty level selection when playing against Stockfish
difficultiesconstant mapping four levels (easy, medium, hard, expert) to ELO values in a newstockfish.tsconstants module.useStockfishhook now sendsUCI_LimitStrengthandUCI_EloUCI commands based on the selected difficulty, and issuesgo movetime 1000to cap think time.computerGame.tsxmanages difficulty state (defaulting toeasy) and passes it down touseComputerGameand the sidebar.<select>control whensetDifficultyis provided.easy(ELO-limited) instead of playing at full strength.Macroscope summarized 4a7f284.
ComputerChessBoard,useComputerGame, anduseStockfish.@constantspath aliases to the TypeScript and Vite configurations.