Skip to content

Commit 5fa7d8c

Browse files
Version 2.3
1 parent d50784f commit 5fa7d8c

8 files changed

+1040
-803
lines changed

README.md

+59-44
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ to a position, which return a list of objects (typically, positions).
4646

4747
- `move` (or `m` for short): performs as forward move.
4848

49+
- `legal`: analyzes the legality of the position and its history.
50+
This may label the position as:
51+
- *illegal* (FIDE illegal), when the position is unreachable from
52+
the starting position via a sequence of legal moves (that is,
53+
not considering FIDE Article 5.2.2 about "dead positions").
54+
- *zombie*, when it is FIDE legal, but all possible legal retractions
55+
are from dead positions.
56+
- No label on if FIDE legal and non-zombie.
57+
58+
This command also analyzes whether a position is alive/dead when the
59+
position is the result of a retraction or it is part of a longer sequence
60+
of moves, possibly labeling the position as "dead".
61+
62+
- `DP` : labels the position as "DP" (dead position) or "alive".
63+
4964
- `flip`: flips the turn. This also resets the halfmove clock,
5065
and the en-passant flags to `?` (but preserves castling rights).
5166
The position(s) after a flip become the "game array", i.e., they
@@ -57,17 +72,17 @@ to a position, which return a list of objects (typically, positions).
5772

5873
- `ep` : returns the en-passant privileges of the given position.
5974

60-
- `DP` : labels the position as "DP" (dead position) or "alive".
61-
62-
- A solve command (which stops the potential `>>=` chain). The following solve
63-
commands are supported:
75+
- A solve command. The following solve commands are supported:
6476
- `#[0-9]+[.5]?`: *forced mate* in the given number of moves.
6577
- `h#[0-9]+[.5]?`: *help mate* in the given number of moves.
6678
- `h=[0-9]+[.5]?`: *help stalemate* in the given number of moves.
6779
- `hdp[0-9]+[.5]?`: *help dead position* in the given number of moves.
6880
- `h~=[0-9]+[.5]?`: *help draw* (stalemate or dead) in the given number of
6981
moves.
7082

83+
This transforms the position into the final position of every solution.
84+
(The monadic chain `>>=` may continue from those.)
85+
7186
A solve command can be succeded (after a blank space) with a piece type in
7287
round brackets (to choose from `p`, `n`, `b`, `r`, `q`, `k`).
7388
This will constrain the last move to have been performed by a piece of the
@@ -81,11 +96,11 @@ For example:
8196
```
8297
// Julio Sunyer, 1923 (The Chess Amateur)
8398
>>> 4k3/8/8/7K/8/8/8/8 b - - >>= r >>= r >>= h#1
84-
g6xRh5 h8xQh5 then e8g8 h5h7#
99+
g6xRh5 h8xQh5 e8g8 h5h7# 5rk1/8/6K1/7Q/8/8/8/8 w - - 1 2
85100
nsols 1
86101
87102
// Andrew Buchanan, 2001 (1 Retros mailing list 24th Jan)
88-
>>> k7/8/2K5/8/8/8/8/8 ? >>= turn
103+
>>> k7/8/2K5/8/8/8/8/8 ? >>= legal >>= turn
89104
b
90105
nsols 1
91106
```
@@ -96,80 +111,81 @@ nsols 1
96111
well-formed positions (exactly one king per side, no pawns on 1st or 8th rank,
97112
etc) even if they are illegal.
98113
Furthermore, in virtue of FIDE Article 5.2.2, all positions preceeding a
99-
**dead** position should be **alive**.
100-
Our retractor still displays those that are dead, but it labels them.
114+
*dead* position should be *alive*.
115+
Our retractor still displays those that are dead, but it labels them if
116+
the command `legal` is used.
101117

102118
- We perform minimal legality checks on a position, by checking whether it
103-
admits at least an alive retraction.
104-
Positions that are identified to be illegal with this simple check are labeled
105-
as so and displayed.
119+
admits at least a retraction.
120+
This means at the moment our legality analysis is a semi-decision procedure.
121+
If a position is labeled as "illegal", it is definitely illegal.
122+
However, non-labeled positions could be legal and escape our current logic.
123+
*We are working on making this legality check more complete*.
106124

