Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@TheNipanen
Copy link
Contributor

@TheNipanen TheNipanen commented Jun 22, 2025

Ambiguous moves were being generated in game PGNs as per #44. The reason was that the generator was looking at the predecessor position when determining what information was needed for the current move. This PR fixes the issue.

EDIT: The predecessor position was necessary for processing subvariations in the PGN encode. This was brough back in a more robust way, so that ambiguous moves were fixed while keeping the predecessor position for the subvariations. Also added a test case that captures the example from #44

@CorentinGS CorentinGS requested a review from Copilot June 23, 2025 12:58

This comment was marked as outdated.

@TheNipanen TheNipanen changed the title Fix ambiguous moves in PGN Fix ambiguous moves in PGN; Add PGN test case Jun 28, 2025
@TheNipanen TheNipanen requested a review from Copilot June 30, 2025 12:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the issue of ambiguous moves generated in PGNs by updating the move encoding logic to conditionally use the predecessor position for subvariations while preserving legacy behavior for standard moves. It also adds a new test case to capture the ambiguous move scenario reported in #44.

  • Fix ambiguous move generation in PGN encoding.
  • Update move encoding to use the predecessor position only in subvariation mode.
  • Add a test case to verify the correct PGN output for longer games.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
game_test.go Added a test case ("GameStringWithLongerGame") that verifies PGN output for a longer game sequence.
game.go Modified the writeMoveEncoding function to incorporate a 'subVariation' flag for disambiguation.
Comments suppressed due to low confidence (2)

game.go:494

  • [nitpick] Consider renaming the parameter 'subVariation' to 'isSubVariation' for improved clarity regarding its boolean nature.
func writeMoveEncoding(node *Move, currentMove *Move, subVariation bool, sb *strings.Builder) {

game.go:495

  • Add a comment to explain why the parent's position is used when subVariation is true to enhance clarity on the PGN disambiguation logic.
	if subVariation && node.Parent() != nil {

@TheNipanen
Copy link
Contributor Author

@CorentinGS Could you allow the test workflow to be run? I believe this PR is ready and the new more robust solution fixes the previously failed tests.

@TheNipanen
Copy link
Contributor Author

TheNipanen commented Jul 6, 2025

The error in the latest test run seems to not be related to this PR. It does not happen for me locally and this PR doesn't touch the opening package.

@CorentinGS CorentinGS merged commit 0a2700b into CorentinGS:main Jul 7, 2025
5 of 6 checks passed
@TheNipanen TheNipanen deleted the fix/ambiguous-moves-in-pgn branch October 2, 2025 20:46
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