How are PGN ambiguities handled?

How are ambiguities handled when writing the PGN when more than one piece of the same type can move into the same square?

[FEN "1R4QQ/R1R4Q/8/6pP/5P1P/8/NK1k4/1N1N4 w - g6 0 1"]


Note: It isWhite to move, with an en passant capturing square on g6.

What would happen if:

1. the top rook moves to b7?
2. one of the bottom rooks moves to b7?
3. the left pawn takes xg5?
4. the bottom right pawn takes xg5?
5. the top right pawn takes xg6 by en passant_?
6. the top left knight goes to c3?
7. one of the bottom knight goes to c3?

Edit (bonus question):

• What would happen if any queen wants to go to g7?

From the specification:

A basic SAN [Standard Algebraic Notation] move is given by listing the moving piece letter (omitted for pawns) followed by the destination square. Capture moves are denoted by the lower case letter "x" immediately prior to the destination square; pawn captures the file letter of the originating square of the capturing pawn immediately prior to the "x" character.

And

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.

1: Rbb7

2: Rab7 or Rcb7

3: fxg5

4: hxg5

5: hxg6

6: Nac3

7: Nbc3 or Ndc3

Note that this is simply how the specification is written. En passant captures should not be an edge case, but they are unlikely to be implemented correctly 100% of the time. You'll have to test your replayer to see whether it handles these cases correctly or not.

• Warning: your implementation may vary. An online PGN tool I constantly use notates as Q8g7,Q7g7 and Qhg7. Works in this example, but being a natural born troll, I positioned 8 queens around g7. No crash, but now Qf8-g7 is impossible to notate: even if I write it out in PGN, and load it, Qf6-g7 is played. (Of course the probability of this happening in RL is about zero.) – Hauke Reddmann Feb 23 at 20:51

We need to use the first step that that removes the ambiguity:

1. Use the originating file letter (if the ambiguity was not removed, see #2).
2. Use the originating rank number (if the ambiguity was not removed, see #3).
3. Use both the file and rank from the originating square.

1) Rbb7 (because #1)
2) Rab7 or Rcb7 (both because #1)
3) fxg5 (no disambiguation needed)
4) hxg5 (no disambiguation needed)
5) hxg6 (no disambiguation needed)
6) Nac3 (because #1)
7) Nbc3 or Ndc3 (both because #1)

Now for the bonus example:

in the case of g8 queen to g7:Qgg7 (because #1)
in the case of h7 queen to g7:Q7g7 (because #2)
in the case of h8 queen to g7:Qh8g7 (because #3)



[FEN "1R4QQ/R1R4Q/8/6pP/5P1P/8/NK1k4/1N1N4 w - g6 0 1"]



What would happen if:

1. the top rook moves to b7?

Rbb7

2. one of the bottom rooks moves to b7?

Rab7 or Rcb7

3. the left pawn takes xg5?

fxg5

4. the bottom right pawn takes xg5?

hxg5

5. the top right pawn takes xg6 by en passant?

hxg6!

6. the top left knight goes to c3?

Nac3

7. one of the bottom knight goes to c3?

Nbc3 or Ndc3

bonus What would happen if any queen wants to go to g7?

When all else fails, be explicit. Qh8g7 or h8g7