def __sendAnalyze(self, inverse=False): if inverse and self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [([toAN(self.board, getMoveKillingKing(self.board)) ], MATE_VALUE - 1, "")]) return def stop_analyze(): if self.engineIsAnalyzing: print("exit", file=self.engine) # Some engines (crafty, gnuchess) doesn't respond to exit command # we try to force them to stop with an empty board fen print("setboard 8/8/8/8/8/8/8/8 w - - 0 1", file=self.engine) self.engineIsAnalyzing = False print("post", file=self.engine) print("analyze", file=self.engine) self.engineIsAnalyzing = True if self.analysis_timer is not None: self.analysis_timer.cancel() self.analysis_timer.join() self.analysis_timer = Timer(conf.get("max_analysis_spin", 3), stop_analyze) self.analysis_timer.start()
def putMove (self, board1, move, board2): """ Sends the engine the last move made (for spectator engines). @param board1: The current board @param move: The last move made @param board2: The board before the last move was made """ self.board = board1 if not board2: self.__tellEngineToPlayCurrentColorAndMakeMove() self.movenext = False return if self.mode == INVERSE_ANALYZING: self.board = self.board.switchColor() self.__printColor() if self.engineIsInNotPlaying: print >> self.engine, "force" self.__usermove(board2, move) if self.mode == INVERSE_ANALYZING: if self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [getMoveKillingKing(self.board)], MATE_VALUE-1) return self.__printColor() if self.engineIsInNotPlaying: print >> self.engine, "force"
def __sendAnalyze (self, inverse=False): if inverse and self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [([toAN(self.board, getMoveKillingKing(self.board))], MATE_VALUE-1, "")]) return def stop_analyze (): if self.engineIsAnalyzing: print("exit", file=self.engine) # Some engines (crafty, gnuchess) doesn't respond to exit command # we try to force them to stop with an empty board fen print("setboard 8/8/8/8/8/8/8/8 w - - 0 1", file=self.engine) self.engineIsAnalyzing = False print("post", file=self.engine) print("analyze", file=self.engine) self.engineIsAnalyzing = True if self.analysis_timer is not None: self.analysis_timer.cancel() self.analysis_timer.join() self.analysis_timer = Timer(conf.get("max_analysis_spin", 3), stop_analyze) self.analysis_timer.start()
def __sendAnalyze(self, inverse=False): if inverse and self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit( "analyze", [ ( self.board.ply, [toAN(self.board, getMoveKillingKing(self.board))], MATE_VALUE - 1, "1", "", ) ], ) return print("post", file=self.engine) print("analyze", file=self.engine) self.engineIsAnalyzing = True if not conf.get("infinite_analysis"): loop = asyncio.get_event_loop() loop.call_later(conf.get("max_analysis_spin"), self.__stop_analyze)
def _searchNow(self, ponderhit=False): log.debug("_searchNow: self.needBestmove=%s ponderhit=%s self.board=%s" % ( self.needBestmove, ponderhit, self.board), extra={"task": self.defname}) commands = [] if ponderhit: commands.append("ponderhit") elif self.mode == NORMAL: commands.append("position %s" % self.uciPosition) if self.strength <= 3: commands.append("go depth %d" % self.strength) else: if self.moves > 0: commands.append("go wtime %d winc %d btime %d binc %d movestogo %s" % ( self.wtime, self.incr, self.btime, self.incr, self.moves)) else: commands.append("go wtime %d winc %d btime %d binc %d" % ( self.wtime, self.incr, self.btime, self.incr)) else: print("stop", file=self.engine) if self.mode == INVERSE_ANALYZING: if self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [([toAN( self.board, getMoveKillingKing(self.board))], MATE_VALUE - 1, "")]) return commands.append("position fen %s" % self.board.asFen()) else: commands.append("position %s" % self.uciPosition) # commands.append("go infinite") move_time = int(conf.get("max_analysis_spin", 3)) * 1000 commands.append("go movetime %s" % move_time) if self.hasOption("MultiPV") and self.multipvSetting > 1: self.multipvExpected = min(self.multipvSetting, legalMoveCount(self.board)) else: self.multipvExpected = 1 self.analysis = [None] * self.multipvExpected if self.needBestmove: self.commands.append(commands) log.debug("_searchNow: self.needBestmove==True, appended to self.commands=%s" % self.commands, extra={"task": self.defname}) else: for command in commands: print(command, file=self.engine) if getStatus(self.board)[ 1] != WON_MATE: # XXX This looks fishy. self.needBestmove = True self.readyForStop = True
def __sendAnalyze(self, inverse=False): if inverse and self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [(self.board.ply, [toAN( self.board, getMoveKillingKing(self.board))], MATE_VALUE - 1, "", "")]) return print("post", file=self.engine) print("analyze", file=self.engine) self.engineIsAnalyzing = True if not conf.get("infinite_analysis", False): loop = asyncio.get_event_loop() loop.call_later(conf.get("max_analysis_spin", 3), self.__stop_analyze)
def _searchNow(self, ponderhit=False): log.debug("_searchNow: self.needBestmove=%s ponderhit=%s self.board=%s\n" % \ (self.needBestmove, ponderhit, self.board), self.defname) with self.moveLock: commands = [] if ponderhit: commands.append("ponderhit") elif self.mode == NORMAL: commands.append("position fen %s" % self.board.asFen()) if self.strength <= 3: commands.append("go depth %d" % self.strength) else: commands.append("go wtime %d btime %d winc %d binc %d" % \ (self.wtime, self.btime, self.incr, self.incr)) else: if self.mode == INVERSE_ANALYZING: if self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [getMoveKillingKing(self.board)], MATE_VALUE - 1) return print >> self.engine, "stop" if self.board.asFen() == FEN_START: commands.append("position startpos") else: commands.append("position fen %s" % self.board.asXFen()) commands.append("go infinite") if self.needBestmove: self.commands.append(commands) log.debug("_searchNow: self.needBestmove==True, appended to self.commands=%s\n" % \ self.commands, self.defname) else: for command in commands: print >> self.engine, command if self.board.asFen() != FEN_START and getStatus( self.board)[1] != WON_MATE: self.needBestmove = True self.readyForStop = True
def _searchNow (self, ponderhit=False): log.debug("_searchNow: self.needBestmove=%s ponderhit=%s self.board=%s\n" % \ (self.needBestmove, ponderhit, self.board), self.defname) with self.moveLock: commands = [] if ponderhit: commands.append("ponderhit") elif self.mode == NORMAL: commands.append("position fen %s" % self.board.asFen()) if self.strength <= 3: commands.append("go depth %d" % self.strength) else: commands.append("go wtime %d btime %d winc %d binc %d" % \ (self.wtime, self.btime, self.incr, self.incr)) else: if self.mode == INVERSE_ANALYZING: if self.board.board.opIsChecked(): # Many engines don't like positions able to take down enemy # king. Therefore we just return the "kill king" move # automaticaly self.emit("analyze", [getMoveKillingKing(self.board)], MATE_VALUE-1) return print >> self.engine, "stop" if self.board.asFen() == FEN_START: commands.append("position startpos") else: commands.append("position fen %s" % self.board.asXFen()) commands.append("go infinite") if self.needBestmove: self.commands.append(commands) log.debug("_searchNow: self.needBestmove==True, appended to self.commands=%s\n" % \ self.commands, self.defname) else: for command in commands: print >> self.engine, command if self.board.asFen() != FEN_START and getStatus(self.board)[1] != WON_MATE: self.needBestmove = True self.readyForStop = True