Пример #1
0
def Score6DevTable():
    ret = collections.defaultdict(lambda: collections.defaultdict(int))
    for six_dev in DeckInfo.SixDevList():
        score_func = GetScoreFunc(six_dev)
        for card in DeckInfo.CardList():
            ret[six_dev][card] = score_func(card)
    return ret
Пример #2
0
def ScoreGoldenAgeofTerraforming(card):
    if 'Terraforming' in card:
        return 2 + (DeckInfo.ProductionPower(card) == PRODUCTION)
    if DeckInfo.CardIsDev(card) and (DeckInfo.Cost(card) == 6):
        return 1
    if DeckInfo.ProductionPower(card) == PRODUCTION:
        return 1
    return 0
Пример #3
0
def ScorePanGalacticHologrid(card):
    if card == "Expanding Colony":
        return 2
    if DeckInfo.GoodType(card) == NOVELTY:
        return 2
    if DeckInfo.CardIsWorld(card):
        return 1
    return 0
Пример #4
0
 def __init__(self, card_list, vp=0, prestige=0):
     #self.bonus_points_per_card = collections.defaultdict(int)
     self.bonus_points_per_6_dev = collections.defaultdict(int)
     self.card_list = card_list
     self.vp = vp
     self.prestige = prestige
     self.total_points = self.vp
     for card in card_list:
         if DeckInfo.Is6Dev(card):
             bonus_for_6 = self.ScoreFor6Dev(card)
             self.bonus_points_per_6_dev[card] += bonus_for_6
             self.total_points += bonus_for_6
         self.total_points += DeckInfo.Value(card)
Пример #5
0
    def ScoreFor6Dev(self, card):
        score = 0
        gal_ex_types = 0
        mil_worlds_bonus = 0

        if card == 'Galactic Renaissance':
            score += self.vp / 3
        elif card == 'Pan-Galactic Affluence':
            score += self.prestige
        elif card == 'Galactic Exchange':
            good_types = set()
            for other_card in self.card_list:
                good_types.add(DeckInfo.GoodType(other_card))
            gal_ex_types = len(good_types - set([NO_GOOD]))
            #print 'num good types = ', gal_ex_types
        elif card == 'New Galactic Order':
            if 'Hidden Fortress' in self.card_list:
                for other_card in self.card_list:
                    mil_worlds_bonus += DeckInfo.IsMilWorld(other_card)
            if 'Rebel Freedom Fighters' in self.card_list:
                imp = False
                for card in self.card_list:
                    if 'Imperium' in card:
                        imp = True
                        break
                if imp:
                    score -= 2
        elif card == 'Universal Peace Institute':
            if 'Hidden Fortress' in self.card_list:
                for other_card in self.card_list:
                    mil_worlds_bonus -= DeckInfo.IsMilWorld(other_card)
            if 'Rebel Freedom Fighters' in self.card_list:
                imp = False
                for card in self.card_list:
                    if 'Imperium' in card:
                        imp = True
                        break
                if imp:
                    score += 2

        score += gal_ex_types * (gal_ex_types + 1) / 2
        score += mil_worlds_bonus
        table_for_this_dev = _six_dev_score_table[card]
        for other_card in self.card_list:
            score += table_for_this_dev[other_card]
            #if other_card != card:
            #    self.bonus_points_per_card[other_card] += bonus
        if not card in self.card_list:
            score += table_for_this_dev[card]
        return score
Пример #6
0
def ScoreAlienCornucopia(card):
    if 'Alien' in card:
        return 2
    if DeckInfo.ProductionPower(card) == PRODUCTION:
        return 1
    return 0
Пример #7
0
 def MaxCardVersion(player_dict):
     return max(DeckInfo.Version(card) for card in player_dict['cards'])
Пример #8
0
def ScoreImperiumLords(card):
    if 'Imperium' in card:
        return 2
    return DeckInfo.IsMilWorld(card)
Пример #9
0
def ScoreMerchantGuild(card):
    return (DeckInfo.ProductionPower(card) == PRODUCTION) * 2
Пример #10
0
def ScoreGalacticImperium(card):
    if DeckInfo.IsMilWorld(card):
        return 1 + ('Rebel' in card)
    return 0
Пример #11
0
def ScoreAlienTechInstitute(card):
    if 'Alien' in card:
        return 2 + (DeckInfo.ProductionPower(card) == PRODUCTION)
    return 0
Пример #12
0
def ScoreGalacticBankers(card):
    if card in ['Gambling World', 'Interstellar Bank', 'Investment Credits']:
        return 2
    return DeckInfo.CardIsDev(card)
Пример #13
0
def ScorePanGalacticLeague(card):
    if card == 'Contact Specialist':
        return 3
    if DeckInfo.GoodType(card) == GENES:
        return 2
    return DeckInfo.IsMilWorld(card)
Пример #14
0
def ScoreProspectingGuild(card):
    if DeckInfo.GoodType(card) == RARE:
        return 2
    if 'Terraforming' in DeckInfo.Keywords(card):
        return 1
    return DeckInfo.CardIsWorld(card)
Пример #15
0
def ScoreNewGalacticOrder(card):
    return DeckInfo.MilitaryStrength(card)
Пример #16
0
def ScoreNewEconomy(card):
    return DeckInfo.HasConsumePower(card) * (DeckInfo.CardIsDev(card) + 1)
Пример #17
0
def ScoreMiningLeague(card):
    if card in ['Mining Conglomerate', 'Mining Robots']:
        return 2
    return (DeckInfo.GoodType(card) == RARE) * (
        (DeckInfo.ProductionPower(card) == PRODUCTION) + 1)
