示例#1
0
def start(discoverer):
    atexit.register(SubProcess.finishAllSubprocesses)
    pgnfile, gameno = queryGameno(sys.argv[1])
    analyzer = queryAnalyzer(discoverer.getAnalyzers())
    secs = queryTime()
    name1, name2 = pgnfile.get_player_names(gameno)
    print("%s will now analyze the game between %s and %s with %d seconds per move." % \
            (discoverer.getName(analyzer), name1, name2, secs))
    print()
    
    global game, values
    values = {}
    game = GameModel()
    game.setPlayers([DummyPlayer(), DummyPlayer()])
    analyzer = discoverer.initAnalyzerEngine(analyzer, ANALYZING, game.variant)
    analyzer.connect('analyze', onAnalyze)
    game.spectators[HINT] = analyzer
    game.loadAndStart(sys.argv[1], pgn, gameno, -1)
    
    def cb():
        if game.ply == game.lowply:
            on_finish()
            return False
        check_blund()
        return True
    glib.timeout_add_seconds(secs, cb)
示例#2
0
def start(discoverer):
    atexit.register(SubProcess.finishAllSubprocesses)
    pgnfile, gameno = queryGameno(sys.argv[1])
    analyzer = queryAnalyzer(discoverer.getAnalyzers())
    secs = queryTime()
    name1, name2 = pgnfile.get_player_names(gameno)
    print("%s will now analyze the game between %s and %s with %d seconds per move." % \
            (discoverer.getName(analyzer), name1, name2, secs))
    print()

    global game, values
    values = {}
    game = GameModel()
    game.setPlayers([DummyPlayer(), DummyPlayer()])
    analyzer = discoverer.initAnalyzerEngine(analyzer, ANALYZING, game.variant)
    analyzer.connect('analyze', onAnalyze)
    game.spectators[HINT] = analyzer
    game.loadAndStart(sys.argv[1], pgn, gameno, -1)

    def cb():
        if game.ply == game.lowply:
            on_finish()
            return False
        check_blund()
        return True

    GLib.timeout_add_seconds(secs, cb)