107125
- Even though we display illegal and dead (retracted from dead) positions,
108126
they do not carry on to the next command. For example, 6 possible well-formed
109127
retractions are shown after the following command:
110128
```
111-
>>> 8/8/8/8/2Q5/k7/1pP5/K7 w - - >>= r
112-
8/8/8/8/2Q5/kp6/2P5/K7 b - - ? 0 b3b2
113-
8/8/8/8/2Q5/k1p5/1PP5/K7 b - - ? 0 (illegal) c3xPb2
114-
8/8/8/8/2Q5/k1p5/1QP5/K7 b - - ? 0 (dead) c3xQb2
115-
8/8/8/8/2Q5/k1p5/1RP5/K7 b - - ? 0 (dead) c3xRb2
116-
8/8/8/8/2Q5/k1p5/1BP5/K7 b - - ? 0 (dead) c3xBb2
117-
8/8/8/8/2Q5/k1p5/1NP5/K7 b - - ? 0 (dead) c3xNb2
129+
>>> 8/8/8/8/2Q5/k7/1pP5/K7 w - - >>= r >>= legal
130+
↶b3b2 8/8/8/8/2Q5/kp6/2P5/K7 b - - ? 0
131+
↶c3xPb2 illegal dead 8/8/8/8/2Q5/k1p5/1PP5/K7 b - - ? 0
132+
↶c3xQb2 dead 8/8/8/8/2Q5/k1p5/1QP5/K7 b - - ? 0
133+
↶c3xRb2 dead 8/8/8/8/2Q5/k1p5/1RP5/K7 b - - ? 0
134+
↶c3xBb2 dead 8/8/8/8/2Q5/k1p5/1BP5/K7 b - - ? 0
135+
↶c3xNb2 dead 8/8/8/8/2Q5/k1p5/1NP5/K7 b - - ? 0
118136
nsols 1
119137
```
120138
However, 5 of them were labeled as either illegal or dead.
121139
If we then apply another command, e.g. `>>= h=1.5`, these 5 will not be
122140
considered in the analysis, only the very first one
123-
`8/8/8/8/2Q5/kp6/2P5/K7 b - - ? 0 b3b2`.
141+
`8/8/8/8/2Q5/kp6/2P5/K7 b - - ? 0`.
124142

125143
- In case our dead position subroutine fails to determine whether a position
126144
is *dead*, the following error message will be raised:
127145
```
128-
>>> B2b4/8/4k3/8/1p1p1p1p/1PpP1P1P/K1P4b/RB6 b - - 0 1 >>= hdp0
146+
>>> B2b4/8/4k3/8/1p1p1p1p/1PpP1P1P/K1P4b/RB6 b - - 0 1 >>= DP
129147
RuntimeError: CHA failed on B2b4/8/4k3/8/1p1p1p1p/1PpP1P1P/K1P4b/RB6 b - - 0 1
130148
```
131149
In a successful execution, every computation regarding dead positions is
132-
*sound* and *correct* in the sense that the tool either finds a helpmate
133-
(proving the position is alive) or definitely proves that the position is dead.
150+
*sound* in the sense that the tool either finds a helpmate (proving the
151+
position is alive) or definitely proves that the position is dead.
134152

135153
- FEN tokens can be unspecified with `?`, in which case, the tool will consider
136154
all plausible values of that token. For example, the following considers that
137155
the en-passant flag takes values `-` or `g6`.
138156
```
139-
>>> 6br/4Bp1k/5P2/5PpK/4B1P1/8/8/8 w - ? ? 100 >>= r
140-
6br/4Bppk/5P2/5P1K/4B1P1/8/8/8 b - - ? 99 g7g5
141-
nsols 1
157+
>>> 6br/4Bp1k/5P2/5PpK/4B1P1/8/8/8 w - ? ? 100
158+
6br/4Bp1k/5P2/5PpK/4B1P1/8/8/8 w - - ? 100
159+
6br/4Bp1k/5P2/5PpK/4B1P1/8/8/8 w - g6 ? 100
160+
nsols 2
142161
```
143162

144163
- Not all 6 FEN tokens are necessary. If fewer tokens are specified, the
145-
remaining will be filled with `?`. For example:
146-
```
147-
>>> 8/7Q/8/4BB2/2PP1P2/3NkN2/PP2P1P1/4K2R w >>= r
148-
8/7Q/8/4BB2/2PPkP2/3N1N2/PP2P1P1/4K2R b K - ? 0 e4e3
149-
8/7Q/8/4BB2/2PPkP2/3NPN2/PP2P1P1/4K2R b K - ? 0 e4xPe3
150-
8/7Q/8/4BB2/2PPkP2/3NQN2/PP2P1P1/4K2R b K - ? 0 (illegal) e4xQe3
151-
8/7Q/8/4BB2/2PPkP2/3NRN2/PP2P1P1/4K2R b K - ? 0 (illegal) e4xRe3
152-
8/7Q/8/4BB2/2PPkP2/3NBN2/PP2P1P1/4K2R b K - ? 0 e4xBe3
153-
8/7Q/8/4BB2/2PPkP2/3NNN2/PP2P1P1/4K2R b K - ? 0 e4xNe3
154-
nsols 4
155-
```
164+
remaining will be filled with `?`.
156165

