Пример #1
0
    def run (cls, uri=None):
        cls._ensureReady()
        if cls.widgets["newgamedialog"].props.visible:
            cls.widgets["newgamedialog"].present()
            return

        if not uri:
            res = ionest.opendialog.run()
            ionest.opendialog.hide()
            if res != gtk.RESPONSE_ACCEPT:
                return
        else:
            if not uri[uri.rfind(".")+1:] in ionest.enddir:
                log.log("Ignoring strange file: %s" % uri)
                return
            cls.loadSidePanel.set_filename(uri)
            cls.filechooserbutton.emit("file-activated")

        cls._hideOthers()
        cls.widgets["newgamedialog"].set_title(_("Open Game"))
        cls.widgets["loadsidepanel"].show()

        def _callback (gamemodel, p0, p1):
            if not cls.loadSidePanel.is_empty():
                uri =  cls.loadSidePanel.get_filename()
                loader = ionest.enddir[uri[uri.rfind(".")+1:]]
                position = cls.loadSidePanel.get_position()
                gameno = cls.loadSidePanel.get_gameno()
                ionest.generalStart(gamemodel, p0, p1, (uri, loader, gameno, position))
            else:
                ionest.generalStart(gamemodel, p0, p1)
        cls._generalRun(_callback)
Пример #2
0
 def zero_reached(self, timemodel, color):
     if conf.get('autoCallFlag', False) and \
             self.gamemodel.status == RUNNING and \
             timemodel.getPlayerTime(1-self.color) <= 0:
         log.log('Automatically sending flag call on behalf of player %s.' %
                 self.name)
         self.emit("offer", Offer(FLAG_CALL))
Пример #3
0
    def write(self, str):
        self.writebuf += str
        if "\n" not in self.writebuf:
            return

        i = self.writebuf.rfind("\n")
        str = self.writebuf[:i + 1]
        self.writebuf = self.writebuf[i + 1:]

        log.log(str, (repr(self), "raw"))
        str = self.encode(str[:-1]) + "\n"
        self.sock.send(str)
Пример #4
0
    def write(self, str):
        self.writebuf += str
        if "\n" not in self.writebuf:
            return

        if self.closed:
            return

        i = self.writebuf.rfind("\n")
        str = self.writebuf[:i]
        self.writebuf = self.writebuf[i + 1 :]

        log.log(str + "\n", (repr(self), "raw"))
        str = self.encode(str)
        self.sock.send(str + "\n")
Пример #5
0
    def write(self, str):
        self.writebuf += str
        if "\n" not in self.writebuf:
            return

        if self.closed:
            return

        i = self.writebuf.rfind("\n")
        str = self.writebuf[:i]
        self.writebuf = self.writebuf[i + 1:]

        log.log(str + "\n", (repr(self), "raw"))
        str = self.encode(str)
        self.sock.send(str + "\n")
Пример #6
0
class EngineDiscoverer(GObject, PooledThread):

    __gsignals__ = {
        "discovering_started": (SIGNAL_RUN_FIRST, TYPE_NONE, (object, )),
        "engine_discovered": (SIGNAL_RUN_FIRST, TYPE_NONE, (str, object)),
        "engine_failed": (SIGNAL_RUN_FIRST, TYPE_NONE, (str, object)),
        "all_engines_discovered": (SIGNAL_RUN_FIRST, TYPE_NONE, ()),
    }

    def __init__(self):
        GObject.__init__(self)

        self.backup = ET.ElementTree(fromstring(backup))
        self.xmlpath = addUserConfigPrefix("engines.xml")
        try:
            self.dom = ET.ElementTree(file=self.xmlpath)
            c = compareVersions(self.dom.getroot().get('version', default='0'),
                                ENGINES_XML_API_VERSION)
            if c == -1:
                log.warn(
                    "engineNest: engines.xml is outdated. It will be replaced\n"
                )
                self.dom = deepcopy(self.backup)
            elif c == 1:
                raise NotImplementedError, "engines.xml is of a newer date. In order" + \
                                "to run this version of PyChess it must first be removed"
        except ParseError, e:
            log.warn("engineNest: %s\n" % e)
            self.dom = deepcopy(self.backup)
        except IOError, e:
            log.log(
                "engineNest: Couldn\'t open engines.xml. Creating a new.\n%s\n"
                % e)
            self.dom = deepcopy(self.backup)
Пример #7
0
 def end (self, status, reason):
     if self.status not in UNFINISHED_STATES:
         log.log("GameModel.end: Can't end a game that's already ended: %s %s\n" % (status, reason))
         return
     if self.status not in (WAITING_TO_START, PAUSED, RUNNING):
         self.needsSave = True
     
     #log.debug("Ending a game with status %d for reason %d\n%s" % (status, reason,
     #    "".join(traceback.format_list(traceback.extract_stack())).strip()))
     log.debug("GameModel.end: players=%s, self.ply=%s: Ending a game with status %d for reason %d\n" % \
         (repr(self.players), str(self.ply), status, reason))
     self.status = status
     self.reason = reason
     
     self.emit("game_ended", reason)
     
     self.__pause()
Пример #8
0
    def end(self, status, reason):
        if self.status not in UNFINISHED_STATES:
            log.log(
                "GameModel.end: Can't end a game that's already ended: %s %s\n"
                % (status, reason))
            return
        if self.status not in (WAITING_TO_START, PAUSED, RUNNING):
            self.needsSave = True

        #log.debug("Ending a game with status %d for reason %d\n%s" % (status, reason,
        #    "".join(traceback.format_list(traceback.extract_stack())).strip()))
        log.debug("GameModel.end: players=%s, self.ply=%s: Ending a game with status %d for reason %d\n" % \
            (repr(self.players), str(self.ply), status, reason))
        self.status = status
        self.reason = reason

        self.emit("game_ended", reason)

        self.__pause()
Пример #9
0
 def zero_reached (self, timemodel, color):
     if conf.get('autoCallFlag', False) and \
             self.gamemodel.status == RUNNING and \
             timemodel.getPlayerTime(1-self.color) <= 0:
         log.log('Automatically sending flag call on behalf of player %s.' % self.name)
         self.emit("offer", Offer(FLAG_CALL)) 
Пример #10
0
def initchess():
    p = pychess.Main.PyChess(None)
    log.log("Started from Naali\n")
Пример #11
0
def initchess():
    p = pychess.Main.PyChess(None)
    log.log("Started from Naali\n")
Пример #12
0
    def __parseLine (self, line):
#        log.debug("__parseLine: line=\"%s\"\n" % line.strip(), self.defname)
        parts = whitespaces.split(line.strip())
        
        if parts[0] == "pong":
            self.lastpong = int(parts[1])
            return
        
        # Illegal Move
        if parts[0].lower().find("illegal") >= 0:
            log.warn("__parseLine: illegal move: line=\"%s\", board=%s" \
                % (line.strip(), self.board), self.defname)
            if parts[-2] == "sd" and parts[-1].isdigit():
                print >> self.engine, "depth", parts[-1] 
            return
        
        # A Move (Perhaps)
        if self.board:
            if parts[0] == "move":
                movestr = parts[1]
            # Old Variation
            elif d_plus_dot_expr.match(parts[0]) and parts[1] == "...":
                movestr = parts[2]
            else:
                movestr = False
            
            if movestr:
                log.debug("__parseLine: acquiring self.boardLock\n", self.defname)
                self.waitingForMove = False
                self.readyForMoveNowCommand = False
                self.boardLock.acquire()
                try:
                    if self.engineIsInNotPlaying:
                        # If engine was set in pause just before the engine sent its
                        # move, we ignore it. However the engine has to know that we
                        # ignored it, and thus we step it one back
                        log.log("__parseLine: Discarding engine's move: %s\n" % movestr, self.defname)
                        print >> self.engine, "undo"
                        return
                    else:
                        try:
                            move = parseAny(self.board, movestr)
                        except ParsingError, e:
                            raise PlayerIsDead, e
                        
                        if validate(self.board, move):
                            self.board = None
                            self.returnQueue.put(move)
                            return
                        raise PlayerIsDead, "Board didn't validate after move"
                finally:
                    log.debug("__parseLine(): releasing self.boardLock\n", self.defname)
                    self.boardLock.release()
                    self.movecon.acquire()
                    self.movecon.notifyAll()
                    self.movecon.release()
        
        # Analyzing
        if self.engineIsInNotPlaying:
            if parts[:4] == ["0","0","0","0"]:
                # Crafty doesn't analyze until it is out of book
                print >> self.engine, "book off"
                return
            
            match = anare.match(line)
            if match:
                score, moves = match.groups()
                
                if "mat" in score.lower():
                    # Will look either like -Mat 3 or Mat3
                    scoreval = MATE_VALUE - int("".join(c for c in score if c.isdigit()))
                    if score.startswith('-'): scoreval = -scoreval
                else:
                    scoreval = int(score)
                
                mvstrs = movere.findall(moves)
                try:
                    moves = listToMoves (self.board, mvstrs, type=None, validate=True, ignoreErrors=False)
                except ParsingError, e:
                    # ParsingErrors may happen when parsing "old" lines from
                    # analyzing engines, which haven't yet noticed their new tasks
                    log.debug("Ignored a line from analyzer: ParsingError%s\n" % e, self.defname)
                    return
                
                # Don't emit if we weren't able to parse moves, or if we have a move
                # to kill the opponent king - as it confuses many engines
                if moves and not self.board.board.opIsChecked():
                    self.emit("analyze", moves, scoreval)
                
                return
Пример #13
0
 def extendlog(self, messages):
     [log.log(m+"\n") for m in messages]
     self.log.extend(messages)
     del self.log[:-10]