示例#3
0
def workfunc(worker, gamemodel, player0tup, player1tup, loaddata=None):
    log.debug("ionest.workfunc: %s\n %s\n %s\n" %
              (gamemodel, player0tup, player1tup))
    gmwidg = gamewidget.GameWidget(gamemodel)

    player0 = {}
    player1 = {}
    for player, playertup in ((player0, player0tup), (player1, player1tup)):
        player["name"] = playertup[3]
        player["rating"] = (len(playertup) > 4 and
                            playertup[4]) and "(" + playertup[4] + ")" or None
        player["tabtext"] = player["rating"] and player["name"] + " " + player["rating"] \
                or player["name"]
    text = [player0["tabtext"], _("vs"), player1["tabtext"]]
    gmwidg.setTabText(" ".join(text))

    # Initing analyze engines
    # We have to do this before publishing gmwidg to make sure that
    # gamemodel.*EngineSupportsVariant is set right before on_gmwidg_created() is called

    anaengines = list(discoverer.getAnalyzers())
    specs = {}
    engine = discoverer.getEngineByMd5(conf.get("ana_combobox", 0))
    if engine is None: engine = anaengines[0]
    if gamemodel.variant.board.variant in discoverer.getEngineVariants(engine) or \
       gamemodel.variant.standard_rules:
        if conf.get("analyzer_check", True):
            hintanalyzer = discoverer.initAnalyzerEngine(
                engine, ANALYZING, gamemodel.variant)
            specs[HINT] = hintanalyzer
            log.debug("Hint Analyzer: %s\n" % repr(hintanalyzer))
        gamemodel.hintEngineSupportsVariant = True
    else:
        gamemodel.hintEngineSupportsVariant = False
    engine = discoverer.getEngineByMd5(conf.get("inv_ana_combobox", 0))
    if engine is None: engine = anaengines[0]
    if gamemodel.variant.board.variant in discoverer.getEngineVariants(engine) or \
       gamemodel.variant.standard_rules:
        if conf.get("inv_analyzer_check", True):
            spyanalyzer = discoverer.initAnalyzerEngine(
                engine, INVERSE_ANALYZING, gamemodel.variant)
            specs[SPY] = spyanalyzer
            log.debug("Spy Analyzer: %s\n" % repr(spyanalyzer))
        gamemodel.spyEngineSupportsVariant = True
    else:
        gamemodel.spyEngineSupportsVariant = False

    worker.publish((gmwidg, gamemodel))

    # For updating names
    players = []

    def updateTitle(color=None):

        name0_name1 = gmwidg.getTabText().split(" %s " % _("vs"))
        if not name0_name1:
            name0, name1 = _("White"), _("Black")
        else:
            name0, name1 = name0_name1

        if color is None:
            name0 = repr(players[WHITE])
            name0 += player0["rating"] and " " + player0["rating"] or ""
            name1 = repr(players[BLACK])
            name1 += player1["rating"] and " " + player1["rating"] or ""
        elif color == WHITE:
            name0 = repr(players[WHITE])
            name0 += player0["rating"] and " " + player0["rating"] or ""
        elif color == BLACK:
            name1 = repr(players[BLACK])
            name1 += player1["rating"] and " " + player1["rating"] or ""

        gmwidg.setTabText("%s %s %s" % (name0, _("vs"), name1))

    # Initing players
    for i, playertup in enumerate((player0tup, player1tup)):
        type, func, args = (playertup[0:3])
        if type != LOCAL:
            players.append(func(*args))
            if type == ARTIFICIAL:

                def readyformoves(player, color):
                    updateTitle(color)

                players[i].connect("readyForMoves", readyformoves, i)
        else:
            # Until PyChess has a proper profiles system, as discussed on the
            # issue tracker, we need to give human players special treatment
            ichandle = None
            if len(args) > 2:
                ichandle = args[2]
                args = [v for v in args[0:2]]
            player = func(gmwidg, ichandle=ichandle, *args)
            players.append(player)
            if i == 0 or (i == 1 and player0tup[0] != LOCAL):
                key = "firstName"
                alt = conf.username
            else:
                key = "secondName"
                alt = _("Guest")
            player.setName(conf.get(key, alt))

            def callback(none, color, key, alt):
                players[color].setName(conf.get(key, alt))
                updateTitle(color)

            conf.notify_add(key, callback, i, key, alt)

    worker.publish(updateTitle)

    # Setting game
    gamemodel.setPlayers(players)
    gamemodel.setSpectactors(specs)

    # Starting
    if loaddata:
        try:
            uri, loader, gameno, position = loaddata
            gamemodel.loadAndStart(uri, loader, gameno, position)
        except LoadingError, e:
            d = gtk.MessageDialog(type=gtk.MESSAGE_WARNING,
                                  buttons=gtk.BUTTONS_OK)
            d.set_markup("<big><b>%s</b></big>" % e.args[0])
            d.format_secondary_text(e.args[1] + "\n\n" + _(
                "Correct the move, or start playing with what could be read"))
            d.connect("response", lambda d, a: d.hide())
            worker.publish(d.show)
