Heavily inspired by Smallest chess board compression I decided to make a similar but distinctly different competition.
Take the file Chess_Games.txt and compress it as much as you can so that you can expand it to the original file.
Write an algorithm to encode and decode an entire chess database from start position to end
The encoding must be able to determine for all of the games all the positions:
- The location all the pieces
- Whose turn it is
- Whether the player can castle on each side.
- Whether the player can perform an en-passant, and if so, which of their pawns?
- The previous position
- Each game should also include who won and how it ended (forfeit, draw, checkmate, stalemate, etc...)
There should be 2 algorithms Compress/Expand which satisfy the following properties:
Compress takes in a file of games via a sequence of moves via chess notation and output compressed file
Expand does the opposite, taking in a compressed file and outputting the original file with all the games in the same order
Correctness: Expand(Compress(file)) = file for all properly formed files
Any game that is not well formed or violates the rules of chess is considered bad. All bad games may be skipped.
The file should look like the following:
e4 d5 exd5 Nf6 d3 Qxd5 Nc3 Qf5 Be2 Bd7 g4 Qe6 g5 Nd5 Ne4 Bc6 Bg4 Qe5 f4 Qd4 Nf3 Qb6 Qe2 e6 Be3 Qa6 O-O Nd7 c4 Ne7 f5 Bxe4 dxe4 exf5 exf5 O-O-O f6 gxf6 gxf6 Nc6 Nd4 Nxd4 Bxd4 Bc5 Bxc5 Rhg8 Be7 Rde8 b4 Qxf6 Bxf6 Rxe2 h3 h5 Kh1 hxg4 Rg1 Nxf6 Rae1 Rxe1 Rxe1 gxh3 Kh2 Ng4+ Kxh3 Nf2+ Kh2 Ng4+ Kg3 f5 Kf4 Nh6 Re7 Rg4+ Ke5 Kd8 Kf6 Ng8+ Kf7 Nxe7 Kf8 f4 c5 f3 c6 f2 cxb7 Nc6 b8=Q+ Nxb8 Kf7 Kd7 0-1 d3 e6 e3 d5 Nf3 Nf6 Be2 Be7 O-O O-O Nc3 Nbd7 Ne1 c5 f3 e5 e4 d4 Nb1 b6 f4 exf4 Rxf4 Qc7 Rf3 Bd6 g3 Ng4 Rf1 Ndf6 Bxg4 Bxg4 Qd2 Rae8 Qf2 Re5 Bf4 Rh5 Bxd6 Qxd6 Nf3 c4 e5 Rxe5 Nxe5 Qxe5 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6 Ne8 Qa3 Qa7 Red3 b5 Bxb5 cxb5 Rc3+ Kb7 Qe7 b4 Rc5 Rxc5 dxc5 Qxc5 Qxd8 Ndf6 Qb8+ Ka6 Rd8 Qa7 Rxe8 Nxe8 Qxe8 Qc5 Qa8+ Kb5 Qb8+ Ka4 b3+ Ka3 Qf4 Qc3 Qe5 1-0 e4 d5 exd5 Qxd5 Nf3 Qd8 Nc3 e6 Bc4 Nf6 Bb3 Be7 a3 a6 O-O O-O h3 b6 d3 Bb7 Bg5 Nbd7 Ne4 h6 Bh4 Nxe4 Bxe7 Qxe7 dxe4 Bxe4 Re1 Bb7 Ba2 Nf6 b4 Rfd8 Qc1 Qd6 c4 Qc6 Qc2 Rd7 Rac1 Rad8 c5 bxc5 Qxc5 Qb5 Qxb5 axb5 Ne5 Rd2 Bb3 Rb2 Bd1 Rdd2 Re2 Rxe2 Bxe2 Rxe2 Nf3 Ra2 Rxc7 Bd5 Rc8+ Kh7 Ne5 Rxa3 Rf8 Ra1+ Kh2 h5 Rxf7 Kh6 Rf8 Kg5 g3 Kf5 Nd7 Ra2 Nxf6 gxf6 Rg8 Rxf2+ Kg1 Rg2+ Kf1 Rh2 g4+ hxg4 hxg4+ Ke5 Re8 Rh1+ Kf2 Rh2+ Kg3 Rg2+ Kh4 Rf2 Kg3 Rf4 g5 Re4 gxf6 Kxf6 Rf8+ Ke5 Rh8 Re3+ Kf2 Re4 Rh5+ Kd4 Rh6 Rf4+ Kg3 Re4 Rh8 Re3+ 0-1 ...
In order to make things objective, the winner is the algorithm that can compress the files at https://database.lichess.org/ as small as possible. The target database is the "May 2017". The winner is whoever has the smallest file that expands properly.
The file to use is Chess_Games.txt which is the first 10000 games from the "May 2017" database at https://database.lichess.org/ with all of the header information removed. This file will be the benchmark to use. It should be 2,789,897 bytes with a SHA-256 hash of
56b6d2fffc7644bcd126becd03d859a3cf6880fa01a47fa08d4d6a823a4866bc (Pastebin might remove the last newline after game 10000)
Using generic compression algorithms:
- zip: 647,772 bytes (76.841%)
- 7z: 652,813 bytes (76.661%)
- bz2: 722,158 bytes (74.182%)
- xz: 784,980 bytes (71.936%)
- rar: 853,482 bytes (69.487%)
- gz: 923,474 bytes (66.985%)