Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1033.
Adds
Game.set_time_control(time_control), the setter counterpart ofGame.time_control(). It writes theTimeControlheader in the PGN spec format (section 9.6.1), so thatparse_time_control()reads back an equalTimeControl.:. A part is written asmoves/seconds, or as plainsecondsfor sudden death, followed by+incrementor+delaydwhere set. Fractional increments and delays are written with up to 3 decimals, the same wayset_clock()writes them (180+0.5,300+2).TimeControlwithout parts is written as-when its type isUNLIMITED, and as?otherwise.ValueErroris raised, and the header is left unchanged, for values thatparse_time_control()would reject or cannot express: a sudden-death part before the last part, or a part with both an increment and a delay.Game.time_controlandGame.set_time_controlare also added to theGamemembers listed indocs/pgn.rst.The new test
PgnTestCase.test_set_time_controlround-trips headers (40/7200:20/3600:900+30,300+2,180+0.5,5400+30d,1800,-,?) and checks the error cases.Checks run locally:
python test.pyon Python 3.14 and 3.9: 297 tests OK (22 skipped, engine binaries not installed). The new test fails on master withAttributeError: 'Game' object has no attribute 'set_time_control'.python -m mypy --strict chess: no issues.python -m pyright chess/pgn.py: 0 errors (one existing warning abouttyping_extensions).python -m doctest README.rst: only the 3 Stockfish examples fail, because nostockfishbinary is installed.Not run: Windows CI and the perft workflow, which this change does not touch.