scalachess
scalachess copied to clipboard
Generalize Pgn
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.