chess.js icon indicating copy to clipboard operation
chess.js copied to clipboard

Any way to have RAV(Recursive Annotation Variation) in chess.js

Open coffeeDev98 opened this issue 3 years ago • 8 comments

I want to use this package in my project (with chessboardjs package) but I want to keep RAV functionality.

coffeeDev98 avatar Dec 14 '21 15:12 coffeeDev98

@jhlywa Does this package create variations and later discard/ignore them when the user undos and makes another move? Would like to get in touch with you if possible to discuss this.

coffeeDev98 avatar Dec 15 '21 06:12 coffeeDev98

The library doesn't explicitly create variations, it simply uses a stack to keep track of moves - pushing (.move()) and popping (.undo()) as needed. There's currently no support for preserving RAV when loading PGN.

The current PGN parser is dense and brittle. If I can find some time, I'd like roll a new one using a parser generator (e.g. PEG.js).

jhlywa avatar Dec 15 '21 17:12 jhlywa

Came across an es6 rework of this package by @aaronfi (here) which includes move variations but am unable to use the package in my project with React.

coffeeDev98 avatar Dec 16 '21 05:12 coffeeDev98

Hi @coffeeDev98. It was an old project of mine. Definitely could use a rewrite into TypeScript (which I imagine would allow for far cleaner code).

https://github.com/aaronfi/chess-es6-demo is the demo site I wrote that made use of the package you mentioned. This demo repo makes use of the package. Maybe you can mimic its approach? Hope this helps.

aaronfi avatar Dec 21 '21 07:12 aaronfi

Hey @aaronfi , Is it possible to use your es6 rework of chess.js in a React(JS/Typescript) project? Not well versed with Ruby so, I'm having a bit of trouble going through the example code.

coffeeDev98 avatar Dec 22 '21 13:12 coffeeDev98

Hi @coffeeDev98, yes it should be possible. It's just JavaScript. You can ignore the Ruby.

The chess.js library is here: https://github.com/aaronfi/chess-es6-demo/tree/master/chess-es6 The constructor is here: https://github.com/aaronfi/chess-es6-demo/blob/d784f9a31118eb94bde5f2223b62d13c99ad013a/chess-es6/src/chess.js#L11

Here's the line in my demo website where the chess.js library is instantiated: https://github.com/aaronfi/chess-es6-demo/blob/d784f9a31118eb94bde5f2223b62d13c99ad013a/app/assets/javascripts/main.js#L245

I think the chess.js functionality of interest to you might be here: https://github.com/aaronfi/chess-es6-demo/blob/d784f9a31118eb94bde5f2223b62d13c99ad013a/chess-es6/src/chess.js#L144

Let me know if you run into any issues or shortcomings. I've long wanted to revisit this old work and port it over to TypeScript.

Cheers

aaronfi avatar Dec 22 '21 22:12 aaronfi

Hey @aaronfi, Thanks for the help! It was very useful. Had a doubt. Is it possible to implement creating a variation from any point of the match by clicking on the move notation and playing a different move from there with the existing functionalities? Like in PGNViewer (https://mliebelt.github.io/PgnViewerJS/examples.html#1003).

coffeeDev98 avatar Dec 24 '21 05:12 coffeeDev98

Hi, I wrapped some ES6 around chess.js, combined it with my "cm-pgn" module and here I proudly present "cm-chess", which supports variations and annotations: https://github.com/shaack/cm-chess

shaack avatar Jun 28 '22 21:06 shaack