示例#4
0
def workfunc (worker, gamemodel, player0tup, player1tup, loaddata=None):
    log.debug("ionest.workfunc: %s\n %s\n %s\n" % (gamemodel, player0tup, player1tup))
    gmwidg = gamewidget.GameWidget(gamemodel)

    player0 = {}
    player1 = {}
    for player, playertup in ((player0, player0tup), (player1, player1tup)):
        player["name"] = playertup[3]
        player["rating"] = (len(playertup) > 4 and playertup[4]) and "("+playertup[4]+")" or None
        player["tabtext"] = player["rating"] and player["name"] + " " + player["rating"] \
                or player["name"]
    text = [ player0["tabtext"], _("vs"), player1["tabtext"] ]
    gmwidg.setTabText(" ".join(text))

    # Initing analyze engines
    # We have to do this before publishing gmwidg to make sure that
    # gamemodel.*EngineSupportsVariant is set right before on_gmwidg_created() is called
    
    anaengines = list(discoverer.getAnalyzers())
    specs = {}
    engine = discoverer.getEngineByMd5(conf.get("ana_combobox", 0))
    if engine is None: engine = anaengines[0]
    if gamemodel.variant.board.variant in discoverer.getEngineVariants(engine) or \
       gamemodel.variant.standard_rules:
        if conf.get("analyzer_check", True):
            hintanalyzer = discoverer.initAnalyzerEngine(engine, ANALYZING,
                                                         gamemodel.variant)
            specs[HINT] = hintanalyzer
            log.debug("Hint Analyzer: %s\n" % repr(hintanalyzer))
        gamemodel.hintEngineSupportsVariant = True
    else:
        gamemodel.hintEngineSupportsVariant = False
    engine = discoverer.getEngineByMd5(conf.get("inv_ana_combobox", 0))
    if engine is None: engine = anaengines[0]
    if gamemodel.variant.board.variant in discoverer.getEngineVariants(engine) or \
       gamemodel.variant.standard_rules:
        if conf.get("inv_analyzer_check", True):
            spyanalyzer = discoverer.initAnalyzerEngine(engine, INVERSE_ANALYZING,
                                                        gamemodel.variant)
            specs[SPY] = spyanalyzer
            log.debug("Spy Analyzer: %s\n" % repr(spyanalyzer))
        gamemodel.spyEngineSupportsVariant = True            
    else:
        gamemodel.spyEngineSupportsVariant = False

    worker.publish((gmwidg,gamemodel))

    # For updating names
    players = []
    def updateTitle (color=None):

        name0_name1 = gmwidg.getTabText().split(" %s "%_("vs"))
        if not name0_name1:
            name0, name1 = _("White"), _("Black")
        else: name0, name1 = name0_name1

        if color is None:
            name0 = repr(players[WHITE])
            name0 += player0["rating"] and " "+player0["rating"] or ""
            name1 = repr(players[BLACK])
            name1 += player1["rating"] and " "+player1["rating"] or ""
        elif color == WHITE:
            name0 = repr(players[WHITE])
            name0 += player0["rating"] and " "+player0["rating"] or ""
        elif color == BLACK:
            name1 = repr(players[BLACK])
            name1 += player1["rating"] and " "+player1["rating"] or ""

        gmwidg.setTabText("%s %s %s" % (name0, _("vs"), name1))

    # Initing players
    for i, playertup in enumerate((player0tup, player1tup)):
        type, func, args = (playertup[0:3])
        if type != LOCAL:
            players.append(func(*args))
            if type == ARTIFICIAL:
                def readyformoves (player, color):
                    updateTitle(color)
                players[i].connect("readyForMoves", readyformoves, i)
        else:
            # Until PyChess has a proper profiles system, as discussed on the
            # issue tracker, we need to give human players special treatment
            ichandle = None
            if len(args) > 2:
                ichandle = args[2]
                args = [ v for v in args[0:2] ]
            player = func(gmwidg, ichandle=ichandle, *args)
            players.append(player)
            if i == 0 or (i == 1 and player0tup[0] != LOCAL):
                key = "firstName"
                alt = conf.username
            else:
                key = "secondName"
                alt = _("Guest")
            player.setName(conf.get(key, alt))

            def callback (none, color, key, alt):
                players[color].setName(conf.get(key, alt))
                updateTitle(color)
            conf.notify_add(key, callback, i, key, alt)

    worker.publish(updateTitle)

    # Setting game
    gamemodel.setPlayers(players)
    gamemodel.setSpectactors(specs)

    # Starting
    if loaddata:
        try:
            uri, loader, gameno, position = loaddata
            gamemodel.loadAndStart (uri, loader, gameno, position)
        except LoadingError, e:
            d = gtk.MessageDialog (type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK)
            d.set_markup ("<big><b>%s</b></big>" % e.args[0])
            d.format_secondary_text (e.args[1] + "\n\n" +
                    _("Correct the move, or start playing with what could be read"))
            d.connect("response", lambda d,a: d.hide())
            worker.publish(d.show)