Example #1
0
def createRematch(gamemodel):
    """ If gamemodel contains only LOCAL or ARTIFICIAL players, this starts a
        new game, based on the info in gamemodel """

    if gamemodel.timed:
        secs = gamemodel.timemodel.intervals[0][WHITE]
        gain = gamemodel.timemodel.gain
    else:
        secs = 0
        gain = 0
    newgamemodel = GameModel(TimeModel(secs, gain), variant=gamemodel.variant)

    wp = gamemodel.players[WHITE]
    bp = gamemodel.players[BLACK]

    if wp.__type__ == LOCAL:
        player1tup = (wp.__type__, wp.__class__, (BLACK, repr(wp)), repr(wp))
        if bp.__type__ == LOCAL:
            player0tup = (bp.__type__, bp.__class__, (WHITE, repr(wp)),
                          repr(bp))
        else:
            engine = discoverer.getEngineByMd5(bp.md5)
            player0tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                          (engine, WHITE, bp.strength, gamemodel.variant, secs,
                           gain), repr(bp))
    else:
        player0tup = (bp.__type__, bp.__class__, (WHITE, repr(bp)), repr(bp))
        engine = discoverer.getEngineByMd5(wp.md5)
        player1tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                      (engine, BLACK, wp.strength, gamemodel.variant, secs,
                       gain), repr(wp))

    ionest.generalStart(newgamemodel, player0tup, player1tup)
Example #2
0
def createRematch (gamemodel):
    """ If gamemodel contains only LOCAL or ARTIFICIAL players, this starts a
        new game, based on the info in gamemodel """

    if gamemodel.timed:
        secs = gamemodel.timemodel.intervals[0][WHITE]
        gain = gamemodel.timemodel.gain
    else:
        secs = 0
        gain = 0
    newgamemodel = GameModel(TimeModel(secs, gain), variant=gamemodel.variant)

    wp = gamemodel.players[WHITE]
    bp = gamemodel.players[BLACK]

    if wp.__type__ == LOCAL:
        player1tup = (wp.__type__, wp.__class__, (BLACK, repr(wp)), repr(wp))
        if bp.__type__ == LOCAL:
            player0tup = (bp.__type__, bp.__class__, (WHITE, repr(wp)), repr(bp))
        else:
            engine = discoverer.getEngineByMd5(bp.md5)
            player0tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                          (engine, WHITE, bp.strength, gamemodel.variant,
                           secs, gain), repr(bp))
    else:
        player0tup = (bp.__type__, bp.__class__, (WHITE, repr(bp)), repr(bp))
        engine = discoverer.getEngineByMd5(wp.md5)
        player1tup = (ARTIFICIAL, discoverer.initPlayerEngine,
                      (engine, BLACK, wp.strength, gamemodel.variant,
                       secs, gain), repr(wp))

    ionest.generalStart(newgamemodel, player0tup, player1tup)
Example #3
0
def anal_combo_set_value(combobox, value, show_arrow_check, ana_check,
                         analyzer_type):
    engine = discoverer.getEngineByMd5(value)
    if engine is None:
        combobox.set_active(0)
        # This return saves us from the None-engine being used
        # in later code  -Jonas Thiem
        return
    else:
        try:
            index = list(discoverer.getAnalyzers()).index(engine)
        except ValueError:
            index = 0
        combobox.set_active(index)

    from pychess.widgets.gamewidget import widgets
    perspective = perspective_manager.get_perspective("games")
    for gmwidg in perspective.gamewidgets:
        spectators = gmwidg.gamemodel.spectators
        md5 = engine.get('md5')

        if analyzer_type in spectators and \
                spectators[analyzer_type].md5 != md5:
            gmwidg.gamemodel.remove_analyzer(analyzer_type)
            asyncio. async (gmwidg.gamemodel.start_analyzer(analyzer_type))
            if not widgets[show_arrow_check].get_active():
                gmwidg.gamemodel.pause_analyzer(analyzer_type)
Example #4
0
def anal_combo_set_value(combobox, value, show_arrow_check, ana_check,
                         analyzer_type):
    engine = discoverer.getEngineByMd5(value)
    if engine is None:
        combobox.set_active(0)
        # This return saves us from the None-engine being used
        # in later code  -Jonas Thiem
        return
    else:
        try:
            index = list(discoverer.getAnalyzers()).index(engine)
        except ValueError:
            index = 0
        combobox.set_active(index)

    from pychess.widgets.gamewidget import widgets
    perspective = perspective_manager.get_perspective("games")
    for gmwidg in perspective.gamewidgets:
        spectators = gmwidg.gamemodel.spectators
        md5 = engine.get('md5')

        if analyzer_type in spectators and \
                spectators[analyzer_type].md5 != md5:
            gmwidg.gamemodel.remove_analyzer(analyzer_type)
            asyncio.async(gmwidg.gamemodel.start_analyzer(analyzer_type))
            if not widgets[show_arrow_check].get_active():
                gmwidg.gamemodel.pause_analyzer(analyzer_type)
Example #5
0
 def set_value (combobox, value, show_arrow_check, ana_check, analyzer_type):
     engine = discoverer.getEngineByMd5(value)
     if engine is None:
         combobox.set_active(0)
         # This return saves us from the None-engine being used
         # in later code  -Jonas Thiem
         return
     else:
         try:
             index = list(discoverer.getAnalyzers()).index(engine)
         except ValueError:
             index = 0
         combobox.set_active(index)
     
     replace_analyzers = False
     if widgets[show_arrow_check].get_active() is True and \
             widgets[ana_check].get_active() is True:
         replace_analyzers = True
     
     from pychess.Main import gameDic
     for gmwidg in gameDic.keys():
         spectators = gmwidg.gamemodel.spectators
         md5 = engine.get('md5')
         
         if analyzer_type in spectators and \
                 spectators[analyzer_type].md5 != md5:
             gmwidg.gamemodel.remove_analyzer(analyzer_type)
             if replace_analyzers:
                 gmwidg.gamemodel.start_analyzer(analyzer_type)
 def set_value (combobox, value):
     engine = discoverer.getEngineByMd5(value)
     if not engine:
         combobox.set_active(0)
     else:
         try:
             index = list(discoverer.getAnalyzers()).index(engine)
         except ValueError:
             index = 0
         combobox.set_active(index)
 def set_value(combobox, value):
     engine = discoverer.getEngineByMd5(value)
     if not engine:
         combobox.set_active(0)
     else:
         try:
             index = list(discoverer.getAnalyzers()).index(engine)
         except ValueError:
             index = 0
         combobox.set_active(index)
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)
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)