Skip to content

Commit 558215d

Browse files
committed
Added prompts and support files
1 parent c1a4532 commit 558215d

File tree

5 files changed

+350
-3
lines changed

5 files changed

+350
-3
lines changed

parsing/PDN.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _read_board_orientation(self, value):
163163
raise SyntaxError(f"Unknown {value} used in board_orientation tag.")
164164

165165
def _start_move_list(self, _):
166-
if self._black_player and self._white_player:
166+
if self._black_player and self._white_player and self._black_player != "*" and self._white_player != "*":
167167
title = f"{self._event}: {self._black_player} vs. {self._white_player}"
168168
else:
169169
title = f"{self._event}"
@@ -281,9 +281,9 @@ def read_game(self, idx):
281281
self._moves.append([move_list, annotation])
282282
else:
283283
raise RuntimeError(f"Cannot interpret item {item} in game.body")
284-
# if no game description was in the file, add a basic one so the user has something to guide them.
284+
# if no game description was in the file, add a basic one so the user has something to guide them.
285285
if not self._description:
286-
if self._black_player and self._white_player:
286+
if self._black_player and self._white_player and self._black_player != "*" and self._white_player != "*":
287287
self._description += f"{self._event}: {self._black_player} vs. {self._white_player}"
288288
else:
289289
self._description += f"{self._event}"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# FEN Description for American Checkers (8x8 Board)
2+
3+
The Forsyth-Edwards Notation (FEN) represents a checkers position in a concise string format. For American Checkers, the FEN format follows this pattern:
4+
5+
[TURN]:[COLOR1][PIECES]:[COLOR2][PIECES]
6+
7+
Where:
8+
- [TURN] is either "W" (White's turn) or "B" (Black's turn)
9+
- [COLOR1] is always "W" for White pieces
10+
- [COLOR2] is always "B" for Black pieces
11+
- [PIECES] is a comma-separated list of piece positions, with kings prefixed by "K"
12+
13+
## Format Rules:
14+
1. The FEN always begins with the turn indicator "W" or "B" followed by a colon
15+
2. White pieces are always listed first, then Black pieces
16+
3. Regular men are indicated by just their square number
17+
4. Kings are indicated by "K" followed immediately by their square number
18+
5. Multiple pieces of the same color are separated by commas
19+
6. The two color sections are separated by a colon
20+
7. No spaces are allowed in the FEN string
21+
8. Square numbers range from 1-32
22+
23+
## Examples:
24+
25+
Starting position (White to move):
26+
W:W21,22,23,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,7,8,9,10,11,12
27+
28+
White has two kings, Black has one king and one man (Black to move):
29+
B:WK10,K20:B5,K15
30+
31+
White has one king, Black has three kings (White to move):
32+
W:WK23:BK7,K10,K15
33+
34+
Two kings vs one king (Either to play):
35+
W:WK5,K10:BK20
36+
B:WK5,K10:BK20
37+
38+
## Important Notes:
39+
1. When generating a FEN string from a diagram, first determine the turn from the accompanying instruction line ("Black to play", "White to play", or "Either to play").
40+
2. When the instruction says "Either to play", use the side specified first in the continuation text.
41+
3. In PDN files, the FEN tag must be formatted as: [FEN "W:W1,2:B3,4"] (including the quotes)
42+
4. Men and kings should be listed in ascending order by square number for readability (though this is not required by the standard)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
The PDN output for each diagram should be as follows:
2+
An Event tag is first in the file. It should be the name of the diagram, such as "Diagram 5".
3+
4+
Next is the Date tag. If there is a date listed as part of the surrounding diagram text (such as "Edinburgh 1848, game 1" or "I got Willie Leeds with this move in the 1985 championship") then the date would go here in the value; otherwise, the value should just be an asterisk. All dates should be represented in MM/DD/YYYY format. If some of the date is unknown, then use question marks to represent the unknown portions, e.g., ??/??/1985
5+
6+
The Round tag is next. Use an asterisk for this value.
7+
8+
The Black tag is next. If the Black player has a name, it should be included here. For instance, if the surrounding diagram text said "Tinsley is Black; Chinook is White", then the value for Black would be "Tinsley". If no Black player is listed, then leave it as an empty string.
9+
10+
The White tag is next. If the White player has a name, it should be included here. For instance, if the surrounding diagram text said "Tinsley is Black; Chinook is White", then the value for White would be "Chinook". If no White player is listed, then leave it as an empty string.
11+
12+
The Site tag is next. Use an asterisk for this value.
13+
14+
The Result tag is next. If Black wins, the result is 1-0; if White wins, the result is 0-1; if both players draw, the result is 1/2-1/2; if the game is still in-process, the result is an asterisk.
15+
16+
The FEN tag is next. Use the procedure for generating the FEN for each diagram outlined in the attached FEN_description.txt file. Be sure to correctly identify all pieces and their positions.
17+
18+
The BoardOrientation tag is next. Use "white_on_top" for this value.
19+
20+
Next is one or more comment lines (each beginning with a % symbol and a space) that should contain the overall description of the diagram. Things to include in the comments:
21+
22+
1. The title of the section that the diagram is in, if it applies to the diagram.
23+
2. The lesson title.
24+
3. Relevant context or descriptive information in the paragraphs related to the diagram, but not involving the actual checker moves or annotations in the game continuation.
25+
4. Make sure to directly reference the diagram by number in the description (e.g., "Diagram 5 shows...")
26+
5. Don't start descriptions with transition words like "However" that imply preceding content
27+
6. Don't refer to other diagrams in the descriptions
28+
7. Make each description self-contained with all relevant information
29+
8. Use clear, simple language (avoid phrases like "all-king endgame" in favor of clearer phrasing)
30+
31+
After the descriptive comments, add a play instruction line as a comment (starting with % symbol) that describes whose turn it is to play and the expected outcome (e.g., "% Black to play, White wins" or "% White to play and draw").
32+
33+
Next in the file is a GameBody, as defined in PDN_Grammar.txt. This is the PDN version of the move continuation text, listed in the text after its matching diagram. The move continuation text starts with the phrase "Continue: ..." or "Continue from Diagram N: ..." where N refers to the number of the diagram preceding. Include move numbers (1., 2., etc.) at the beginning of each pair of moves. One difference from the PDN grammar GameBody definition is that both Variations or COMMENTs will be in parentheses, and when translated to PDN, both the Variations and the COMMENTs should be in curly braces. Each move should be followed by a comment in curly braces containing the move notation and any variations or annotations given in the original text. The other difference from the PDN grammar in the move continuation text is that rather than ending with a WIN1, DRAW1 or LOSS1, the ending will say something like "Black wins.", "White wins." or "Drawn.". This should be translated to the appropriate WIN1, DRAW1 or LOSS1 when the PDN is created.
34+
35+
Three examples of valid, generated PDNs based on the instructions above:
36+
37+
Example 1 -
38+
[Event "Diagram 5"]
39+
[Date "*"]
40+
[Round "*"]
41+
[Black "Player 1"]
42+
[White "Player 2"]
43+
[Site "*"]
44+
[Result "*"]
45+
[FEN "W:WK23:BK31"]
46+
[BoardOrientation "white_on_top"]
47+
% Chapter 3: Simple Endgames
48+
% Lesson 3: 1 King v 1 King
49+
% Diagram 5 shows a position where Black is pinned on the side of the board and just two moves away from losing.
50+
% Black to play, White wins
51+
1. 31-27 {31-27 (Or 31-26 23-30)} 23-32 {23-32. White wins.} 0-1
52+
53+
Example 2 -
54+
[Event "Diagram 10"]
55+
[Date "*"]
56+
[Round "*"]
57+
[Black "Player 1"]
58+
[White "Player 2"]
59+
[Site "*"]
60+
[Result "*"]
61+
[FEN "W:WK5,WK6:BK15"]
62+
[BoardOrientation "white_on_top"]
63+
% Chapter 3: Simple Endgames
64+
% Lesson 4: 2 Kings v 1 King
65+
% In an open all-king situation where there is a material imbalance, the side with the king majority has a forced win at hand. In the case of 2 kings v 1, the strategy employed is as follows: the lone king strives to access one of the double-corners; the two kings pursue it there, force it out and pin it on the side of the board. Diagram 10 is representative.
66+
% White to play and win
67+
1. 5-9 {5-9} 2. 15-19 {15-19 (15-18 comes to the same thing, while 15-11 just hastens the end)} 6-10 {6-10} 3. 19-24 {19-24 (The same comments apply to 19-23 and 19-16)} 10-15 {10-15 (There is no need to memorize specific moves, just the general strategy)} 4. 24-28 {24-28 (Again, 24-27 is essentially the same; 24-20 loses quickly)} 15-19 {15-19} 5. 28-32 {28-32} 9-14 {9-14} 6. 32-28 {32-28} 14-18 {14-18} 7. 28-32 {28-32} 18-23 {18-23} 8. 32-28 {32-28} 23-27 {23-27} 9. 28-32 {28-32} 19-23 {19-23!} 10. 32-28 {32-28} 27-32 {27-32! (Entering the double-corner and forcing Black out)} 11. 28-24 {28-24} 32-28 {32-28} 12. 24-20 {24-20} 23-18 {23-18!} 13. 20-16 {20-16} 18-15 {18-15} 14. 16-20 {16-20} 15-11 {15-11! White wins.} 0-1
68+
69+
Example 3 -
70+
[Event "Diagram 8"]
71+
[Date "*"]
72+
[Round "*"]
73+
[Black "Player 1"]
74+
[White "Player 2"]
75+
[Site "*"]
76+
[Result "1/2-1/2"]
77+
[FEN "W:WK5:BK12"]
78+
[BoardOrientation "white_on_top"]
79+
% Chapter 3: Simple Endgames
80+
% Lesson 3: 1 King v 1 King
81+
% In Diagram 8, White has the opposition, but it confers no advantage in the current setup. In a 1 king v 1 king situation, possession of the opposition means it's impossible to lose. This position requires Black to employ care to secure the draw.
82+
% Simple as it may be, before proceeding it's well worth playing through Diagram 8 several times, examining all the possible alternate moves, in order to firmly embed the underlying principles.
83+
% White to play, Black draws
84+
1. 5-9 {5-9}; 2. 12-16 {12-16!} 9-14 {9-14} 3. 16-19 {16-19 (16-20 is also okay, but both 16-11? and 16-12? lose)} 14-18 {14-18} 4. 19-24 {19-24!} 18-23 {18-23} 5. 24-28 {24-28!} 23-27 {23-27} 6. 28-32 {28-32} 27-23 {27-23 (Or 27-24 or 27-31) and drawn.} 1/2-1/2
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
PDN Grammars
2+
This section defines some PDN grammars. First a PDN 3.0 grammar is given, with some additional restrictions. The goal of these restrictions is to make PDN easier to parse, and thus to make it easier for programmers to support PDN 3.0. Also some explanations are given. Finally, a much more liberal reading grammar is given that can be used when reading existing PDN files. The grammars that are given in this section can not be parsed using a simple LL(1) parser. See the PDN Implementation section for some examples of LL(1) grammars.
3+
4+
PDN 3.0 Grammar
5+
// Game independent productions
6+
PdnFile : Game (GameSeparator Game)* GameSeparator?
7+
GameSeparator : ASTERISK
8+
Game : (GameHeader GameBody?) | GameBody
9+
GameHeader : PdnTag+
10+
GameBody : (GameMove | Variation | COMMENT | SETUP | NAG)+
11+
PdnTag : LBRACKET IDENTIFIER STRING RBRACKET
12+
GameMove : MOVENUMBER? Move MOVESTRENGTH?
13+
Variation : LPAREN GameBody RPAREN
14+
15+
// Game dependent productions
16+
Move : NormalMove | CaptureMove
17+
NormalMove : Square MOVESEPARATOR Square
18+
CaptureMove : Square (CAPTURESEPARATOR Square)+
19+
Square : ALPHASQUARE | NUMSQUARE
20+
21+
// Tokens
22+
MOVENUMBER : "[0-9]+\.(\.\.)?"
23+
MOVESEPARATOR : "-"
24+
CAPTURESEPARATOR : "x"
25+
ALPHASQUARE : "[a-h][1-8]"
26+
NUMSQUARE : "[1-9][0-9]?"
27+
MOVESTRENGTH : "([\!\?]+)|(\([\!\?]+\))"
28+
NAG : "\$[0-9]+"
29+
LPAREN : "\("
30+
RPAREN : "\)"
31+
LBRACKET : "\["
32+
RBRACKET : "\]"
33+
ASTERISK : "\*"
34+
SETUP : "\/[^\/]*\/"
35+
STRING : "\"([^\"]|\\\")*\""
36+
COMMENT : "\{[^}]*\}"
37+
IDENTIFIER : "[A-Z][a-zA-Z0-9_]*"
38+
Besides the usual white space characters (spaces, tabs and line endings), also line comments starting with a % are allowed. For example
39+
40+
% Board game: International Draughts 10x10
41+
[Date "2012.02.01"]
42+
1. 32-28 19-23
43+
PDN 3.0 Restrictions
44+
When writing PDN, the following restrictions should be applied:
45+
46+
Spaces are not allowed in the notation of a move. For example, 1 - 7 is not allowed.
47+
48+
Spaces are not allowed between a move notation and it’s move strength indicator. For example, 32-28 ! is not allowed.
49+
50+
The symbol * is not allowed as a move strength indicator. Use the $7 numeric annotation glyph instead. See the PDN parsing issues section for an explanation.
51+
52+
Only the symbol * is allowed as a game separator.
53+
54+
Squares of moves may not have leading zeroes. For example 01-07 is not allowed.
55+
56+
Moves must be written in the format (Alpha numeric, Numeric or SAN) as it is specified in the Notation attribute of the GameType tag. See also section GameType tag.
57+
58+
Capture moves must be written using the capture separator corresponding to the GameType, as it is specified in the table in section GameType tag.
59+
60+
Ambiguous moves must be written in long notation, i.e. they must contain the full capture sequence. All other moves should use regular notation, i.e. only a begin and an end square.
61+
62+
Explanation: sometimes the regular notation of a move is ambiguous. For example in the position below the notation 47x36 does not specify exactly which black pieces were captured.
63+
64+
_images/diagram1.png
65+
To resolve this, 47x38x24x13x36 or 47x38x20x9x36 must be chosen.
66+
67+
Disambiguated capture sequences have to specify a complete sequence of intermediate squares along the path of the capture. If there is a change in direction, an intermediate square is the square where a turn in direction was made. If there was not a change in direction, the intermediate square is the square immediately behind a captured piece. There is no intermediate square behind the last captured piece, but otherwise leaving out an intermediate square that is not necessary for the disambiguation is forbidden.
68+
69+
For example, in the above diagram 47x24x36 is not allowed, even though it uniquely determines the move. Also 47x33x24x13x36 is not allowed, since 33 is not immediately behind a captured piece.
70+
71+
N.B. The first five restrictions are enforced by the grammar. Other restrictions have to be checked after parsing.
72+
73+
Explanation
74+
The grammar is given in EBNF format. In the productions the symbol ? stands for 0 or 1 repetitions, * stands for 0 or more repetitions, and + stands for 1 or more repetitions. Tokens are given between double quotes and should be interpreted as regular expressions.
75+
76+
Strings can have embedded double quotes ", by using the escape sequence \". For example "An embedded \" quote!".
77+
78+
Comments are placed between braces. For example { Start of the game } 33-28 18-22 39-33? { This is a classical mistake }.
79+
80+
In existing PDN files games are usually terminated with a result. It can be one of the chess results 1-0, 1/2-1/2, 0-1, one of the results of international draughts 2-0, 1-1, 0-2, or a double forfeit 0-0. Finally the * can be used as a terminator.
81+
82+
A game can not be empty.
83+
84+
Both numeric moves 32-28 and alpha-numeric moves a3-b4 are allowed.
85+
86+
In alpha-numeric moves the separator may be omitted, so a3b4 is allowed.
87+
88+
A move number is a number followed by either one dot or three dots, for example 1. 32-28 or 23... 20-25. The three dots denotes that it is a black move.
89+
90+
Moves can be annotated using a move strength indicator right after their notation, for example 10-15! or 29-23(?).
91+
92+
Moves can also be annotated using numeric annotation glyphs (NAGs). For example $1 has the same meaning as the move strength indicator !.
93+
94+
Comments, variations and NAGs may appear anywhere in the game, in any order. This is less restrictive than in [Nemesis],
95+
96+
Variations are placed between parentheses. They can be nested arbitrarily, for example: 32-28 19-23 (18-23 38-32 (37-32? 23-29! { Black wins }) 12-18) 28x19 14x23.
97+
98+
PDN Reading Grammar
99+
// Game independent productions
100+
PdnFile : Game (GameSeparator Game)* GameSeparator?
101+
GameSeparator : ASTERISK | Result
102+
Game : (GameHeader GameBody?) | GameBody
103+
GameHeader : PdnTag+
104+
GameBody : (GameMove | Variation | COMMENT | SETUP | NAG)+
105+
PdnTag : LBRACKET IDENTIFIER STRING RBRACKET
106+
GameMove : MOVENUMBER? Move MOVESTRENGTH?
107+
Variation : LPAREN GameBody RPAREN
108+
109+
// Game dependent productions
110+
Move : NormalMove | CaptureMove | ELLIPSES
111+
NormalMove : Square MOVESEPARATOR Square
112+
CaptureMove : Square (CAPTURESEPARATOR Square)+
113+
Square : ALPHASQUARE | NUMSQUARE
114+
Result : Result1 | Result2 | DOUBLEFORFEIT
115+
Result1 : WIN1 | DRAW1 | LOSS1
116+
Result2 : WIN2 | DRAW2 | LOSS2
117+
118+
// Tokens
119+
WIN1 : "1-0"
120+
DRAW1 : "1\/2-1\/2"
121+
LOSS1 : "0-1"
122+
WIN2 : "2-0"
123+
DRAW2 : "1-1"
124+
LOSS2 : "0-2"
125+
DOUBLEFORFEIT : "0-0"
126+
ELLIPSES : "\.\.\."
127+
MOVENUMBER : "[0-9]+\.(\.\.)?"
128+
MOVESEPARATOR : "-"
129+
CAPTURESEPARATOR : "[x:]"
130+
ALPHASQUARE : "[a-h][1-8]"
131+
NUMSQUARE : "([1-9][0-9]?)|(0[1-9])"
132+
MOVESTRENGTH : "([\!\?]+)|(\([\!\?]+\))"
133+
NAG : "\$[0-9]+"
134+
LPAREN : "\("
135+
RPAREN : "\)"
136+
LBRACKET : "\["
137+
RBRACKET : "\]"
138+
ASTERISK : "\*"
139+
SETUP : "\/[^\/]*\/"
140+
STRING : "\"([^\"]|\\\")*\""
141+
COMMENT : "\{[^}]*\}"
142+
IDENTIFIER : "[A-Z][a-zA-Z0-9_]*"
143+
When reading PDN, one must take into account that captures can can contain the full capture sequence, also in the case of non-ambiguous moves. This is for backward compatibility.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Each diagram in the attached PDF represents a checkers board state using a structured text format. Diagrams are labeled "Diagram N" or "Diagram N:", where N is a number between 1 and 128.
2+
3+
Each diagram consists of the following key components:
4+
1. Diagram Label
5+
A label starting with "Diagram N" or "Diagram N:", where N is a number.
6+
This may be followed by optional descriptive text and one or more newlines.
7+
8+
2. Checkerboard Representation
9+
Begins with the border line:
10+
QRRRRRRRRS
11+
12+
Ends with the border line:
13+
VWWWWWWWWX
14+
15+
Contains rows prefixed with "T" or "U", which are border characters and must be ignored.
16+
17+
Each row consists of:
18+
Dark, non-playable squares → Represented by "E" (IGNORE THESE COMPLETELY).
19+
Playable squares (either occupied or empty) are defined by a letter-number pair.
20+
21+
Piece Representation:
22+
"A" → Black man
23+
"B" → White man
24+
"C" → Black king
25+
"D" → White king
26+
" " (space) → Open playable square
27+
28+
Square Number Encoding:
29+
1-9 → "1" through "9"
30+
10-19 → "!" replaces the leading 1 (e.g., "!0" = 10, "!1" = 11, etc.)
31+
20-29 → "@" replaces the leading 2 (e.g., "@0" = 20, "@1" = 21, etc.)
32+
30-32 → "#" replaces the leading 3 (e.g., "#0" = 30, "#1" = 31, "#2" = 32)
33+
34+
3. Play Instruction
35+
After the checkerboard, a single line starts with "Black to play", "White to play" or "Either to play".
36+
37+
The following rigorous steps must be followed every time:
38+
Step 1: Extract the Diagram
39+
Locate "Diagram N" or "Diagram N:" to identify the start of the diagram.
40+
Extract everything from "QRRRRRRRRS" (inclusive) to "VWWWWWWWWX" (inclusive).
41+
Extract the single play instruction line directly below the diagram.
42+
43+
Step 2: Process the Board
44+
Ignore "T" and "U" (border characters).
45+
Ignore all "E" characters (non-playable dark squares).
46+
Read only letter-number pairs and map them to the correct square numbers.
47+
Do not infer or assume; each piece must be explicitly listed in the extracted text.
48+
49+
Step 3: List All Pieces
50+
Black Men (A) → List all numbered squares
51+
White Men (B) → List all numbered squares
52+
Black Kings (C) → List all numbered squares
53+
White Kings (D) → List all numbered squares
54+
55+
Confirm each square number using the exact encoding rules.
56+
57+
Example: Interpreting Diagram 86
58+
59+
Extracted board text:
60+
QRRRRRRRRS
61+
TE 1E 2E 3E 4U
62+
TA5EB6E 7E 8EU
63+
TEB9E !0E !1E !2U
64+
T !3EB!4EC!5E !6EU
65+
TE !7E !8E !9E @0U
66+
T @1E @2E @3E @4EU
67+
TE @5EC@6E @7E @8U
68+
T @9E #0E #1E #2EU
69+
VWWWWWWWWX
70+
71+
Play instruction: "White to play"
72+
73+
Final Interpretation
74+
Type of Piece Square Numbers
75+
Black Men (A) 5
76+
White Men (B) 6, 9, 14
77+
Black Kings (C) 15, 26
78+
White Kings (D) (None)

0 commit comments

Comments
 (0)