Skip to content

SAN disambiguation counts pinned pieces, so moves get an unneeded file or rank #99

Closed

Description

@TMHSDigital

Summary

The move list and exported PGN add a file or rank to a move when another piece of the same type could reach the square by its movement pattern, even if that piece is pinned and cannot legally move. Standard notation disambiguates only among legal moves.

Where

  • js/game.js:1726 (generateNotationWithDisambiguation, the rival search at lines 1736 to 1742)
  • js/rules.js:335 (findSANMove, the reader, filters legal moves)

Details

The rival search uses isPseudoLegalMove plus isPathObstructed on the pre-move board and never checks that the rival's move is legal. The reader in rules.js uses allLegalMoves, so the two halves of the PGN round trip decide "which pieces could go there" differently.

The function also reads the globals currentPlayer and boardState (lines 1769 to 1771) to add + or #, so it only works when called from one point inside makeMove, and check and checkmate are then computed a second time a few lines later.

Impact

Non-standard notation in positions with a pinned piece of the same type, in the move list, the screen reader text and the exported PGN. The app's own importer and lenient parsers accept it; strict validators can reject it.

Steps to reproduce

Two-player game: 1. d4 e6 2. Nc3 Bb4 3. Nh3 d6 4. Ng5 h6, then move the g5 knight to e4. The c3 knight is pinned by the bishop on b4. The move list shows "Nge4"; the correct notation is "Ne4".

Suggested fix

Build the rival list from the legal moves of the position before the move (for example allLegalMoves(positionBefore, piece.color) filtered to the same type and destination). While there, pass the check suffix in from makeMove so the function no longer reads globals, and move it next to findSANMove in rules.js.

Acceptance criteria

  • The sequence above records "Ne4".
  • Existing notation tests pass, including double disambiguation.
  • An export-then-import round trip test covers a game with a pinned twin piece.

Getting started

  • Relevant files: js/game.js, js/rules.js, tests/unit/game-moves.test.js, tests/unit/rules-regressions.test.js
  • How to run tests: npm ci, then npm test

Filed by repo-audit/full-audit at ac3afa3. Severity: low. Effort: S. audit-key: bug|js/game.js|generateNotationWithDisambiguation

Activity

  1. added
    bug
    good first issue
    severity: low
    on Nov 15, 2026
  2. TMHSDigital commented on Nov 15, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in the commit that closed this issue ("Disambiguate notation only among legal moves").

    generateNotationWithDisambiguation now receives the position before the move and builds its rival list from legalMovesFrom, so a pinned piece of the same type no longer adds a file or rank. The writer and the reader (findSANMove) now use the same rule.

    Verified with a new test in tests/unit/game-moves.test.js: the sequence from this issue records "Ne4" (it recorded "Nge4" before the change), and the exported PGN of that game loads back to the same position. The existing notation tests, including double disambiguation, pass unchanged. Full suite, lint and format check pass.

    Not done: the optional cleanup of passing the check suffix in from the caller and moving the writer into rules.js; it still reads the live game for + and #. That fits with #89.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issueseverity: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions