Beispiel #1
0
 def makeMove(self, board1, move, board2):
     log.debug("Human.makeMove: move=%s, board1=%s board2=%s" %
               (move, board1, board2))
     if self.board.view.premove_piece and self.board.view.premove0 and \
             self.board.view.premove1 and \
             self.color == self.board.view.premove_piece.color:
         if validate(
                 board1,
                 Move(self.board.view.premove0,
                      self.board.view.premove1,
                      board1,
                      promotion=self.board.view.premove_promotion)):
             log.debug("Human.makeMove: Setting move to premove %s %s" %
                       (self.board.view.premove0, self.board.view.premove1))
             self.board.emit_move_signal(
                 self.board.view.premove0,
                 self.board.view.premove1,
                 promotion=self.board.view.premove_promotion)
         # reset premove
         self.board.view.setPremove(None, None, None, None)
     self.gmwidg.setLocked(False)
     item = self.queue.get(block=True)
     self.gmwidg.setLocked(True)
     if item == "del":
         raise PlayerIsDead("Killed by foreign forces")
     if item == "int":
         log.debug("Human.makeMove: %s: raise TurnInterrupt" % self)
         raise TurnInterrupt
     return item
Beispiel #2
0
    def makeMove(self, board1, move, board2):
        """ Gets a move from the engine (for player engines).
            @param board1: The current board
            @param move: The last move made
            @param board2: The board before the last move was made
            @return: The move the engine decided to make
        """
        log.debug(
            "makeMove: move=%s self.movenext=%s board1=%s board2=%s self.board=%s"
            % (move, self.movenext, board1, board2, self.board),
            extra={"task": self.defname})
        assert self.readyMoves
        self.boardLock.acquire()
        try:
            if self.board == board1 or not board2 or self.movenext:
                self.board = board1
                self.__tellEngineToPlayCurrentColorAndMakeMove()
                self.movenext = False
            else:
                self.board = board1
                self.__usermove(board2, move)

                if self.engineIsInNotPlaying:
                    self.__tellEngineToPlayCurrentColorAndMakeMove()
        finally:
            self.boardLock.release()
        self.waitingForMove = True
        self.readyForMoveNowCommand = True

        # Parse outputs
        status = self.returnQueue.get()
        if status == "not ready":
            log.warning(
                "Engine seems to be protover=2, but is treated as protover=1",
                extra={"task": self.defname})
            status = self.returnQueue.get()
        if status == "ready":
            status = self.returnQueue.get()
        if status == "invalid":
            raise InvalidMove
        if status == "del":
            raise PlayerIsDead("Killed by foreign forces")
        if status == "int":
            raise TurnInterrupt

        self.waitingForMove = False
        self.readyForMoveNowCommand = False
        assert isinstance(status, Move), status
        return status