Skip to content

Scripts for parse pgns files into a sqlite (among other formats) database

Notifications You must be signed in to change notification settings

jbkunst/chess-db

Repository files navigation

Chess-db

Scripts for parse pgns files into a sqlite (tsv, RData) database/table.

How to use

  • Download a "chess database". For example you can download a big list of pgn from http://www.kingbase-chess.net/.
  • Put all the pgn files in the data-raw folder.
  • Then run the R scripts.
  • If you have a humble pc wait for 2-3 hours (if you download the 1.6M DB).
  • And enjoy your chess database ;) in sqslite, Rdata, tsv format!

Input

The input is a big list of pgns like this:

[Event "22. Abu Dhabi Masters"]
[Site "Abudhabi UAE"]
[Date "2015.08.31"]
[Round "9.38"]
[White "Ris, R"]
[Black "Raja, H"]
[Result "1-0"]
[WhiteElo "2449"]
[BlackElo "2247"]
[ECO "A13"]
[EventDate "2015.08.23"]

1.Nf3 Nf6 2.g3 d5 3.c4 e6 4.Bg2 c5 5.O-O Nc6 6.b3 d4 7.e3 Bd6 8.exd4 cxd4 
9.d3 h6 10.Re1 O-O 11.Ba3 e5 12.Bxd6 Qxd6 13.a3 a5 14.Ra2 Bf5 15.Nh4 Bh7 
16.Bh3 Nd7 17.Nf5 Bxf5 18.Bxf5 g6 19.Be4 f5 20.Bd5+ Kg7 21.Rae2 Rae8 22.
Qd2 Nc5 23.b4 axb4 24.axb4 Nd7 25.b5 Nb4 26.Bxb7 Nxd3 27.Qxd3 Nc5 28.Qa3 
Nxb7 29.Qxd6 Nxd6 30.Rxe5 Rxe5 31.Rxe5 Nxc4 32.Rc5 Re8 33.Kf1 Nb6 34.Nd2 
Na4 35.Rc4 Nb6 36.Rxd4 Re5 37.Rb4 Kf6 38.Rb1 Rd5 39.Nf3 g5 40.Rc1 Rxb5 41.
Rc6+ Kg7 42.Nd4 Rb1+ 43.Kg2 h5 44.Nxf5+ Kf7 45.Nd6+ Kg7 46.Ne4 Nd5 47.Nxg5
Rb2 48.Re6 h4 49.Re5 Nf6 50.Re7+ Kg6 51.Ne4 Ng4 52.h3 Ne3+ 53.Kf3 hxg3 54.
fxg3 Nd5 55.Rd7 Rb3+ 56.Kg4 Ne3+ 57.Kf4 Ng2+ 58.Ke5 Rb5+ 59.Rd5 Rxd5+ 60.
Kxd5 Kf5 61.Nd6+ Kg5 62.Ke4 Nh4 63.Ke3 Kh5 64.Ne4 Ng6 65.Kf3 Ne5+ 66.Kf4 
Ng6+ 67.Kf5 Ne7+ 68.Ke6 Ng6 69.Kf6 Nf8 70.Kf5 Ng6 71.g4+ Kh6 72.g5+ Kg7 
73.Nd6 Kh7 74.Nf7 Kg7 75.Ne5 Nh4+ 76.Kg4 Ng2 77.Nc4 Ne1 78.h4 Nd3 79.h5 
1-0

Output

Is a table where every row is a pgn (a game), see a sample in example_output.tsv

event	site	date	round	white	black	result	whiteelo	blackelo	eco	pgn
FIDE World Cup 2015	Baku AZE	2015-09-29	6.2	Karjakin, Sergey	Eljanov, Pavel	1/2-1/2	2762	2717	A29	1.c4 Nf6 2.Nc3 e5 3.Nf3 Nc6 4.g3 Bb4 5.Bg2 O-O 6.O-O e4 7.Ng5 Bxc3 8.bxc3  Re8 9.f3 exf3 10.Nxf3 Qe7 11.e3 Ne5 12.Nh4 d6 13.d3 Ng6 14.Nxg6 1/2-1/2
16. Karpov Poikovsky	Poikovsky RUS	2015-09-28	1.1	Morozevich, Alexander	Bologan, Viktor	0-1	2711	2607	A07	1.Nf3 d5 2.g3 c6 3.Bg2 Bf5 4.c4 e6 5.Qb3 Qb6 6.d3 Nf6 7.Be3 Qxb3 8.axb3 a6 9.Nh4 Bg6 10.f4 Nbd7 11.h3 Bb4+ 12.Kd1 O-O 13.Nd2 Rfd8 14.Kc2 b5 15.Rhd1  a5 16.Nxg6 hxg6 17.Nf3 Re8 18.Nd4 Rac8 19.Bd2 Nh5 20.cxb5 cxb5+ 21.Kb1  Nxg3 22.Nxb5 Rb8 23.Nd4 Nc5 24.Be3 Nf5 25.Nxf5 gxf5 26.Ka2 Nxb3 27.Rab1  Bd6 28.Ba7 Rb4 29.e4 Ra8 30.Be3 Rab8 0-1
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kg7 51.Rc7 Kf8 52.Bc4 Ra5 53.Rb7 Rc5 54.Bb3  Rc1 55.Bd5 Rc2 56.Rb8+ Kg7 57.Rb7 Kf8 58.Be4 Rd2 59.Rb5 Kg7 60.Rf5 Rd7 61. Ke2 Ra7 62.Bd5 Bd8 63.Kd3 Rd7 64.Kc4 Rc7+ 65.Kb5 f6 66.Be6 Re7 67.Rd5 Bc7  68.Bf5 Re5 69.e4 Re7 1/2-1/2

About

Scripts for parse pgns files into a sqlite (among other formats) database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages