當前位置: 首頁>>代碼示例>>Python>>正文


Python Program.getDenyReason方法代碼示例

本文整理匯總了Python中program.Program.getDenyReason方法的典型用法代碼示例。如果您正苦於以下問題:Python Program.getDenyReason方法的具體用法?Python Program.getDenyReason怎麽用?Python Program.getDenyReason使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在program.Program的用法示例。


在下文中一共展示了Program.getDenyReason方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DfpnSolver

# 需要導入模塊: from program import Program [as 別名]
# 或者: from program.Program import getDenyReason [as 別名]
class DfpnSolver(Thread):
    class Error:
        pass

    def __init__(self, name, command, positions, verbose):
        Thread.__init__(self)
        self._name = name
        self._positions = positions
        self._verbose = verbose
        command = command + " --logfile-name=" + name + ".log"
        self._program = Program(command, verbose)

    def sendCommand(self, command):
        try:
            return self._program.sendCommand(command);
        except Program.CommandDenied:
            reason = self._program.getDenyReason()
            self._errorMessage = _name + ": "  + reason
            raise DfpnSolver.Error
        except Program.Died:
            self._errorMessage = _name + ": program died"
            raise DfpnSolver.Error

    def playVariation(self, variation):
        self.sendCommand("clear_board");
        moves = variation.split(' ');
        color = "B";
        for move in moves:
            cmd = "play " + color + " " + move.strip();
            self.sendCommand(cmd);
            if color == "B":
                color = "W";
            else:
                color = "B";
            
    def solvePosition(self, variation):
        if (self._verbose):
            print "#####################################"
            print self._name + ": " + variation
            print "#####################################"
        else:
            print self._name + ": " + variation
        self.playVariation(variation);
        return self.sendCommand("dfpn-solve-state");

    def addResult(self, variation, winner):
        if (winner == "empty"):
            f = open(self._name + ".unsolved", "a");
            print >> f, variation;
            f.close();
        else:
            f = open(self._name + ".solved", "a");
            print >> f, variation + " " + winner
            f.close();

    def run(self):
        while True:
            variation = self._positions.getPosition();
            if variation == "":
                return;
            else:
                winner = self.solvePosition(variation).strip();
                self.addResult(variation, winner);
                print self._name + ": " + winner
開發者ID:PawelTroka,項目名稱:LogicalGamesEnginesGenerator,代碼行數:66,代碼來源:book-solve.py


注:本文中的program.Program.getDenyReason方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。