-
Notifications
You must be signed in to change notification settings - Fork 14
feat: enhance UCI move handling with position context and add tests #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes update how UCI commands are processed. In the Changes
Sequence Diagram(s)sequenceDiagram
participant Tester as Test_UCIMovesTags
participant Engine
participant CmdGo
Tester->>Engine: Initialize engine with StockfishPath and set UCI options
Engine->>Engine: Update position via processCommand (CmdPosition)
Tester->>Engine: Send position command & request best move
Engine->>CmdGo: Invoke ProcessResponse with current position context
CmdGo->>CmdGo: Decode best and ponder moves using provided position
CmdGo-->>Engine: Return decoded moves
Engine-->>Tester: Provide best move and ponder move
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Next steps :
Things to consider :
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #30 +/- ##
==========================================
- Coverage 70.66% 70.48% -0.19%
==========================================
Files 27 27
Lines 4480 4492 +12
==========================================
Hits 3166 3166
- Misses 1178 1190 +12
Partials 136 136 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
uci/engine.go (1)
173-178:Details
❓ Verification inconclusive
Position tracking in processCommand is incomplete
The current implementation sets
e.positionwhen aCmdPositionis received, but there's no handling for when a position changes through other methods (such as moves being applied). Consider documenting this limitation or expanding the position tracking.Additionally, consider adding tests for this new functionality as the static analysis indicates these lines aren't covered.
🏁 Script executed:
#!/bin/bash # Check for test coverage of the position field update logic rg -A 3 "Test.*Position" --type goLength of output: 803
Clarify UCI processCommand Position Handling
In
uci/engine.go(lines 173–178), the position is updated only when aCmdPositioncommand is received. Although tests in files likeposition_test.go,move_test.go, andgame_test.goconfirm overall position functionality in the system, it isn’t clear that they exercise this specific UCI code path.
- Verify whether move-induced position updates are intended to be handled elsewhere.
- If the UCI engine should reflect position changes from moves, consider extending the logic in
processCommandand add tests specifically targeting theCmdPositionhandling.- Otherwise, document that
processCommandonly updatese.positionin response to an explicitCmdPositioncommand.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 173-178: uci/engine.go#L173-L178
Added lines #L173 - L178 were not covered by testsuci/cmd.go (1)
298-304: Position context now used for move decodingThis is a good enhancement that uses the position context when decoding moves from UCI notation. This addresses the PR objective to enhance UCI move handling with position context.
However, the declaration of the
positionvariable adds unnecessary complexity to the code.Consider simplifying this logic:
-var position *chess.Position -if e.position != nil { - position = e.position.Position -} else { - position = nil -} -bestMove, err := chess.UCINotation{}.Decode(position, parts[1]) +bestMove, err := chess.UCINotation{}.Decode(e.position != nil ? e.position.Position : nil, parts[1])Or for better readability:
-var position *chess.Position -if e.position != nil { - position = e.position.Position -} else { - position = nil -} -bestMove, err := chess.UCINotation{}.Decode(position, parts[1]) +// Use position context if available +positionContext := e.position != nil ? e.position.Position : nil +bestMove, err := chess.UCINotation{}.Decode(positionContext, parts[1])🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 298-304: uci/cmd.go#L298-L304
Added lines #L298 - L304 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.gitignore(1 hunks)uci/cmd.go(1 hunks)uci/engine.go(3 hunks)uci/engine_test.go(2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
uci/cmd.go (2)
position.go (1)
Position(71-80)notation.go (4)
UCINotation(102-102)UCINotation(106-108)UCINotation(111-128)UCINotation(131-171)
uci/engine_test.go (7)
uci/engine.go (1)
New(45-63)uci/cmd.go (5)
CmdSetOption(137-140)CmdPosition(157-160)CmdPosition(178-180)CmdGo(222-235)CmdGo(286-327)position.go (2)
Position(71-80)StartingPosition(88-91)game.go (3)
NewGame(163-183)Outcome(34-34)NoOutcome(38-38)notation.go (4)
AlgebraicNotation(176-176)AlgebraicNotation(180-182)AlgebraicNotation(185-225)AlgebraicNotation(335-370)uci/info.go (1)
SearchResults(16-20)move.go (1)
Capture(14-14)
🪛 GitHub Check: codecov/patch
uci/cmd.go
[warning] 298-304: uci/cmd.go#L298-L304
Added lines #L298 - L304 were not covered by tests
[warning] 310-310: uci/cmd.go#L310
Added line #L310 was not covered by tests
uci/engine.go
[warning] 55-55: uci/engine.go#L55
Added line #L55 was not covered by tests
[warning] 173-178: uci/engine.go#L173-L178
Added lines #L173 - L178 were not covered by tests
🔇 Additional comments (5)
.gitignore (1)
31-32: LGTM: Ignoring IDE and chess engine binariesAdding the
.ideaandstockfishentries to the gitignore is sensible. This ensures JetBrains IDE files and Stockfish binaries aren't accidentally committed to the repository.uci/engine.go (2)
16-25: New position field added to Engine structThe position field has been added to the Engine struct to maintain the current command position, which enables position context-aware move handling. This change is inline with the PR objectives to enhance UCI move handling with position context.
55-55:Details
✅ Verification successful
Engine initialization now includes position context
Good change to initialize the position field during Engine creation.
🏁 Script executed:
#!/bin/bash # Check if the Engine.position field is properly used in other files rg -A 5 -B 5 "e\.position" --type goLength of output: 5080
Engine Initialization with Position Context – Approved
The updated Engine initialization correctly sets the
positionfield, and our verification confirms its proper usage across the codebase (e.g., inuci/cmd.go,pgn.go, andgame.go). This integration aligns with how positional context is managed in subsequent command and game state processing.No further changes are necessary.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 55-55: uci/engine.go#L55
Added line #L55 was not covered by testsuci/cmd.go (1)
310-310: Position context now used for ponder move decodingConsistent with the best move decoding, the ponder move decoding now uses the position context. This ensures move tagging (captures, castling, etc.) works properly for ponder moves as well.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 310-310: uci/cmd.go#L310
Added line #L310 was not covered by testsuci/engine_test.go (1)
26-59: New test added for UCI moves with position contextThis is a valuable addition that tests the UCI move handling with actual position context, which is the core functionality being enhanced in this PR. The test creates a complete game by repeatedly requesting moves from the engine and applying them, verifying that the moves are properly decoded and applied.
However, the test is currently skipped with
t.SkipNow(). This means the new position-aware move handling functionality isn't being automatically verified.Consider enabling this test by removing or conditionally using
t.SkipNow()when the PR is finalized. You could use an environment variable or build tag to control when the test runs:-t.SkipNow() +if os.Getenv("RUN_STOCKFISH_TESTS") != "true" { + t.Skip("Skipping stockfish test; set RUN_STOCKFISH_TESTS=true to run") +}Additionally, consider adding a smaller, more focused test that specifically verifies the position-aware move decoding without requiring a full game simulation.
Summary by CodeRabbit