# Buggy code
def start(self, engine):
    self.info = {}
    self.stopped = False
    self.final_pong = None
    self.draw_offered = False

    # Set game, position and configure.
    engine._new(board, game, options)

    # Limit or time control.
    increment = limit.white_inc if board.turn else limit.black_inc
    if limit.remaining_moves or increment:
        base_mins, base_secs = divmod(
            int(limit.white_clock if board.turn else limit.black_clock), 60
        )
        engine.send_line(
            "level {} {}:{:02d} {}".format(
                limit.remaining_moves or 0, base_mins, base_secs, increment
            )
        )

    if limit.nodes is not None:
        if (
            limit.time is not None
            or limit.white_clock is not None
            or limit.black_clock is not None
            or increment is not None
        ):
            raise EngineError(
                "xboard does not support mixing node limits with time limits"
            )

        if "nps" not in engine.features:
            LOGGER.warning(
                "%s: Engine did not declare explicit support for node limits (feature nps=?)"
            )
        elif not engine.features["nps"]:
            raise EngineError(
                "xboard engine does not support node limits (feature nps=0)"
            )

        engine.send_line("nps 1")
        engine.send_line("st {}".format(int(limit.nodes)))
    if limit.depth is not None:
        engine.send_line("sd {}".format(limit.depth))
    if limit.time is not None:
        engine.send_line("st {}".format(limit.time))
    if limit.white_clock is not None:
        engine.send_line(
            "{} {}".format(
                "time" if board.turn else "otim", int(limit.white_clock * 100)
            )
        )
    if limit.black_clock is not None:
        engine.send_line(
            "{} {}".format(
                "otim" if board.turn else "time", int(limit.black_clock * 100)
            )
        )

    # Start thinking.
    engine.send_line("post" if info else "nopost")
    engine.send_line("hard" if ponder else "easy")
    engine.send_line("go")


# Traceback (asyncio.futures.InvalidStateError)
Exception in callback EngineProtocol.pipe_data_received(1, b'you play bo...Drawn game}\n')
handle: <Handle EngineProtocol.pipe_data_received(1, b'you play bo...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 602, in pipe_data_received
self._line_received(line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 615, in _line_received
self.command._line_received(self, line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 869, in _line_received
self.line_received(engine, line)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1716, in line_received
self._move(engine, line.split(" ", 1)[1])
File "/home/pascal/.local/lib/python3.5/site-packages/chess/engine.py", line 1748, in _move
self.result.set_result(PlayResult(move, None, self.info, self.draw_offered))
File "/usr/lib/python3.5/asyncio/futures.py", line 348, in set_result
raise InvalidStateError('{}: {!r}'.format(self._state, self))
asyncio.futures.InvalidStateError: FINISHED: <Future finished result=<PlayResult a...ffered=False)>>
Traceback (most recent call last):
File "./tournament.py", line 96, in <module>
board.push(result.move)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/__init__.py", line 1942, in push
move = self._to_chess960(move)
File "/home/pascal/.local/lib/python3.5/site-packages/chess/__init__.py", line 3318, in _to_chess960
if move.from_square == E1 and self.kings &amp; BB_E1:
AttributeError: 'NoneType' object has no attribute 'from_square'

# Fixed code
def start(self, engine):
    self.play_result = PlayResult(None, None)
    self.stopped = False
    self.pong_after_move = None
    self.pong_after_ponder = None

    # Set game, position and configure.
    engine._new(board, game, options)

    # Limit or time control.
    increment = limit.white_inc if board.turn else limit.black_inc
    if limit.remaining_moves or increment:
        base_mins, base_secs = divmod(
            int(limit.white_clock if board.turn else limit.black_clock), 60
        )
        engine.send_line(
            "level {} {}:{:02d} {}".format(
                limit.remaining_moves or 0, base_mins, base_secs, increment
            )
        )

    if limit.nodes is not None:
        if (
            limit.time is not None
            or limit.white_clock is not None
            or limit.black_clock is not None
            or increment is not None
        ):
            raise EngineError(
                "xboard does not support mixing node limits with time limits"
            )

        if "nps" not in engine.features:
            LOGGER.warning(
                "%s: Engine did not declare explicit support for node limits (feature nps=?)"
            )
        elif not engine.features["nps"]:
            raise EngineError(
                "xboard engine does not support node limits (feature nps=0)"
            )

        engine.send_line("nps 1")
        engine.send_line("st {}".format(int(limit.nodes)))
    if limit.depth is not None:
        engine.send_line("sd {}".format(limit.depth))
    if limit.time is not None:
        engine.send_line("st {}".format(limit.time))
    if limit.white_clock is not None:
        engine.send_line(
            "{} {}".format(
                "time" if board.turn else "otim", int(limit.white_clock * 100)
            )
        )
    if limit.black_clock is not None:
        engine.send_line(
            "{} {}".format(
                "otim" if board.turn else "time", int(limit.black_clock * 100)
            )
        )

    # Start thinking.
    engine.send_line("post" if info else "nopost")
    engine.send_line("hard" if ponder else "easy")
    engine.send_line("go")