23-NOV-2024

0048 - pgn

I added a fixme to mark where I left off, but I’ve managed a lot of progress on this parser. I switched to a different approach that essentially focused on tokenizing the PGN to a much more convenient representation that was easy to shove into the Variation structure. I’m only missing a few things:

  1. Annotations need to be tokenized so they can be ignored correctly.
  2. Comments similar
  3. Better Section marking, I’m just marking start/end of file, the naming is bad, etc.
  4. The current_position calculation for Variation needs to be modified/replaced to be able to calculate the position at the tip of the log.

I think those things get me enough to parse PGNs. It should also be possible to reverse this and generate a sequence of tokens from a variation, which would make it very useful for comparing game trees and the like later on, also handy for the UI.

I’m currently ignoring the turn marker, but embedding that in the variation could be a pretty handy way to track different positions within the tree. I want to look into having a sort of ‘detached’ cursor that could be used to have multiple referents to a single Variation, I think this will be helpful in lots of ways but it starts to venture into bits of the borrow checker I’ve largely avoided.

Sounds like a problem for future me though.

1116 - pgn

Finished the annotations and comments from above.

2309 - pgn

I need to work a lot on how I navigate around the log.

There is a case, I think, for a specialized cursor that acts as a state machine over the log, that is where the game tracking lives, a single log can have multiple cursors, which can be constantly growing and being pruned as the engine works. It tweaks my design a little, but I think that’s the next natural place to put effort. I think the parser is properly handling PGNs now, so it’s really ‘done’ and should be merged, the conversion to a variation is what’s broken, but it’s separate from the ‘current_position’ problem that I think this will solve.

I also want to consider embedding the number of moves contained in a variation as part of the variation itself. This would have to be done in a second pass after tokenization, but it would make the skip-ahead logic much easier.

I’m going to split this work into a new branch, then kill mutants until I can merge pgn. The tests for the actual pgn class will be lacking, but I think I’ll just have to make it up elsewhere.