niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.46k stars 531 forks source link

Code refactor, meta stuff #1028

Open bswck opened 1 year ago

bswck commented 1 year ago

Some algorithms do need logic refactoring, for instance

https://github.com/niklasf/python-chess/blob/f76c387ef9c68555a08b1629b56655d85f86d949/chess/syzygy.py#L323-L352

which could simply be truncated into

for i in range(5):
    j = 0
    a = PFACTOR[i]
    p = PAWNIDX[i]

    for k in range(4):
        s = 0
        t = 6 * (k+1)
        while j < t:
            p[j] = s
            s += 1 if i == 0 else binom(PTWIST[INVFLAP[j]], i)
            j += 1
        a[k] = s

I'll work on those enhancements soon. Please let me know what you think about migrating to poetry and maybe possibly migrating tests to pytest to make them easier to read and work with. @niklasf

niklasf commented 1 year ago

Hi, some thoughts about these:

For pytest, at a glance I don't see how it would improve dx for this project. Do you have any particular features in mind?

kraktus commented 1 year ago

About (4), I think as long as you import from __future__ importannotations, you should be able to use the new syntax just fine, we use it on berserk and support 3.8

bswck commented 7 months ago

It can actually work even for type hints evaluated at runtime since https://github.com/alexmojaki/eval_type_backport.