Skip to content

Commit

Permalink
Return None instead of empty tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Feb 16, 2015
1 parent ac8f705 commit 1f1802c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,17 @@ Features
>>> engine = chess.uci.popen_engine("/usr/games/stockfish")
>>> engine.uci()
()
>>> engine.author
'Tord Romstad, Marco Costalba and Joona Kiiski'
>>> # Synchronous mode.
>>> board = chess.Bitboard("1k1r4/pp1b1R2/3q2pp/4p3/2B5/4Q3/PPP2B2/2K5 b - - 0 1")
>>> engine.position(board)
()
>>> engine.go(movetime=2000) # Gets tuple of bestmove and pondermove.
(Move.from_uci('d6d1'), Move.from_uci('c1d1'))
>>> # Synchronous communication, but search in background.
>>> engine.go(infinite=True)
()
>>> time.sleep(2)
>>> engine.stop()
(Move.from_uci('d6d1'), Move.from_uci('c1d1'))
Expand Down
24 changes: 14 additions & 10 deletions chess/uci.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def _notify(self, result):

def _notify_callback(self):
if self._callback and not self._callback is True:
if self.result is None:
self._callback()
return

try:
iter(self.result)
except TypeError:
Expand Down Expand Up @@ -255,7 +259,7 @@ def _execute(self, engine):
engine.uciok.clear()
engine.process.send_line("uci")
engine.uciok.wait()
self._notify(())
self._notify(None)


class DebugCommand(Command):
Expand All @@ -268,7 +272,7 @@ def _execute(self, engine):
engine.process.send_line("debug on")
else:
engine.process.send_line("debug off")
self._notify(())
self._notify(None)


class IsReadyCommand(Command):
Expand All @@ -279,7 +283,7 @@ def _execute(self, engine):
engine.readyok.clear()
engine.process.send_line("isready")
engine.readyok.wait()
self._notify(())
self._notify(None)


class SetOptionCommand(IsReadyCommand):
Expand Down Expand Up @@ -417,7 +421,7 @@ def _execute(self, engine):
engine.bestmove_received.clear()
engine.process.send_line(self.buf)
if self.infinite:
self._notify(())
self._notify(None)
else:
engine.bestmove_received.wait()
self._notify((engine.bestmove, engine.ponder))
Expand Down Expand Up @@ -971,7 +975,7 @@ def debug(self, on, async_callback=None):
:param on: bool
:return: ()
:return: Nothing
"""
return self.queue_command(DebugCommand(on, async_callback))

Expand All @@ -982,7 +986,7 @@ def isready(self, async_callback=None):
The engine will respond as soon as it has handled all other queued
commands.
:return: ()
:return: Nothing
"""
return self.queue_command(IsReadyCommand(async_callback))

Expand All @@ -992,7 +996,7 @@ def setoption(self, options, async_callback=None):
:param options: A dictionary with option names as keys.
:return: ()
:return: Nothing
"""
return self.queue_command(SetOptionCommand(options, async_callback))

Expand All @@ -1006,7 +1010,7 @@ def ucinewgame(self, async_callback=None):
analyse a position from a different game. Using this command is
recommended but not required.
:return: ()
:return: Nothing
"""
return self.queue_command(UciNewGameCommand(async_callback))

Expand All @@ -1023,7 +1027,7 @@ def position(self, board, async_callback=None):
:param board: A *chess.Bitboard*.
:return: ()
:return: Nothing
"""
return self.queue_command(PositionCommand(board, async_callback))

Expand Down Expand Up @@ -1075,7 +1079,7 @@ def ponderhit(self, async_callback=None):
The engine should continue searching but should switch from pondering
to normal search.
:return: ()
:return: Nothing
"""
return self.queue_command(PonderhitCommand(async_callback))

Expand Down

0 comments on commit 1f1802c

Please sign in to comment.