# Does move disambiguation happen before or after legality checking?

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?

On the assumption that you are asking about PGN, the answer can be found in section 8.2.3.3 Basic SAN move construction in the PGN standard itself. Note that SAN, (i.e. Standard Algebraic Notation) not necessarily describes the same thing as FIDE notation.

Also assuming that the position you use as explanation has A1 in the upper right corner.

Section 8.2.3.3 says, among other things:

In the case of ambiguities (multiple pieces of the same type moving to the same square), the first appropriate disambiguating step of the three following steps is taken: First, if the moving pieces can be distinguished by their originating files, the originating file letter of the moving piece is inserted immediately after the moving piece letter. Second (when the first step fails), if the moving pieces can be distinguished by their originating ranks, the originating rank digit of the moving piece is inserted immediately after the moving piece letter. Third (when both the first and the second steps fail), the two character square coordinate of the originating square of the moving piece is inserted immediately after the moving piece letter. The result of the SAN actions described so far is called "the basic SAN move notation".

In the case you describe, you do not have a situation where two pieces may move to the same destination square, as only the move Nxd6 is legal. For that reason, move disambiguation is not really relevant. (Added: That is, move disambiguation assumes that the moves are legal.)

If you drop the wQ, removing the pin, the steps above would be applied, resulting in N5xd6 or N7xd6.

(Correction: No, that was wrong. Nbxd6 or Nfxd6 would be the correctly disambiguated moves. Just read the quoted passage from the PGN standard ... )

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).

• 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) Commented Jul 19, 2023 at 1:41
• 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 ;-)
– IT M
Commented Jul 19, 2023 at 12:19

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.)

• 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 Commented Jul 19, 2023 at 13:01
• @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. Commented Jul 19, 2023 at 20:17
• @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 Commented Jul 20, 2023 at 2:01