Пример #18
0
 def PointsPerCard(self, card):
     ret = DeckInfo.Value(card)
     for other_card in self.card_list:
         if DeckInfo.Is6Dev(other_card) and other_card != card:
             ret += GetScoreFunc(other_card)(card)
     return ret + self.BonusPer6Dev(card)
Пример #19
0
def ScoreGalacticFederation(card):
    if DeckInfo.CardIsDev(card):
        return 1 + (DeckInfo.Cost(card) == 6)
    return 0
Пример #20
0
def ScoreRebelAlliance(card):
    keywords = DeckInfo.Keywords(card)
    if 'Rebel' in keywords:
        return 2
    return DeckInfo.IsMilWorld(card)
Пример #21
0
def ScoreImperiumSeat(card):
    keywords = DeckInfo.Keywords(card)
    if 'Imperium' in keywords:
        return 2
    return 2 * ('Rebel' in keywords and DeckInfo.IsMilWorld(card))
Пример #22
0
def ScoreFreeTradeAssociation(card):
    if card in ['Consumer Markets', 'Expanding Colony']:
        return 2
    if DeckInfo.GoodType(card) == NOVELTY:
        return 1 + (DeckInfo.ProductionPower(card) == PRODUCTION)
    return 0
Пример #23
0
def ScoreTerraformingGuild(card):
    if 'Terraforming' in card:
        return 2
    return 2 * (DeckInfo.ProductionPower(card) == WINDFALL)
Пример #24
0
def ScoreUniversalPeaceInstitute(card):
    ret = 0
    ret -= DeckInfo.MilitaryStrength(card)
    ret += DeckInfo.IsMilWorld(card)
    ret += 2 * (card == "Pan-Galactic Mediator")
    return ret
Пример #25
0
def ScoreTradeLeague(card):
    return DeckInfo.HasTradePower(card) * (DeckInfo.CardIsDev(card) + 1)
Пример #26
0
def ScoreGalacticGenomeProject(card):
    if card == 'Genetics Lab':
        return 3
    return 2 * (DeckInfo.GoodType(card) == GENES)
Пример #27
0
def ScoreUpliftCode(card):
    keywords = DeckInfo.Keywords(card)
    return ('UpliftX' in keywords) + 2 * ('Uplift' in keywords)
Пример #28
0
def ScoreGalacticSurveySETI(card):
    if DeckInfo.HasExplorePower(card):
        return 1 + DeckInfo.CardIsWorld(card)
    return DeckInfo.CardIsWorld(card)
Пример #29
0
def ParseGame(page_contents, card_id_to_name):
    page_contents = page_contents.replace('<br/>', '<br>')
    version_loc = page_contents.index(': Game #')
    version_with_context = page_contents[version_loc - 50:version_loc + 50]

    is_gs = 'Gathering Storm' in version_with_context
    version = int(is_gs)
    using_goals = False
    goals = set()
    if 'Available goals' in version_with_context:
        end_goal_loc = page_contents.find('Chosen Actions')
        snip_with_goals = page_contents[version_loc - 50:end_goal_loc]
        goals.update(ParseGoals(snip_with_goals))
        using_goals = True

    ret = {
        'player_list': [],
        'game_id': ('http://genie.game-host.org/game.htm?gid=' +
                    GAME_NUM_RE.search(version_with_context).group(1))
    }

    if 'Status:' not in page_contents:
        print 'could not find status'
        raise CompleteButRejectedGame()

    page_contents = page_contents[:page_contents.find('Comments'):]
    status_list = page_contents.split('Status:')[1:]

    for status in status_list:
        player_result = {}
        status_lines = status.split('<br>')
        if len(status_lines) < 3:
            print 'confused, could not under status lines', status_lines
        game_end_line = status_lines[0]
        if 'Game End' not in game_end_line:
            if 'Frozen' in game_end_line:
                raise CompleteButRejectedGame()
            print "Don't think game", ret['game_no'], "is over"
            return None

        name_points = status_lines[1]
        player_result['name'] = name_points[:name_points.find("'")]
        player_result['points'] = int(POINTS_RE.search(name_points).group(1))
        player_result['chips'] = int(CHIPS_RE.search(name_points).group(1))
        if player_result['points'] <= 5:
            raise CompleteButRejectedGame()

        card_goal_list_line = status_lines[2]
        card_goal_list_imgs = card_goal_list_line.split('src=')
        cards = []
        won_goals = []
        goods = 0
        for card_or_goal in card_goal_list_imgs:
            if 'border-width:5px' in card_or_goal:
                goods += 1
        for card_or_goal in card_goal_list_imgs[1:]:
            img = card_or_goal.replace('/', ' ').replace('.', ' ').split()[1]
            if img[0] == 'g':
                won_goals.append(GOAL_NUM_TO_NAME[int(img[1:])])
            else:
                card_data = card_id_to_name[img]
                card_name = card_data['name']
                cards.append(card_name)

                version = max(version, DeckInfo.Version(card_name))

        player_result['cards'] = cards
        if using_goals:
            goals.update(won_goals)
            player_result['goals'] = won_goals
        player_result['goods'] = goods
        ret['player_list'].append(player_result)

    if len(ret['player_list']) <= 1:
        print 'insufficient players'
        raise CompleteButRejectedGame()

    if using_goals:
        ret['goals'] = list(goals)

    hand_sizes = [int(x) for x in CARD_NUM_RE.findall(page_contents)]
    for player_result, hand_size in zip(ret['player_list'], hand_sizes):
        player_result['hand'] = hand_size

    ret['advanced'] = int('Action1:' in page_contents
                          and 'Action2:' in page_contents)
    version = max(version, int(len(goals) > 1))
    ret['expansion'] = version
    return ret