code method to get ECO code/opening name

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
adams161
Posts: 490
Joined: Sun May 13, 2007 7:55 pm
Location: Tacoma, WA USA

code method to get ECO code/opening name

Post by adams161 » Sun Apr 27, 2014 10:38 am

Hi,

Some of you may know me. I've written the Pulsar Chess engine. My current dilemma, and I've been googling but not finding anything, is if you have a PGN you're looking at or a move list, and i can obviously generate a fen of the current position, how could you get the ECO code and opening name. Is there a package to use in the C language? Is there is just data like these are the fens and these are the ECO codes and opening names, that would actually be preferable. Then i could check the position starting on move one and see what is the opening till i'm 'out of book'.

thanks for any ideas on how to do this.

Mike

Ferdy
Posts: 3816
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: code method to get ECO code/opening name

Post by Ferdy » Sun Apr 27, 2014 1:00 pm

Have a look on the eco.pgn from here.
https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/
Last edited by Ferdy on Sun Apr 27, 2014 1:12 pm, edited 2 times in total.

Edmund
Posts: 668
Joined: Mon Dec 03, 2007 2:01 pm
Location: Barcelona, Spain
Contact:

Re: code method to get ECO code/opening name

Post by Edmund » Sun Apr 27, 2014 1:01 pm

You will probably have to build your own ECO-Codes-"opening book".
But there are lists on the web, that associate opening lines with eco-codes and names:

e.g.:
http://www.dwheeler.com/chessclub/ http://www.geocities.com/SiliconValley/ ... /chess.htm (Opening)

adams161
Posts: 490
Joined: Sun May 13, 2007 7:55 pm
Location: Tacoma, WA USA

Re: code method to get ECO code/opening name

Post by adams161 » Sun Apr 27, 2014 3:37 pm

thanks for the links/ideas. I will check out both links and i was thinking as mentioned i could build a book from the lines that are associated with codes. thanks again

User avatar
hgm
Posts: 23155
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: code method to get ECO code/opening name

Post by hgm » Sun Apr 27, 2014 4:57 pm

Edmund wrote:You will probably have to build your own ECO-Codes-"opening book".
But there are lists on the web, that associate opening lines with eco-codes and names:

e.g.:
http://www.dwheeler.com/chessclub/ http://www.geocities.com/SiliconValley/ ... /chess.htm (Opening)
This is actually something that is still on my to-do list: to make a Polyglot book where the learn field is used to hold the ECO code of the current position.

jdart
Posts: 3719
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: code method to get ECO code/opening name

Post by jdart » Tue Apr 29, 2014 4:25 am

It is a difficult problem because of transpositions. Even ChessBase is inconsistent in how they classify certain opening lines.

I have a text file https://github.com/jdart1/arasan-chess/ ... r/book/eco that is is used to generate a lookup table of position hashcodes -> ECO codes. In case of multiple matches during the game the code takes the match with the greatest ply distance from the starting position. It handles some transpositions but not all of them.

--Jon

adams161
Posts: 490
Joined: Sun May 13, 2007 7:55 pm
Location: Tacoma, WA USA

Re: code method to get ECO code/opening name

Post by adams161 » Sat May 03, 2014 6:22 am

I think I'm going to parse the pgn to the final position then database the eco code and opening name of the position using info in this post to find the eco and moves/pgn. But that is interesting that two codes could have the same position. I'm only concerned with matching the board on each move to see if it's in database. I'd update the opening name on each move deep till no more matches against my eco position database. But that is interesting if two final positions could have same code.

Mike

jdart
Posts: 3719
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: code method to get ECO code/opening name

Post by jdart » Sat May 03, 2014 11:07 am

Here is an example:

