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: White to move, En Passant square at `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`?
-
Black should probably resign! :) – AndyM Jan 11 '13 at 23:04
BTW, the position can't legally be white to move, since black is in check. – ETD Jan 11 '13 at 23:14
you might also want to read: is there the need to disambiguate if the other pieces are pinned? – ajax333221 Jan 17 '13 at 5:23

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.

-
is the `5` in `...xg5` necessary? pawns capture in only one way, there should be no problem with just `...xg` edit: I just checked a major chess viewer/player and he uses the `5`... Interesting – ajax333221 Jan 10 '13 at 20:32
It is. I added the relevant section. There are no exceptions to the rule in the specification, and it's better to have a "hard" destination anyway. Again, keep in mind that not all replayers will implement this correctly. – Jonathan Garber Jan 10 '13 at 20:37
true, the weird thing is that the specification just says "pawn captures the file letter of the originating square of the capturing pawn immediately prior to the "x" character.", never says anything about rank – ajax333221 Jan 10 '13 at 20:40
Well, hmm, you're right. I think we can safely assume it's the correct way to disambiguate, but it's not in the specification. Granted, an ambiguous en passant capture IS an edge case in itself. But regardless, listing the destination is required by the spec in all cases. – Jonathan Garber Jan 10 '13 at 20:43
One more random note, in #5, the correct pgn would be `1. hxg6`. You can also add `e.p.` to create `1. hxg6 e.p.` if you want to specify that the capture is en passant. But all pawn captures are origin file, "x", destination square. – Andrew Jan 10 '13 at 21:19

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`

-