Skip to content

Conversation

@adbar
Copy link
Contributor

@adbar adbar commented Jan 5, 2025

Hi @niklasf, I was having a look at the code to understand how endgame databases work and I saw that the Gaviota part of the code could be improved. Here is a first step:

  • Duplicate lines removed
  • Reduced code complexity (good for maintenance...)
  • Convenience functions introduced to avoid repetitions

The whole structure is the same so the PR should hopefully be easy enough to review. The tests pass and the code should also run faster.

@adbar
Copy link
Contributor Author

adbar commented Jan 5, 2025

There are apparently lines not covered by the tests that mypy was able to catch. I am open to modifying the code if it needs improvement.

@niklasf
Copy link
Owner

niklasf commented Jan 8, 2025

Thanks, looks good! Will test offline with a larger test suite just to be sure.

@niklasf
Copy link
Owner

niklasf commented Jan 11, 2025

Found #1132 (happy if someone wants to take a look), but that's not a regression. So merging this.

@niklasf niklasf merged commit 91699cd into niklasf:master Jan 11, 2025
22 checks passed
@adbar adbar deleted the shorter_gaviota branch January 12, 2025 11:17
niklasf added a commit that referenced this pull request Feb 23, 2025
The resulting code is not equivalent, that is, when the full tablebase
is available ./test.py GaviotaTestCase fails with

    ERROR: test_dm_4 (__main__.GaviotaTestCase.test_dm_4)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/niklas/Projekte/python-chess/./test.py", line 35, in _wrapper
        return f(self)
      File "/home/niklas/Projekte/python-chess/./test.py", line 4305, in test_dm_4
        dtm = self.tablebase.probe_dtm(board)
      File "/home/niklas/Projekte/python-chess/chess/gaviota.py", line 1393, in probe_dtm
        dtm = self.egtb_get_dtm(req)
      File "/home/niklas/Projekte/python-chess/chess/gaviota.py", line 1518, in egtb_get_dtm
        dtm = self._tb_probe(req)
      File "/home/niklas/Projekte/python-chess/chess/gaviota.py", line 1621, in _tb_probe
        buffer_zipped = stream.read(z)
    ValueError: read length must be non-negative or -1
@niklasf
Copy link
Owner

niklasf commented Feb 23, 2025

There appears to be a suble way this is not equivalent, but I don't have the bandwidth to track it down at the moment. Reverted for now via 636e95f (see commit message for the problem).

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

Successfully merging this pull request may close these issues.

3 participants