[pgn]
[Event "Wch U20 Girls 28th"]
[Site "Chotowa"]
[Date "2010.08.04"]
[Round "2"]
[White "Rysbayeva, Nazerke"]
[Black "Olsarova, Tereza"]
[Result "1-0"]
[ECO "A70"]
[WhiteElo "2052"]
[BlackElo "2252"]
[PlyCount "63"]
[EventDate "2010.08.03"]
[EventType "swiss"]
[EventRounds "13"]
[EventCountry "POL"]
[Source "ChessBase"]
[SourceDate "2010.09.01"]

1. d4 Nf6 2. c4 c5 3. d5 e6 4. Nc3 exd5 5. cxd5 d6 6. Nf3 g6 7. e4 Bg7 8. h3 a6
9. a4 Nbd7 10. Bd3 Nh5 11. O-O Ne5 12. Be2 Nxf3+ 13. Bxf3 Qh4 14. Bg4 O-O 15.
Bxc8 Raxc8 16. Qg4 Qe7 17. Bg5 Qc7 18. Rfe1 Qa5 19. Be7 Be5 20. Bxf8 Rxf8 21.
g3 Qb4 22. Rab1 Bd4 23. Kg2 Re8 24. Qd7 Nf6 25. Qc7 c4 26. Red1 Bc5 27. Re1 Kf8
28. a5 Kg7 29. f4 Ng8 30. e5 Nh6 31. Qd7 Kf8 32. e6 1-0
[/pgn]

ChessBase says this is ECO code A70. A70 is supposed to contain the line 1. d4 Nf6 2. c4 c5 3. d5 e6 4. Nc3 exd5 5. cxd5 d6 6. e4 g6 7. Nf3 Bg7, so this looks right.

But ChessBase classified this game as A65:

[pgn]
[Event "Lucija op 3rd"]
[Site "Lucija"]
[Date "2011.08.14"]
[Round "3"]
[White "Janzelj, Tim"]
[Black "Beletic, Daniel"]
[Result "1-0"]
[ECO "A65"]
[WhiteElo "2047"]
[BlackElo "2215"]
[PlyCount "73"]
[EventDate "2011.08.14"]
[EventType "swiss"]
[EventRounds "9"]
[EventCountry "SLO"]
[Source "ChessBase"]
[SourceDate "2011.11.24"]

1. d4 Nf6 2. c4 c5 3. d5 e6 4. Nc3 exd5 5. cxd5 d6 6. e4 g6 7. h3 a6 8. a4 Bg7
9. Nf3 Nbd7 10. Bd3 Nh5 11. O-O Ne5 12. Be2 Nxf3+ 13. Bxf3 Qh4 14. Ne2 O-O 15.
Bxh5 Qxh5 16. Bf4 Be5 17. Bxe5 Qxe5 18. Nc3 f5 19. f4 Qd4+ 20. Rf2 Re8 21. Qe1
fxe4 22. Rd1 Qg7 23. Re2 Bd7 24. Nxe4 Bxa4 25. Rdd2 Bb5 26. Re3 Qf8 27. Qh4 Kg7
28. f5 gxf5 29. Rg3+ Kh8 30. Nf6 Qe7 31. Qh6 Rf8 32. Rg6 Rf7 33. Rf2 Qe1+ 34.
Kh2 Qxf2 35. Qg5 Raf8 36. Qh6 Rxf6 37. Qg7# 1-0
[/pgn]

Here White has delayed Nf3 but it was eventually played on move 9, and the position up to 13. .. Qh4 is the same as the first game.

There are lots of transpositions within and between the Benoni lines (A60-A69) and King's Indian (E90-E90).

--Jon

jdart
Posts: 3719
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: code method to get ECO code/opening name

Post by jdart » Sat May 03, 2014 4:16 pm

another example is this position:

[D] r1bq1rk1/pp1n1ppp/4pn2/6B1/1bBP4/2N2N2/PP3PPP/R2Q1RK1 b - - 0 10

which is usually classified as a Nimzo-Indian (E54) but can also be reached via many other move orders, starting out from the Queen's Gambit, Caro-Kann, or Sicilian Defense. ChessBase is inconsistent about classifying such games.

--Jon

Post Reply