Skip to content

Commit

Permalink
Test a subset of 5 piece endgames
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 3, 2015
1 parent 404b02f commit 7180030
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 207 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ before_install:
- cd ..
- # Gaviota tablebases
- cd data/gaviota
- wget --no-clobber https://syzygy-tables.info/gaviota/INDEX.txt
- wget --no-clobber --input-file INDEX.txt
- md5sum -c MD5SUMS.txt
- wget --no-clobber --input-file TEST-SOURCE.txt
- cd ../..
install:
- python -c "import sys; sys.exit(int(sys.version_info < (2, 7)));" || pip install unittest2 backport_collections
Expand Down
44 changes: 44 additions & 0 deletions data/endgame-dm-4.epd
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 4 piece endgames for Gaviota tablebase testing.
# Source: http://kirill-kryukov.com/chess/longest-checkmates/longest-checkmates.shtml

1k1K4/8/8/pP6/8/8/8/8 w - a6 dm 0;
8/8/8/1k6/8/8/K5P1/8 w - - dm 28;
8/8/8/8/8/2k5/1R6/K7 w - - dm 16;
8/8/8/5k2/8/8/1Q6/K7 w - - dm 10;
8/8/8/8/8/2k3P1/6P1/K7 w - - dm 32;
8/8/8/8/8/4N3/3N4/K1k5 w - - dm 1;
8/7N/8/8/8/5k2/7P/K7 w - - dm 27;
8/3P4/KBk5/8/8/8/8/8 w - - dm 31;
8/8/7N/8/8/8/8/K1k1B3 w - - dm 33;
8/8/8/8/7B/8/3k4/K2B4 w - - dm 19;
8/8/1R6/2kP4/8/8/8/K7 w - - dm 16;
8/8/8/8/3N4/3k4/2R5/K7 w - - dm 16;
8/8/8/8/3B4/3k4/2R5/K7 w - - dm 16;
8/8/8/8/8/3k4/2R5/KR6 w - - dm 7;
8/8/8/3k4/8/4P3/8/K1Q5 w - - dm 10;
8/8/5k2/8/8/8/8/KN4Q1 w - - dm 9;
8/5B2/5k2/8/8/8/8/KQ6 w - - dm 8;
8/8/8/8/3k4/2R5/8/K6Q w - - dm 6;
1Q6/Q7/8/8/8/5k2/8/K7 w - - dm 4;
2K5/k7/7p/8/8/8/6P1/8 w - - dm 33;
8/8/8/k7/8/n7/K5P1/8 w - - dm 29;
8/8/8/k7/8/b7/K5P1/8 w - - dm 29;
8/5k2/2PK4/5r2/8/8/8/8 w - - dm 43;
8/8/8/k7/8/q7/K5P1/8 w - - dm 29;
8/8/8/8/p7/8/N7/k1K5 w - - dm 7;
8/8/8/8/8/8/n1K5/k1N5 w - - dm 1;
8/8/8/8/8/8/b7/k1K1N3 w - - dm 1;
8/8/8/8/8/8/r2N4/k1K5 w - - dm 1;
8/8/8/8/8/8/p7/k1K1B3 w - - dm 1;
8/8/8/8/8/8/n1K5/k1B5 w - - dm 1;
8/8/8/8/8/8/b7/k1K1B3 w - - dm 1;
8/8/K7/3p4/8/3k4/4R3/8 w - - dm 26;
8/2R5/8/8/7k/3K4/8/4n3 w - - dm 40;
8/8/8/8/8/2R5/8/3K1bk1 w - - dm 29;
8/8/8/8/8/1R6/6r1/K1k5 w - - dm 19;
8/8/8/8/8/1R6/6q1/K1k5 w - - dm 19;
3Q4/3K4/8/8/8/3k4/3p4/8 w - - dm 28;
8/8/8/8/8/2k5/2n5/KQ6 w - - dm 21;
8/6Q1/8/4b3/3k4/8/8/K7 w - - dm 17;
8/8/8/8/2r5/8/2k5/K6Q w - - dm 35;
8/8/8/8/8/8/8/qk1K2Q1 w - - dm 13;
46 changes: 46 additions & 0 deletions data/endgame-dm-5.epd
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Endgames selected from
# http://kirill-kryukov.com/chess/longest-checkmates/longest-checkmates.shtml
# to test Gaviota tablebase probing.

# kaaak_pctoindex krrrk
# kaabk_pctoindex krrnk
# kaakb_pctoindex knnkn
# kaakp_pctoindex knnkp
# kaapk_pctoindex krrpk
# kabbk_pctoindex kqbbk
# kabck_pctoindex kqrnk
# kabkc_pctoindex kbnkb
# kabkp_pctoindex krnkp
# kabpk_pctoindex krnpk
# kapkb_pctoindex krpkn
# kapkp_pctoindex kbpkp
# kappk_pctoindex knppk
# kppka_pctoindex kppkq
# kppkp_pctoindex kppkp
# kpppk_pctoindex kpppk

8/8/5k2/8/7p/8/PP6/1K6 w - - dm -13;
K7/8/8/8/2k3P1/6P1/6P1/8 w - - dm 33;
7N/K5k1/8/8/8/6P1/6P1/8 w - - dm 32;
6k1/6NR/7P/8/8/8/8/K7 w - - dm 17;
8/K7/8/8/5k2/4RPR1/8/8 w - - dm 14;
8/8/6R1/6Nk/6R1/8/8/K7 w - - dm 10;
8/8/8/8/4k3/5R2/R7/RK6 w - - dm 5;
8/8/8/8/8/1B6/Q1B1k3/K7 w - - dm 6;
Q7/N7/8/8/8/8/3k4/K1R5 w - - dm 5;
8/8/8/8/1p2P3/4P3/1k6/3K4 w - - dm 127;
8/4P3/7q/8/8/8/k1K1P3/8 w - - dm 124;
1N6/8/p7/8/8/8/2k1N3/K7 w - - dm 115;
7n/8/8/8/8/8/2NK4/1kN5 w - - dm 7;
8/7p/8/8/8/1B6/K6P/2k5 w - - dm 67;
8/7B/8/4N3/8/8/3k4/K1b5 w - - dm 39;
8/5n2/8/8/8/7k/7P/3K3R w - - dm 54;
8/8/8/4R3/8/2k3N1/3p4/K7 w - - dm 29;
8/8/7P/3K4/5p2/4p3/8/7k w - - dm 43;
8/8/7P/8/4n3/1k6/8/3K3n w - - dm 74;
3K4/8/1P6/8/6p1/8/4b3/7k w - - dm 51;
1n6/1K1P4/8/8/8/8/4r3/1k6 w - - dm 68;
8/8/8/8/n7/kn6/8/NK6 w - - dm 1;
8/8/8/8/3N4/p7/3r4/k1K5 w - - dm 8;
8/8/8/8/2n5/8/b7/k1K1B3 w - - dm 2;
8/8/8/2K5/5p2/8/1Q2pk2/8 w - - dm 41;
200 changes: 0 additions & 200 deletions data/endgame.epd

This file was deleted.

16 changes: 16 additions & 0 deletions data/gaviota/TEST-SOURCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
https://syzygy-tables.info/gaviota/kqrnk.gtb.cp4
https://syzygy-tables.info/gaviota/krpkn.gtb.cp4
https://syzygy-tables.info/gaviota/kbpkp.gtb.cp4
https://syzygy-tables.info/gaviota/krrpk.gtb.cp4
https://syzygy-tables.info/gaviota/knppk.gtb.cp4
https://syzygy-tables.info/gaviota/kbnkb.gtb.cp4
https://syzygy-tables.info/gaviota/knnkn.gtb.cp4
https://syzygy-tables.info/gaviota/krrnk.gtb.cp4
https://syzygy-tables.info/gaviota/kqbbk.gtb.cp4
https://syzygy-tables.info/gaviota/kppkp.gtb.cp4
https://syzygy-tables.info/gaviota/kppkq.gtb.cp4
https://syzygy-tables.info/gaviota/krrrk.gtb.cp4
https://syzygy-tables.info/gaviota/krnkp.gtb.cp4
https://syzygy-tables.info/gaviota/kpppk.gtb.cp4
https://syzygy-tables.info/gaviota/knnkp.gtb.cp4
https://syzygy-tables.info/gaviota/krnpk.gtb.cp4
25 changes: 21 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2266,8 +2266,8 @@ def setUp(self):
def tearDown(self):
self.tablebases.close()

def test_dm(self):
with open("data/endgame-dm.epd") as epds:
def test_dm_4(self):
with open("data/endgame-dm-4.epd") as epds:
for line, epd in enumerate(epds):
# Skip empty lines and comments.
epd = epd.strip()
Expand All @@ -2277,10 +2277,27 @@ def test_dm(self):
# Parse EPD.
board, extra = chess.Board.from_epd(epd)

# Skip 5 and 6 piece endgames.
if not os.path.exists("egtb/gaviota/kbbbk.gtb.cp4") and chess.pop_count(board.occupied) > 4:
# Check DTM.
if extra["dm"] > 0:
expected = extra["dm"] * 2 - 1
else:
expected = extra["dm"] * 2
dtm = self.tablebases.probe_dtm(board)
self.assertEqual(dtm, expected,
"Expecting dtm {0} for {1}, got {2} (at line {3})".format(expected, board.fen(), dtm, line + 1))

@unittest.skipUnless(os.path.exists("data/gaviota/kqrnk.gtb.cp4"), "need 5 piece gaviota tables")
def test_dm_5(self):
with open("data/endgame-dm-5.epd") as epds:
for line, epd in enumerate(epds):
# Skip empty lines and comments.
epd = epd.strip()
if not epd or epd.startswith("#"):
continue

# Parse EPD.
board, extra = chess.Board.from_epd(epd)

# Check DTM.
if extra["dm"] > 0:
expected = extra["dm"] * 2 - 1
Expand Down

0 comments on commit 7180030

Please sign in to comment.