scalachess icon indicating copy to clipboard operation
scalachess copied to clipboard

Generalize Pgn

Open lenguyenthanh opened this issue 2 months ago • 0 comments

Motivation

Currently, We need convert any data structure (mostly Game and Study) to Pgn and then using Pgn.render to build PgnStr. It'd better if We could just go from any Node[A] to PgnStr directly if A can be render as SanStr.

Proposal

Here is the a draft of what I'm thinking about

// Or ToSanStr
trait SanEncoder[A]:
  def encode[A]: SanStr
  
extension (node: Node[A])(using SanEncoder[A]):
  def toPgnString: PgnStr = ??? // The implement will be similar to current `Pgn.render`

So, in the future We can define SanEncoder for study.Branch and then study.toPgnStr directly without any intermediate data structure like our current Pgn.

Potential issue

lila's Annotator is used for annotating a Pgn directly which will need to change how it works.

lenguyenthanh avatar Apr 14 '24 02:04 lenguyenthanh