Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryFen in python-chess #1099

Open
Torom opened this issue Jul 22, 2024 · 4 comments
Open

BinaryFen in python-chess #1099

Torom opened this issue Jul 22, 2024 · 4 comments

Comments

@Torom
Copy link

Torom commented Jul 22, 2024

You introduced the efficient BinaryFen in this blog post on Lichess.

My question is whether it would be possible to implement this in python-chess. I guess python-chess is used by quite a few people to store a lot of positions (at least I do). For this it would be very helpful to be able to use the space-saving and reversible BinaryFen.

Thank you for this awesome library.

@vondele
Copy link

vondele commented Aug 18, 2024

indeed, would be real nice to have.

@vondele
Copy link

vondele commented Aug 22, 2024

see also Disservin/chess-library#109

@Torom
Copy link
Author

Torom commented Aug 28, 2024

Here is my implementation in Python:

https://github.com/Torom/BinaryFen_python/blob/main/BinaryFen.py

It is definitely not perfect, pretty much a 1:1 conversion of Disservin's implementation.
So it also has no adaptations to variants.
And the size savings in Python also seem to be rather small:

>>> sys.getsizeof(bytearray(24))
81
>>> sys.getsizeof(chess.Board().epd())
93

Edit:
Okay apparently it was unnecessary to return bytearray. It gets better with bytes:

>>> sys.getsizeof(bytes(24))
57

@niklasf
Copy link
Owner

niklasf commented Aug 29, 2024

I'd imagine that this will be most useful when serializing to disk, so despite the relatively large memory usage as per sys.getsizeof(bytes(24)), it's really the 24 that makes it interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants