zcesur / opening-repertoire

Build opening repertoires from chess games in PGN format
BSD 3-Clause "New" or "Revised" License
14 stars 2 forks source link

awesome library! any chance to show the number of occurences for each line? #1

Closed vesper8 closed 3 years ago

vesper8 commented 3 years ago

First of all thanks for making this! It's the first time I touch Rust and it was so easy to get this running.

I was wondering if would be possible to also show how many times each variation is actually encountered in the list of PGN games provided?

Right now I'm struggling to understand how to tell which is the best line/variation to play based on how often it's played.. maybe I'm just not getting how to interpret the results? I'm planning to use this in my own chess tool that I'm building so that's why I want to know how best to read the results.

Thanks!

zcesur commented 3 years ago

My pleasure!

The output should be unambiguous with respect to the repertoire color you provide, because lesser played moves (of your color) are pruned by the library. As a result, there is a single response for each opponent move.

vesper8 commented 3 years ago

Hrm.. would you mind explaining a little more what it does exactly?

Like how does it decide which moves are "lesser" ? Does it deem all lines that did not lead to a victory as part of a lesser line?

Is it a fair statement to say that if I pass it, for example Eric Rosen's collection of 5000 played PGNs, and then I run a command such as opening-repertoire -p ../pgn/chess.com_IMRosen_white.pgn -c white -s d4,d5,Bf4,Nf6, then this would be an efficient way of having it return the most popular (most common) reply to the above line?

zcesur commented 3 years ago

Like how does it decide which moves are "lesser" ? Does it deem all lines that did not lead to a victory as part of a lesser line?

No, pruning is entirely based on frequency.

Following your example, we can see that Eric has played each of the moves 3.{e3,Nd2,e4,Nf3,Nc3,Bg3} at some point in reply to 2...Nf6, but if you run that command you'll see that only the lines with 3.e3 are included since that's the move he played the most. From there it branches out to 3...{e6,c6,g6,&c}, and for each of those black moves there is again a single white move based on what Eric plays the most.

Does that answer your question?

vesper8 commented 3 years ago

Yes.. I think it does

I think it would have been valuable for me to see the percentage of times he played the most popular move, and the percentage of times he played other moves

I guess I should build my own dataset from his PGNs in order to know this. Sometimes it's useful to not only now the most popular move, as the less popular moves might also be playable and lead to good positions and wins

It would be nice if there were additional flags that can be passed on the CLI to retrieve this extra information.. occurrences of each moves in the collection of PGNs and percentage played vs other moves

Perhaps this is out of scope though if your one and only concern was to make something you can then plug into the likes of Lichess / Chessable

I haven't figured out how I'm supposed to "import" the results of your CLI tool into Lichess by the way.. perhaps a small section explaining how this output is meant to be used specifically would be a good addition to your Readme

Cheers! Thanks for taking the time to answer me

zcesur commented 3 years ago

I see, yeah that's a totally valid use case!

I've added a couple new flags so you can inspect the opening tree. At each node you'll see a move along with the # of times it has occurred. Check out --output-type and --disable-pruning

Eventually we can put this info in the PGN itself, perhaps by utilizing tags or comments.

I haven't figured out how I'm supposed to "import" the results of your CLI tool into Lichess by the way.. perhaps a small section explaining how this output is meant to be used specifically would be a good addition to your Readme

Check out their study tool. Frankly I don't think the output of this program is best suited for lichess at the moment since they allow importing up to merely 20 games at a time. Perhaps we could support another type of PGN output where the entire opening tree is collapsed into a single game with many sub-variations to get around that restriction.

vesper8 commented 3 years ago

Awesome! Thanks for the super quick additions!

While I have your attention.. It would be enormously helpful if you added a --ouput-format json. Right now I'm having to parse your different outputs.. indents and special characters included ;) in order to get at the data I want and it would be so much easier if it was all json arrays

You see I'm calling your program from a script

vesper8 commented 3 years ago

Another feature which I think would be cool is if you could pass a username as an option, so that you could then use a pgn containing both black and white games, and by passing -c white and --username EricRosen then it would only include games with that username playing white in the computations

zcesur commented 3 years ago

Just added json support.

What kind of tool are you building? Curious to know more about it!

Feel free to open another issue for the latter feature but I won't implement it anytime soon. You're always welcome to submit a PR though. This can be your first foray into Rust - which was also the case for me ;)

vesper8 commented 3 years ago

Awesome thank you!

Is there a command for getting the update quickly?

Right now I've just been re-running cargo install --git https://github.com/zcesur/opening-repertoire

I tried cargo update --git https://github.com/zcesur/opening-repertoire but that didn't work

I'll consider diving in and trying to submit a PR

As for the tool I'm building.. well I'm building quite a few tools actually, it's my personal playground.. aimed at improving my own chess game first and foremost but with the possibility of turning into projects I would want to launch to the public. The one I'm currently toying around with is a tool that would train you to "Play more like insertname__". So it checks your games history and compares it to the history of games by a master-level player and tells you where you deviated from that master's usual lines.

Don't have it anywhere to working yet though.

zcesur commented 3 years ago

Not sure if there's another command for that.

That sounds awesome! I'd love to try out your projects once you feel like sharing them.