def nobestmove(self): if self.engine.sit.turn == Chess.RED: side = '黑方' else: side = '红方' logger.debug('nobestmove') self.toast.message(f"{side}行棋违例!")
def run(self): logger.debug("Thread started.") while not self.__stopped: self.__wait() if not self.__stopped: try: self.doCall() except Exception, e: logger.critical("Unhandled exception", exc_info=e)
def run(self): logger.debug("Thread started.") while not self.__stopped: self.__wait() if not self.__stopped: try: self.doCall() except Exception, e: logger.critical("Unhandled exception", exc_info=e)
def set_thinking(self, thinking): self.thinking = thinking logger.debug("set thinking %s", self.thinking) if len(self.engine_side) == 2 and not self.engine.checkmate: QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.BusyCursor) elif self.thinking: QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.BusyCursor) else: QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.ArrowCursor) self.update_action_state()
def go(self): if self.engine.checkmate: self.game_signal.checkmate.emit() logger.debug('engine is checkmated hint ignored...') return self.game_signal.thinking.emit(True) engine = self.current_engine() engine.position(self.engine.sit.format_fen()) params = self.settings.get_params(self.engine.sit.turn) engine.go(**params)
def redo(self): for _ in range(2): self.engine.redo() logger.debug('engine redo result %d', self.engine.sit.result) self.game_signal.move.emit(self.engine.sit.result) if self.engine.checkmate: self.game_signal.checkmate.emit() if self.engine.sit.turn in self.human_side: break self.updateBoard()
def finish_arrange(self, finished): if not finished: return logger.debug('finish arrange') self.engine.close() self.engine = Engine() self.engine.sit.board = self.board.board self.engine.sit.turn = self.board.first_side self.engine.sit.fen = self.engine.sit.format_current_fen() self.try_engine_move() self.game_menu.setAllShortcutEnabled(True)
def doCall(self): endDateTime = self.__nextBarClose self.__updateNextBarClose() barDict = {} for indentifier in self.__identifiers: try: logger.debug("Requesting bars with precision %s and period %s for %s" % (self.__precision, self.__period, indentifier)) response = api.XigniteGlobalRealTime_GetBar(self.__apiToken, indentifier, "Symbol", endDateTime, self.__precision, self.__period) # logger.debug(response) barDict[indentifier] = build_bar(response["Bar"], indentifier, self.__frequency) except api.XigniteError, e: logger.error(e)
class PollingThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.__stopped = False def __wait(self): # Wait until getNextCallDateTime checking for cancelation every 0.5 second. nextCall = self.getNextCallDateTime() while not self.__stopped and utcnow() < nextCall: time.sleep(0.5) def stop(self): self.__stopped = True def stopped(self): return self.__stopped def run(self): logger.debug("Thread started.") while not self.__stopped: self.__wait() if not self.__stopped: try: self.doCall() except Exception, e: logger.critical("Unhandled exception", exc_info=e) logger.debug("Thread finished.")
def engine_callback(self, type, data): if type == Chess.MOVE: time.sleep(self.settings.delay.value() / 1000) self.move(data[0], data[1]) elif type == Chess.INFO: logger.debug(data) elif type == Chess.POPHASH: logger.debug(data) elif type == Chess.DRAW: self.game_signal.draw.emit() elif type == Chess.RESIGN: self.game_signal.resign.emit() elif type == Chess.CHECKMATE: pass # self.game_signal.checkmate.emit() elif type == Chess.NOBESTMOVE: self.game_signal.nobestmove.emit()
def doCall(self): endDateTime = self.__nextBarClose self.__updateNextBarClose() barDict = {} for indentifier in self.__identifiers: try: logger.debug( "Requesting bars with precision %s and period %s for %s" % (self.__precision, self.__period, indentifier)) response = api.XigniteGlobalRealTime_GetBar( self.__apiToken, indentifier, "Symbol", endDateTime, self.__precision, self.__period) # logger.debug(response) barDict[indentifier] = build_bar(response["Bar"], indentifier, self.__frequency) except api.XigniteError, e: logger.error(e)
def move(self, fpos, tpos): self.game_signal.thinking.emit(False) if self.engine.checkmate: self.game_signal.checkmate.emit() return result = self.engine.move(fpos, tpos) logger.debug('move result %s', result) if not result: return if result != Chess.INVALID: self.game_signal.animate.emit(fpos, tpos) if self.engine.sit.check: self.board.setCheck(self.engine.sit.check) logger.debug('check ... %s', self.engine.sit.check) else: self.board.setCheck(None) self.game_signal.move.emit(result) if result == Chess.CHECKMATE: logger.debug("emit checkmate") self.game_signal.checkmate.emit() return self.try_engine_move()
def paste(self): content = QtWidgets.QApplication.clipboard().text() logger.debug('Clipboard text %s', content) self.pasre_content(content)
def stop(self): self.__stopped = True def stopped(self): return self.__stopped def run(self): logger.debug("Thread started.") while not self.__stopped: self.__wait() if not self.__stopped: try: self.doCall() except Exception, e: logger.critical("Unhandled exception", exc_info=e) logger.debug("Thread finished.") # Must return a non-naive datetime. def getNextCallDateTime(self): raise NotImplementedError() def doCall(self): raise NotImplementedError() class TushareBarFeedThread(TuSharePollingThread): # Events ON_BARS = 1 def __init__(self, queue, identifiers, frequency): super(TushareBarFeedThread, self).__init__(identifiers)
def stop(self): self.__stopped = True def stopped(self): return self.__stopped def run(self): logger.debug("Thread started.") while not self.__stopped: self.__wait() if not self.__stopped: try: self.doCall() except Exception, e: logger.critical("Unhandled exception", exc_info=e) logger.debug("Thread finished.") # Must return a non-naive datetime. def getNextCallDateTime(self): raise NotImplementedError() def doCall(self): raise NotImplementedError() class TushareBarFeedThread(TuSharePollingThread): # Events ON_BARS = 1 def __init__(self, queue, identifiers, frequency): super(TushareBarFeedThread, self).__init__(identifiers)
def handleResponse(self, msg): ret = msg.get("event") == "pusher:pong" if ret: logger.debug("Received pusher:pong.") return ret
def sendKeepAlive(self): logger.debug("Sending pusher:ping.") self.getWSClient().sendPing()
def handleResponse(self, msg): ret = msg.get("event") == "pusher:pong" if ret: logger.debug("Received pusher:pong.") return ret
def sendKeepAlive(self): logger.debug("Sending pusher:ping.") self.getWSClient().sendPing()
def debug(self): logger.debug("debug slot.....")
def hint(self): if self.thinking: logger.debug('engine is thinking hint ignored...') return self.go()