157166
- When the halfmove clock is specified, it will be considered in the computation
158167
of retractions. That is, if it is specified to be `0`, the last move must have
159168
been a capture or a pawn move. Analogously, when it is strictly positive, all
160169
retractions will be officer non-captures.
161170
For example:
162171
```
163-
>>> k7/8/2K5/8/8/8/8/8 b - - 0 50 >>= r
164-
k7/3K4/2p5/8/8/8/8/8 w - - ? 50 d7xPc6
165-
k7/3K4/2q5/8/8/8/8/8 w - - ? 50 d7xQc6
166-
k7/3K4/2r5/8/8/8/8/8 w - - ? 50 d7xRc6
172+
>>> k7/8/2K5/8/8/8/8/8 b - - 0 50 >>= r >>= legal
173+
↶d7xPc6 k7/3K4/2p5/8/8/8/8/8 w - - ? 50
174+
↶d7xQc6 k7/3K4/2q5/8/8/8/8/8 w - - ? 50
175+
↶d7xRc6 k7/3K4/2r5/8/8/8/8/8 w - - ? 50
167176
...
168177
nsols 21
169178
```
170179
but
171180
```
172-
>>> k7/8/2K5/8/8/8/8/8 b - - 1 50 >>= r
181+
>>> k7/8/2K5/8/8/8/8/8 b - - 1 50 >>= r >>= legal
182+
↶d7c6 dead k7/3K4/8/8/8/8/8/8 w - - 0 50
183+
↶d5c6 dead k7/8/8/3K4/8/8/8/8 w - - 0 50
184+
↶b5c6 dead k7/8/8/1K6/8/8/8/8 w - - 0 50
185+
↶c7c6 zombie k7/2K5/8/8/8/8/8/8 w - - 0 50
186+
↶c5c6 dead k7/8/8/2K5/8/8/8/8 w - - 0 50
187+
↶d6c6 dead k7/8/3K4/8/8/8/8/8 w - - 0 50
188+
↶b6c6 zombie k7/8/1K6/8/8/8/8/8 w - - 0 50
173189
nsols 0
174190
```
175191

@@ -181,14 +197,14 @@ nsols 1
181197
term `half-duplex` next to the specification. For example:
182198
```
183199
>>> 8/8/2B5/5Q2/8/4p2P/4k2K/8 w - - >>= h#3 half-duplex
184-
f5b1 e2f2 c6h1 e3e2 b1f1 e2f1n#
200+
f5b1 e2f2 c6h1 e3e2 b1f1 e2f1n# 8/8/8/8/8/7P/4pk1K/5Q1B b - - 1 3
185201
nsols 1
186202
```
187203
Furthermore, if the term `duplex` is specified, both WTM and BTM positions
188204
will be considered.
189205

190206
- For the impatient folk, you can run Deadpos with flag `--fast` to
191-
significtly speed-up the analysis of dead positions. This means the analysis
207+
significantly speed-up the analysis of dead positions. This means the analysis
192208
may miss some complicated dead positions and there is no way to know about it.
193209
Use this flag if you want to find cooks (if they exist, they will probably
194210
be found with this method) or you are designing a problem. However, in order
@@ -197,7 +213,6 @@ nsols 1
197213

198214
- You can disable the progress bar with `--no-progress-bar`.
199215

200-
- You can use flag `--verbose` to get a more detailed output.
201216

202217
## Feedback
203218

src/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ get-retractor:
2525
cd ../lib/retractor && eval `(opam env)` && dune build
2626

2727
test:
28-
cat ../test/test-vectors.txt | python3 deadpos.py --verbose --no-progress-bar > /tmp/test-vectors.out
28+
cat ../test/test-vectors.txt | python3 deadpos.py --no-progress-bar > /tmp/test-vectors.out
2929
diff ../test/test-vectors.out /tmp/test-vectors.out
3030

3131
pdb-tests:
32-
cat ../test/PDB.txt | grep -v Slow | python3 deadpos.py --verbose --no-progress-bar > /tmp/PDB.out
32+
cat ../test/PDB.txt | grep -v Slow | python3 deadpos.py --no-progress-bar > /tmp/PDB.out
3333
diff ../test/PDB.out /tmp/PDB.out
3434

3535
promote-tests:

0 commit comments

Comments
 (0)