chess.js
chess.js copied to clipboard
Enhancement: Parse Clock time comments
Eg: PGN with clock timing comments should be parsed
[Event "Playzone game"]
[Site "https://protected-play.chess24.com/play/7847b6f475d6"]
[Date "2021.2.8"]
[Round "1.4"]
[White "Anish Giri"]
[Black "Teimour Radjabov"]
[Result "*"]
[WhiteTitle "GM"]
[BlackTitle "GM"]
[UTCDate "2021.02.09"]
[UTCTime "15:30:17"]
[Variant "From Position"]
[ECO "?"]
[Opening "?"]
[Annotator "https://lichess.org/@/broadcaster"]
1. e4 { [%clk 0:15:20] } 1... c5 { [%clk 0:15:20] } 2. Nf3 { [%clk 0:15:28] } 2... Nc6 { [%clk 0:15:28] } 3. d4 { [%clk 0:15:37] } 3... cxd4 { [%clk 0:15:37] } 4. Nxd4 { [%clk 0:15:47] } 4... e5 { [%clk 0:15:46] }
For instance:
game.get_clock() // in above position
// -> White: 0:15:47, Black: 0:10:46
I think this could end up with a fundamental rewrite of the comment system entirely, since there can be a lot of stuff between the {}
s.
In my opinion, we should get comments per move. I.e., the Move object should have the comment, with any extra details, parsed just like a PGN. Take this PGN for example:
1. g4 {[%clk 0:09:50.7]} 1... e5 {[%clk 0:09:50.9]} 2. f3 {[%clk 0:09:42.5] This blunders mate}
2... Qh4# {[%clk 0:09:46.7]} 0-1
Say we get move 3, with const move = history({verbose:true})[2]
. We should be able to move.comment.clk
to get "0:09:42.5" and move.comment.text
to get "This blunders mate" just as an example.
I tried to hack something together to make the clock work. It... certainly does work. Here's my code, if it's worth PRing: https://github.com/Chew/chess.js/commit/bc646b344ceeb5480f3951b75c04a55d06fc6d56
Just wanted to leave my comments here before I dive too deep.