Skip to content

user can choose a difficulty level when playing stockfish - #8

Merged
MohamedSayed0573 merged 4 commits into
mainfrom
feat/stockfish-difficulties
Aug 9, 2026
Merged

user can choose a difficulty level when playing stockfish#8
MohamedSayed0573 merged 4 commits into
mainfrom
feat/stockfish-difficulties

Conversation

@MohamedSayed0573

@MohamedSayed0573 MohamedSayed0573 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Note

Add difficulty level selection when playing against Stockfish

  • Adds a difficulties constant mapping four levels (easy, medium, hard, expert) to ELO values in a new stockfish.ts constants module.
  • The useStockfish hook now sends UCI_LimitStrength and UCI_Elo UCI commands based on the selected difficulty, and issues go movetime 1000 to cap think time.
  • computerGame.tsx manages difficulty state (defaulting to easy) and passes it down to useComputerGame and the sidebar.
  • The sidebar renders a difficulty <select> control when setDifficulty is provided.
  • Behavioral Change: Stockfish now defaults to easy (ELO-limited) instead of playing at full strength.

Macroscope summarized 4a7f284.

  • Add Stockfish difficulty levels from beginner to expert with Elo-based settings.
  • Add a difficulty selector to the chess sidebar.
  • Pass the selected difficulty through ComputerChessBoard, useComputerGame, and useStockfish.
  • Configure Stockfish with the selected Elo rating and a one-second search limit.
  • Add @constants path aliases to the TypeScript and Vite configurations.

@MohamedSayed0573
MohamedSayed0573 requested a balanced review from Copilot August 9, 2026 01:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chesslab Ready Ready Preview Aug 9, 2026 1:34am

@MohamedSayed0573 MohamedSayed0573 changed the title use can choose a difficulty level when playing stockfish user can choose a difficulty level when playing stockfish Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MohamedSayed0573, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e0dc75ad-2ed3-400c-9b0f-1f554475adfc

📥 Commits

Reviewing files that changed from the base of the PR and between d7d6034 and 4a7f284.

📒 Files selected for processing (3)
  • apps/client/src/components/chessSidebar.tsx
  • apps/client/src/constants/stockfish.ts
  • apps/client/src/pages/computerGame.tsx
📝 Walkthrough

Walkthrough

The computer game now supports five typed Stockfish difficulty levels. ComputerChessBoard stores the selected difficulty and passes it to the game hook and sidebar. The sidebar renders a controlled selector. Stockfish uses the selected Elo rating and applies depth and time limits. New TypeScript and Vite aliases support imports from the constants directory.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: users can choose a Stockfish difficulty level.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread apps/client/src/constants/stockfish.ts
@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds a selectable Stockfish difficulty and propagates it from the computer-game page into the engine configuration.

  • Defines four difficulty levels using Elo values supported by the bundled engine.
  • Adds the difficulty selector to the computer-game sidebar.
  • Configures Stockfish strength before searches and limits searches to one second.
  • Adds the @constants alias to TypeScript and Vite configuration.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported unsupported Elo values and invalid default difficulty key are corrected at the current head.

Important Files Changed

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

Comment thread apps/client/src/constants/stockfish.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 039e0e9 and d7d6034.

📒 Files selected for processing (7)
  • apps/client/src/components/chessSidebar.tsx
  • apps/client/src/constants/stockfish.ts
  • apps/client/src/hooks/game/useComputerGame.ts
  • apps/client/src/hooks/game/useStockfish.ts
  • apps/client/src/pages/computerGame.tsx
  • apps/client/tsconfig.json
  • apps/client/vite.config.ts

Comment thread apps/client/src/components/chessSidebar.tsx Outdated
Comment thread apps/client/src/components/chessSidebar.tsx Outdated
Comment thread apps/client/src/constants/stockfish.ts
Comment thread apps/client/src/hooks/game/useStockfish.ts
Comment thread apps/client/src/pages/computerGame.tsx Outdated
@MohamedSayed0573
MohamedSayed0573 merged commit b1e93d8 into main Aug 9, 2026
5 checks passed
@MohamedSayed0573
MohamedSayed0573 deleted the feat/stockfish-difficulties branch August 9, 2026 01:34
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.

2 participants