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

'move' referenced before assignment #382

Closed
pascalgeo opened this issue Mar 18, 2019 · 6 comments
Closed

'move' referenced before assignment #382

pascalgeo opened this issue Mar 18, 2019 · 6 comments
Labels
bug engine Chess engine integration

Comments

@pascalgeo
Copy link

I got that error :

WARNING:chess.engine:<XBoardProtocol (pid=22516)>: Unexpected engine output: you play both
DEBUG:chess.engine:<XBoardProtocol (pid=22516)>: >> level: 6 moves in 0:03, increment 0 seconds
WARNING:chess.engine:<XBoardProtocol (pid=22516)>: Unexpected engine output: level: 6 moves in 0:03, increment 0 seconds
DEBUG:chess.engine:<XBoardProtocol (pid=22516)>: >> post off
WARNING:chess.engine:<XBoardProtocol (pid=22516)>: Unexpected engine output: post off
DEBUG:chess.engine:<XBoardProtocol (pid=22516)>: >> pondering off
WARNING:chess.engine:<XBoardProtocol (pid=22516)>: Unexpected engine output: pondering off
DEBUG:chess.engine:<XBoardProtocol (pid=22516)>: >> move f5g5
ERROR:asyncio:Exception in callback EngineProtocol.pipe_data_received(1, b'move f5g5\n...Drawn game}\n')
handle: <Handle EngineProtocol.pipe_data_received(1, b'move f5g5\n...Drawn game}\n')>
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
self._callback(*self._args)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 603, in pipe_data_received
self._line_received(line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 616, in _line_received
self.command._line_received(self, line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 870, in _line_received
self.line_received(engine, line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1718, in line_received
self._move(engine, line.split(" ", 1)[1])
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1750, in _move
self.result.set_result(PlayResult(move, None, self.info, self.draw_offered))
UnboundLocalError: local variable 'move' referenced before assignment
Traceback (most recent call last):
File "./tournament.py", line 125, in
result = eng.play(board, lim)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 2222, in play
return future.result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 405, in result
return self.__get_result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/usr/lib/python3.5/asyncio/tasks.py", line 381, in wait_for
return (yield from fut)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1779, in play
return (yield from self.communicate(Command))
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 655, in communicate
return (yield from command.result)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
chess.engine.EngineError: invalid or illegal xboard move: 'f5g5' in 7b/8/8/5K2/8/3k4/8/3R4 b - - 100 154

In the code below :

1743             def _move(self, engine, arg):
1744                 if not self.result.cancelled():
1745                     try:
1746                         move = engine.board.push_xboard(arg)
1747                     except ValueError as err:
1748                         self.result.set_exception(EngineError(err))
1749
1750                     self.result.set_result(PlayResult(move, None, self.info, self.draw_offered))
1751
1752                 if not ponder:
1753                     self.end(engine)

I wonder why after a ValueError in move, PlayResult is still called, given that move is not assigned.

@pascalgeo
Copy link
Author

Another error triggered when Stockfish played (it seems that a white move is tried with a board set for black to move). Note that many games are ok, and exceptions are raised in 1/10th of them.

DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove h1f1 currmovenumber 20
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7g5 currmovenumber 21
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7f6 currmovenumber 22
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7f8 currmovenumber 23
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7e8 currmovenumber 24
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7f7 currmovenumber 25
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 currmove e7e6 currmovenumber 26
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> info depth 19 seldepth 31 multipv 1 score cp 19 nodes 1210475 nps 290142 hashfull 434 tbhits 0 time 4172 pv e7a7 b8b1 e1d2 b1h1 d2d3 e8d8 d3c2 h1h2 c5c6 h2g2 c2c3 g2g1 c6c7 d8f8 c3d2 g1g2 d2d3 g2g1 a7b7 g1c1 d3d2 c1c5 b7b6 c5c4 d2d3 c4c1 b6b7 h7h5 a2a3
DEBUG:chess.engine:<UciProtocol (pid=30307)>: >> bestmove e7d7 ponder e8d8
Exception eng.play Traceback (most recent call last):
File "./tournament.py", line 118, in
result = eng.play(board, lim)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 2222, in play
return future.result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 405, in result
return self.__get_result()
File "/usr/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/usr/lib/python3.5/asyncio/tasks.py", line 381, in wait_for
return (yield from fut)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1240, in play
return (yield from self.communicate(Command))
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 655, in communicate
return (yield from command.result)
File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
raise self._exception
chess.engine.EngineError: illegal uci: 'e7d7' in 1r4k1/4Qppp/4p3/2P5/p7/3bPP2/P5PP/4K2R b K - 0 32

DEBUG:chess.engine:<XBoardProtocol (pid=30305)>: >> move e1f2

@niklasf niklasf added bug engine Chess engine integration labels Mar 19, 2019
@niklasf
Copy link
Owner

niklasf commented Mar 19, 2019

As you can tell you're probably one of the first people to use the new engine API extensively. Thanks for not giving up :)

I already noticed and fixed the first issue while working on #379: 419985d.

For the second issue, in order to know where to look, is ponder on or off?

@pascalgeo
Copy link
Author

I do thank you for your work, which eases a lot chess development. I don't give up.

When running games between engines, ponder is off for both engines.

@niklasf
Copy link
Owner

niklasf commented Mar 19, 2019

Small update: I set up a script to run test games, but so far I have failed to reproduce #382 (comment). Surprising, because UciProtocol is the simpler of the two implementations, and there are not many paths it could take.

Any other information that could help reproducing this? A script that triggers it, even after many games, would be great. I'll keep trying either way ...

@pascalgeo
Copy link
Author

I will run games UCI vs xboard 24/7 (on a Raspberry Pi). So far, no more crashes. I set a method to be able to reproduce a scenario in case an error occurs again.

@pascalgeo
Copy link
Author

I set some code to get the context of the game in case of a crash, but I played 200 games with no crash, so I close this issue until I encounter another problem.

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

No branches or pull requests

2 participants