Crafty Book Creation

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: Crafty Book Creation

Post by jhaglund »

jwes wrote:
bob wrote:
jhaglund wrote:
Only other issue I can think of is the actual parsing, since comments can be nested. I have seen one that would choke a large mule with comments 14 levels deep. It is a pretty significant change, since encountering a PGN header resets the game to the initial position at present. This would need to back up to the previous position where analysis was found...
Use the current header values or even the defaults, don't reset until you finish stepping through the comments and find no more comment identifiers such as "{(" and then the result_tag '*' at the end of PGN.

Count the steps and inc each time one is found and repeat until none are found.

count = 0;
while(!=result_tag){
If(comment) // find begin chars
grab(); //do your magic

count = count + 1; //line in pgn
step(); // your location

if(result_tag)
reset();

}

next_pgn();
That's not my point. When I find a line starting with "[" I simply reset the game to the starting position and then search for the result tag followed by the first move. This requires more complex code, as I have to remember the point where a "branch" (alternate analyis) starts and when I get to the end, back up to that point. But it has to be "stacked" because nested analysis is perfectly allowable in PGN. Makes the parsing a lot more complicated. Might be easier to write something to eat a PGN file and expand a single game into many games by unnesting the analysis comments...
Also you wouldn't introduce a bug into your regular code trying to handle some special case. :wink:
No chance for a bug. The code would be tested, and can be a separate function from the previous code... & Bob doesn't make mistakes.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Crafty Book Creation

Post by bob »

jhaglund wrote:
jwes wrote:
bob wrote:
jhaglund wrote:
Only other issue I can think of is the actual parsing, since comments can be nested. I have seen one that would choke a large mule with comments 14 levels deep. It is a pretty significant change, since encountering a PGN header resets the game to the initial position at present. This would need to back up to the previous position where analysis was found...
Use the current header values or even the defaults, don't reset until you finish stepping through the comments and find no more comment identifiers such as "{(" and then the result_tag '*' at the end of PGN.

Count the steps and inc each time one is found and repeat until none are found.

count = 0;
while(!=result_tag){
If(comment) // find begin chars
grab(); //do your magic

count = count + 1; //line in pgn
step(); // your location

if(result_tag)
reset();

}

next_pgn();
That's not my point. When I find a line starting with "[" I simply reset the game to the starting position and then search for the result tag followed by the first move. This requires more complex code, as I have to remember the point where a "branch" (alternate analyis) starts and when I get to the end, back up to that point. But it has to be "stacked" because nested analysis is perfectly allowable in PGN. Makes the parsing a lot more complicated. Might be easier to write something to eat a PGN file and expand a single game into many games by unnesting the analysis comments...
Also you wouldn't introduce a bug into your regular code trying to handle some special case. :wink:
No chance for a bug. The code would be tested, and can be a separate function from the previous code... & Bob doesn't make mistakes.
I certainly wish that was true. :)
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: Crafty Book Creation

Post by jhaglund »

I certainly wish that was true.
So does this mean it's added to the to-do list? I'm sure while it sits in que, after awhile, you'll be able to spit out the code like it wasn't that tough to begin with. :)