Answers.Body: <p>It should not be written <code>N5xd6</code> as rank disambiguation is done if file disambiguation is not sufficient to determine the piece. In this case, giving the file is enough. On a pgn, <code>Nxd6</code> should be written (the given move is a capture).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T01:41:47.283Z
Answers.Text: so the full rule is row disambiguation before column disambiguation (just to rephrase to be sure) and **after** illegal moves are filtered? (the missing take is a typo yes I forgot it)
Answers.UserDisplayName: Crocobag
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T12:19:55.490Z
Answers.Text: No, if the c-Knight wasn't pinned, correct notation would be Nbxd6. Columns before rows! It's pinned, so Nxd6 is the only correct notation here. I don't know any referee that would give a punishment for this however ;-)
Answers.UserDisplayName: IT M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T01:28:09.350Z
Answers.LastActivityDate: 2023-07-19T09:04:07.650Z
Answers.LastEditDate: 2023-07-19T09:04:07.650Z
Answers.UserDisplayName: Lucenaposition
Answers.Body: <p>Of course disambiguation occurs after checking for legality. Consider the following slightly different position.</p>
  <pre><code>[FEN &quot;6k1/6n1/3R4/1n6/8/5Q2/8/4K3 b - - 0 1&quot;]
  </code></pre>
  <p>Now certainly it is just <code>Nxd6</code>: you don't need to write <code>Nbxd6</code> because capturing with the other knight would be an illegal move. Why should the illegal move in your example be treated any differently?</p>
  <p>(Note that I am still assuming the board is rotated so the b file is towards the right.)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T13:01:20.373Z
Answers.Text: Because it depends on how you understand the word "ambiguous". 
  In my scenario f7d6 is "pseudo-legal" but not legal. Does it worth it to disambiguate taking those moves into account? I now know that the answer is no
Answers.UserDisplayName: Crocobag
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T20:17:54.343Z
Answers.Text: @Olympiloutre: Yeah, this answer was my first thought, but that means PGN *decoders* would need to have move-legality checkers built-in.  It's easy to imagine a different design choice where moves are supposed to be unambiguous without looping over every piece looking for pins and stuff.  e.g. to simplify decoding for things like the Javascript that powers the move GUI on this site, which doesn't otherwise need to do any chess-engine stuff, just move images of pieces around on a grid.  So it's not obvious at all whether PGNs should be expected to avoid this type of semi-ambiguity.
Answers.UserDisplayName: Peter Cordes
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-20T02:01:32.860Z
Answers.Text: @PeterCordes: That's exactly what I am doing, programming a GUI. This question was genuine. It seems that their SAN guidelines was made to be human readable and understood, not to be a perfect algorithm that you can apply without thinking about it for a bit
Answers.UserDisplayName: Crocobag
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T12:33:22.540Z
Answers.LastActivityDate: 2023-07-19T12:33:22.540Z
Answers.UserDisplayName: Especially Lime
Body: <p>I am wondering if disambiguation occurs before or after the legality of such moves has been established. Given this position:</p>
  <pre><code>[FEN &quot;5k2/5n2/3R4/1n6/8/5Q2/8/4K3 b - - 0 1&quot;]
  </code></pre>
  <p>Both knights are targeting d6, but the one on f7 is pinned. In PGN notation, should the move <code>b5d6</code> be written as <code>Nd6</code> or <code>Nbd6</code>/<code>N5d6</code> nonetheless?</p>
  
Tags: <pgn><notation><pins>
Title: Does move disambiguation happen before or after legality checking?
ThreadText: # Does move disambiguation happen before or after legality checking?
  
  (Asked by: username_0 on 2023-07-19)
  
  I am wondering if disambiguation occurs before or after the legality of such moves has been established. Given this position:
  [FEN "5k2/5n2/3R4/1n6/8/5Q2/8/4K3 b - - 0 1"]
  
  Both knights are targeting d6, but the one on f7 is pinned. In PGN notation, should the move b5d6 be written as Nd6 or Nbd6/N5d6 nonetheless?
  
  **Tags:** pgn, notation, pins
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-07-19. Score: 2
  
  It should not be written `N5xd6` as rank disambiguation is done if file disambiguation is not sufficient to determine the piece. In this case, giving the file is enough. On a pgn, `Nxd6` should be written (the given move is a capture).
  
  > **Comments:**
  > **username_0**: so the full rule is row disambiguation before column disambiguation (just to rephrase to be sure) and **after** illegal moves are filtered? (the missing take is a typo yes I forgot it)  
  > **username_2**: No, if the c-Knight wasn't pinned, correct notation would be Nbxd6. Columns before rows! It's pinned, so Nxd6 is the only correct notation here. I don't know any referee that would give a punishment for this however ;-)  
  
  ---
  
  ### Answer by username_3 on 2023-07-19. Score: 0
  
  Of course disambiguation occurs after checking for legality. Consider the following slightly different position.
  [FEN "6k1/6n1/3R4/1n6/8/5Q2/8/4K3 b - - 0 1"]
  
  Now certainly it is just Nxd6: you don't need to write Nbxd6 because capturing with the other knight would be an illegal move. Why should the illegal move in your example be treated any differently?
  (Note that I am still assuming the board is rotated so the b file is towards the right.)
  
  > **Comments:**
  > **username_0**: Because it depends on how you understand the word "ambiguous".  In my scenario f7d6 is "pseudo-legal" but not legal. Does it worth it to disambiguate taking those moves into account? I now know that the answer is no  
  > **username_4**: @Olympiloutre: Yeah, this answer was my first thought, but that means PGN *decoders* would need to have move-legality checkers built-in.  It's easy to imagine a different design choice where moves are supposed to be unambiguous without looping over every piece looking for pins and stuff.  e.g. to simplify decoding for things like the Javascript that powers the move GUI on this site, which doesn't otherwise need to do any chess-engine stuff, just move images of pieces around on a grid.  So it's not obvious at all whether PGNs should be expected to avoid this type of semi-ambiguity.  
  > **username_0**: @PeterCordes: That's exactly what I am doing, programming a GUI. This question was genuine. It seems that their SAN guidelines was made to be human readable and understood, not to be a perfect algorithm that you can apply without thinking about it for a bit  
  
  ---
  
  