def generate_third_card(c1, c2): """ function to generate the third card which forms a SET with the given two cards :rtype: object :param c1: card object1 :param c2: card object2 :return: card object3 """ color_set, symbol_set, shading_set, frequency_set = generate_sets() c3 = Card() if c1.color == c2.color: c3.color = c1.color else: c3.color = str((color_set - {c1.color, c2.color}).pop()) if c1.symbol == c2.symbol: c3.symbol = c1.symbol else: c3.symbol = str((symbol_set - {c1.symbol, c2.symbol}).pop()) if c1.shading == c2.shading: c3.shading = c1.shading else: c3.shading = str((shading_set - {c1.shading, c2.shading}).pop()) if c1.no_of_symbols == c2.no_of_symbols: c3.no_of_symbols = c1.no_of_symbols else: c3.no_of_symbols = int( (frequency_set - {c1.no_of_symbols, c2.no_of_symbols}).pop()) return c3
def read_hole_cards_line(self, hole_cards_line, active_player): """Read the two hole cards given to the active player in the hole card line. Analyses a single line (string). Args: hole_cards_line (str) : The hole card line, containing the name of the active player. active_player (Player) : The name of the active player. Returns: (list): A list of two Card, containing the two hole cards read. """ # TODO: Does not read the 1st hand of a file if not active_player.name in hole_cards_line: raise Exception("The active player hole cards are missing.") in_cards = False card1 = Card(0, "") card2 = Card(0, "") for i in range(len(hole_cards_line)): if in_cards == True: card1.set_value(hole_cards_line[i]) card1.color = hole_cards_line[i + 1] card2.set_value(hole_cards_line[i + 3]) card2.color = hole_cards_line[i + 4] break if hole_cards_line[i] == "[": in_cards = True return [card1, card2]
def __parse_card_item(self, text): card = Card() card.multiverseid = int(multiverseid_re.search(text).group(1)) card.set_code = self.set_code card.number = int(number_re.search(text).group(1)) card.name = name_re.search(text).group(1) card.artist = artist_re.search(text).group(1) card.color = color_re.search(text).group(1) card.rarity = rarity_re.search(text).group(1) return card
def compute_third(self, card1, card2): card3 = Card("default", "default", "default", "default") if card1.color == card2.color: card3.color = card1.color else: card3.color = Features.computeColor(card1.color, card2.color) if card1.shape == card2.shape: card3.shape = card1.shape else: card3.shape = Features.computeShape(card1.shape, card2.shape) if card1.number == card2.number: card3.number = card1.number else: card3.number = Features.computeNumber(card1.number, card2.number) if card1.texture == card2.texture: card3.texture = card1.texture else: card3.texture = Features.computeTexture(card1.texture, card2.texture) return card3
def parse_card(set_of_cards): """ function to create a list of card objects :rtype: list :param set_of_cards: list of cards :return: list of card objects """ card_objects = [] for x in set_of_cards: c = Card() l = x.split() c.color = l[0] c.no_of_symbols = len(l[1]) s = l[1] s = str(s[0]) if s.istitle(): c.shading = 'upper' if s is 'A': c.symbol = 'A' elif s is 'H': c.symbol = 'H' elif s is 'S': c.symbol = 'S' elif s.islower(): c.shading = 'lower' if s is 'a': c.symbol = 'A' elif s is 'h': c.symbol = 'H' elif s is 's': c.symbol = 'S' else: c.shading = 'symbol' if s is '@': c.symbol = 'A' elif s is '#': c.symbol = 'H' elif s is '$': c.symbol = 'S' card_objects.append(c) return card_objects
temp_card.power = card.find('power').text or "Default" temp_card.toughness = card.find('toughness').text or "Default" temp_card.loyalty = card.find('loyalty').text or "Default" temp_card.ability = card.find('ability').text or "Default" #temp_card.flavor = card.find('flavor').text or "Default" if temp_card.id == 74256: temp_card.flavor = "Default" else: temp_card.flavor = card.find('flavor').text or "Default" temp_card.variation = card.find('variation').text or "Default" temp_card.artist = card.find('artist').text or "Default" temp_card.number = card.find('number').text or "Default" temp_card.rating = card.find('rating').text or "Default" temp_card.ruling = card.find('ruling').text or "Default" temp_card.color = card.find('color').text or "Default" temp_card.generated_mana = card.find('generated_mana').text or "Default" temp_card.pricing_low = card.find('pricing_low').text or "Default" temp_card.pricing_mid = card.find('pricing_mid').text or "Default" temp_card.pricing_high = card.find('pricing_high').text or "Default" temp_card.back_id = card.find('back_id').text or "Default" temp_card.watermark = card.find('watermark').text or "Default" temp_card.name_CN = card.find('name_CN').text or "Default" temp_card.name_TW = card.find('name_TW').text or "Default" temp_card.name_FR = card.find('name_FR').text or "Default" temp_card.name_DE = card.find('name_DE').text or "Default" temp_card.name_IT = card.find('name_IT').text or "Default" temp_card.name_JP = card.find('name_JP').text or "Default" temp_card.name_PT = card.find('name_PT').text or "Default" temp_card.name_RU = card.find('name_RU').text or "Default"