From 4a3d9c423ef24a2e2920f09820a8b28cc5d65ee0 Mon Sep 17 00:00:00 2001 From: mwisnowski Date: Tue, 17 Dec 2024 12:02:53 -0800 Subject: [PATCH] Added logic for more themes Adjusted setup to exclude unsets and Heroes of the realm cards --- settings.py | 2 +- setup.py | 50 ++++-- tagger.py | 507 +++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 441 insertions(+), 118 deletions(-) diff --git a/settings.py b/settings.py index 58f0fec..c800835 100644 --- a/settings.py +++ b/settings.py @@ -29,7 +29,7 @@ colors = ['colorless', 'white', 'blue', 'black', 'red', 'green', 'bant', 'esper', 'grixis', 'jund', 'naya', 'abzan', 'jeskai', 'mardu', 'sultai', 'temur', 'dune', 'glint', 'ink', 'witch', 'yore', 'wubrg', - 'legendary'] + 'commander'] counter_types = ['+0/+1', '+0/+2', '+1/+0', '+1/+2', '+2/+0', '+2/+2', '-0/-1', '-0/-2', '-1/-0', '-1/-2', '-2/-0', '-2/-2', diff --git a/setup.py b/setup.py index 91730b5..bc3d3f1 100644 --- a/setup.py +++ b/setup.py @@ -45,10 +45,12 @@ def filter_by_color(df, column_name, value, new_csv_name): columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'text', 'power', 'toughness', 'keywords'] filtered_df = filtered_df[columns_to_keep] filtered_df.sort_values(by='name', key=lambda col: col.str.lower(), inplace=True) + + filtered_df.to_csv(new_csv_name, index=False) -def determine_legendary(): - print('Generating legendary_cards.csv, containing all Legendary Creatures elligible to be commanders.') +def determine_commanders(): + print('Generating commander_cards.csv, containing all cards elligible to be commanders.') # Filter dataframe while True: try: @@ -66,7 +68,7 @@ def determine_legendary(): # Load cards.csv file into pandas dataframe so it can be further broken down df = pd.read_csv(f'{csv_directory}/cards.csv', low_memory=False) - legendary_options = ['Legendary Creature', 'Legendary Artifact Creature', 'Legendary Enchantment Creature'] + legendary_options = ['Legendary Creature','Legendary Artifact', 'Legendary Artifact Creature', 'Legendary Enchantment Creature', 'Legendary Planeswalker'] filtered_df = df[df['type'].str.contains('|'.join(legendary_options))] """ Save the filtered dataframe to a new csv file, and narrow down/rearranges the columns it @@ -74,12 +76,27 @@ def determine_legendary(): Additionally attempts to remove as many duplicates (including cards with reversible prints, as well as taking out Arena-only cards. """ + rows_to_drop = [] + non_legel_sets = ['PHTR', 'PH17', 'PH18' ,'PH19', 'PH20', 'PH21', 'UGL', 'UND', 'UNH', 'UST',] + for index, row in filtered_df.iterrows(): + if ('Legendary Artifact' in row['type'] + or 'Legendary Planeswalker' in row['type']): + if 'Legendary Artifact Creature' not in row['type']: + if pd.notna(row['text']): + if f'{row['name']} can be your commander' in row['text']: + rows_to_drop.append(index) + for illegal_set in non_legel_sets: + if illegal_set in row['printings']: + rows_to_drop.append(index) + + filtered_df = filtered_df.drop(rows_to_drop) + filtered_df.sort_values('name') filtered_df = filtered_df.loc[filtered_df['layout'] != 'reversible_card'] filtered_df = filtered_df[filtered_df['availability'].str.contains('paper')] filtered_df = filtered_df.loc[filtered_df['promoTypes'] != 'playtest'] filtered_df = filtered_df.loc[filtered_df['securityStamp'] != 'heart'] - filtered_df = filtered_df.loc[filtered_df['securityStamp'] != 'acorn'] + filtered_df = filtered_df.loc[filtered_df['securityStamp'] != 'acorn'] card_types = ['Plane —', 'Conspiracy', 'Vanguard', 'Scheme', 'Phenomena', 'Stickers', 'Attraction'] for card_type in card_types: @@ -89,8 +106,8 @@ def determine_legendary(): columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'text', 'power', 'toughness'] filtered_df = filtered_df[columns_to_keep] filtered_df.sort_values(by='name', key=lambda col: col.str.lower(), inplace=True) - filtered_df.to_csv(f'{csv_directory}/legendary_cards.csv', index=False) - print('legendary_cards.csv file generated.') + filtered_df.to_csv(f'{csv_directory}/commander_cards.csv', index=False) + print('commander_cards.csv file generated.') def initial_setup(): print('Checking for cards.csv file.\n') @@ -127,7 +144,7 @@ def initial_setup(): filter_by_color(df, 'colorIdentity', color_abrv[i], f'{csv_directory}/{colors[i]}_cards.csv') # Once by-color lists have been made, Determine legendary creatures - determine_legendary() + determine_commanders() # Once Legendary creatures are determined, generate staple lists # generate_staple_lists() @@ -144,11 +161,19 @@ def regenerate_csvs_all(): outputfile.write(r.content) # Load cards.csv file into pandas dataframe so it can be further broken down - df = pd.read_csv('csv_files/cards.csv', low_memory=False) + df = pd.read_csv('csv_files/cards.csv', low_memory=False)#, converters={'printings': pd.eval}) # Set frames that have nothing for color identity to be 'Colorless' instead df['colorIdentity'] = df['colorIdentity'].fillna('Colorless') + rows_to_drop = [] + non_legel_sets = ['PHTR', 'PH17', 'PH18' ,'PH19', 'PH20', 'PH21', 'UGL', 'UND', 'UNH', 'UST',] + for index, row in df.iterrows(): + for illegal_set in non_legel_sets: + if illegal_set in row['printings']: + rows_to_drop.append(index) + df = df.drop(rows_to_drop) + # Color identity sorted cards print('Regenerating color identity sorted files.\n') @@ -159,7 +184,7 @@ def regenerate_csvs_all(): print(f'A new {colors[i]}_cards.csv file has been made.\n') # Once files are regenerated, create a new legendary list - determine_legendary() + determine_commanders() def regenerate_csv_by_color(color): """ @@ -188,7 +213,7 @@ def regenerate_csv_by_color(color): print(f'A new {color}_cards.csv file has been made.\n') # Once files are regenerated, create a new legendary list - determine_legendary() + determine_commanders() def generate_staple_lists(): for color in colors: @@ -257,5 +282,6 @@ def setup(): break break -#setup() -#regenerate_csv_by_color('white') \ No newline at end of file +#regenerate_csvs_all() +#regenerate_csv_by_color('white') +#determine_commanders() \ No newline at end of file diff --git a/tagger.py b/tagger.py index 68c93ac..df6b3d1 100644 --- a/tagger.py +++ b/tagger.py @@ -11,9 +11,6 @@ from utility import pluralize, sort_list karnstruct = '0/0 colorless Construct' -df = pd.DataFrame() -color = '' - ### Setup ## Load the dataframe def load_dataframe(color): @@ -27,27 +24,28 @@ def load_dataframe(color): # Setup dataframe while True: try: - check_df = pd.read_csv(f'{csv_directory}/{color}_cards.csv') - column_checks = ['creatureTypes', 'themeTags'] - if 'themeTags' not in check_df.columns or 'creatureTypes' not in check_df.columns: - for column in column_checks: - if column in check_df.columns: - print(f'"{column}" column in {color}_cards.csv.') - elif column not in check_df.columns: - print(f'"{column}" column not found in {color}_cards.csv.\n') - if column == 'creatureTypes': - kindred_tagging(check_df, color) - if column == 'themeTags': - create_theme_tags(check_df, color) - if 'themeTags' in check_df.columns and 'creatureTypes' in check_df.columns: - global df - df = pd.read_csv(f'{csv_directory}/{color}_cards.csv', converters={'themeTags': pd.eval, 'creatureTypes': pd.eval}) - - break + with open(f'{csv_directory}/{color}_cards.csv', 'r', encoding='utf-8') as f: + print(f'{color}_cards.csv found.') + f.close() + break except FileNotFoundError: print(f'{color}_cards.csv not found, regenerating it.') regenerate_csv_by_color(color) - + check_df = pd.read_csv(f'{csv_directory}/{color}_cards.csv') + column_checks = ['creatureTypes', 'themeTags'] + if 'themeTags' not in check_df.columns or 'creatureTypes' not in check_df.columns: + for column in column_checks: + if column in check_df.columns: + print(f'"{column}" column in {color}_cards.csv.') + elif column not in check_df.columns: + print(f'"{column}" column not found in {color}_cards.csv.\n') + if column == 'creatureTypes': + kindred_tagging(check_df, color) + if column == 'themeTags': + create_theme_tags(check_df, color) + if 'themeTags' in check_df.columns and 'creatureTypes' in check_df.columns: + df = pd.read_csv(f'{csv_directory}/{color}_cards.csv', converters={'themeTags': pd.eval, 'creatureTypes': pd.eval}) + tag_by_color(df, color) ## Tag cards on a color-by-color basis @@ -68,7 +66,7 @@ def tag_by_color(df, color): create_theme_tags(df, color) print('====================\n') - # Go through each type of tagging + """# Go through each type of tagging #keyboard.wait('space') add_creatures_to_tags(df, color) print('====================\n') @@ -115,6 +113,9 @@ def tag_by_color(df, color): tag_for_themes(df, color) print('====================\n') + """ + tag_for_toughness(df, color) + # Lastly, sort all theme tags for easier reading sort_theme_tags(df, color) df.to_csv(f'{csv_directory}/{color}_cards.csv', index=False) @@ -2871,6 +2872,30 @@ def tag_for_cantrips(df, color): # Overwrite file with Spells Matter tag added print(f'"Cantrip" themed cards in {color}_cards.csv have been tagged.\n') +## Spell Copy +def tag_for_spell_copy(df, color): + print(f'Tagging cards in {color}_cards.csv that fit the "Spell Copy" theme.') + for index, row in df.iterrows(): + theme_tags = row['themeTags'] + if pd.notna(row['text']): + if ('' in row['text'].lower() + ): + tag_type = ['Spell Copy'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + if pd.notna(row['keywords']): + if ('' in row['keywords'] + ): + tag_type = ['Spell Copy'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + print(f'"Spell Copy" cards in {color}_cards.csv have been tagged.\n') + ### Ramp def tag_for_ramp(df, color): # Tag for ramp @@ -3145,30 +3170,57 @@ def tag_for_themes(df, color): print('==========\n') tag_for_x_spells(df, color) - ## Aggro def tag_for_aggro(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('a creature attacking' in row['text'].lower() + or 'deal combat damage' in row['text'].lower() + or 'deals combat damage' in row['text'].lower() + or 'have riot' in row['text'].lower() + or 'this creature attacks' in row['text'].lower() + or 'whenever you attack' in row['text'].lower() + or f'whenever {row['name'].lower()} attack' in row['text'].lower() + or f'whenever {row['name'].lower()} deals combat' in row['text'].lower() + or 'you control attack' in row['text'].lower() + or 'you control deals combat' in row['text'].lower() + or 'untap all attacking creatures' in row['text'].lower() ): - tag_type = [] + tag_type = ['Aggro', 'Combat Matters'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Blitz' in row['keywords'] + or 'Deathtouch' in row['keywords'] + or 'Double Strike' in row['keywords'] + or 'First Strike' in row['keywords'] + or 'Fear' in row['keywords'] + or 'Haste' in row['keywords'] + or 'Menace' in row['keywords'] + or 'Myriad' in row['keywords'] + or 'Prowl' in row['keywords'] + or 'Raid' in row['keywords'] + or 'Shadow' in row['keywords'] + or 'Spectale' in row['keywords'] + or 'Trample' in row['keywords'] ): - tag_type = [] + tag_type = ['Aggro', 'Combat Matters'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + if ('Voltron' in theme_tags): + tag_type = ['Aggro', 'Combat Matters'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"" cards in {color}_cards.csv have been tagged.\n') ## Aristocrats def search_for_aristocrats(df, color): @@ -3266,83 +3318,220 @@ def search_for_aristocrats(df, color): ## Big Mana def tag_for_big_mana(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Big Mana" theme.') + df['manaValue'] = df['manaValue'].astype(int) + df['manaCost'] = df['manaCost'].astype(str) for index, row in df.iterrows(): theme_tags = row['themeTags'] + + # Specific cards + if (row['name'] == 'Akroma\'s Memorial' + or row['name'] == 'Forsake Monument' + or row['name'] == 'Guardian Project' + or row['name'] == 'Omniscience' + or row['name'] == 'One with the Multiverse' + or row['name'] == 'Portal to Phyrexia' + ): + tag_type = ['Big Mana'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + if pd.notna(row['text']): - if ('' in row['text'].lower() + # Mana value 5 or greater matters + if ( + 'add {w}{u}{b}{r}{g}' in row['text'].lower() + or 'card onto the battlefield' in row['text'].lower() + or 'control with power 3 or greater' in row['text'].lower() + or 'control with power 4 or greater' in row['text'].lower() + or 'control with power 5 or greater' in row['text'].lower() + or 'creature with power 3 or greater' in row['text'].lower() + or 'creature with power 4 or greater' in row['text'].lower() + or 'creature with power 5 or greater' in row['text'].lower() + or 'double the power' in row['text'].lower() + or 'from among them onto the battlefield' in row['text'].lower() + or 'from among them without paying' in row['text'].lower() + or 'hand onto the battlefield' in row['text'].lower() + or 'mana, add one mana' in row['text'].lower() + or 'mana, it produces twice' in row['text'].lower() + or 'mana, it produces three' in row['text'].lower() + or 'mana, its controller adds' in row['text'].lower() + or 'you may cast it without paying' in row['text'].lower() + or 'pay {w}{u}{b}{r}{g}' in row['text'].lower() + or 'spell with power 5 or greater' in row['text'].lower() + or 'value 5 or greater' in row['text'].lower() + or 'value 6 or greater' in row['text'].lower() + or 'value 7 or greater' in row['text'].lower() ): - tag_type = [] + print(row['name']) + tag_type = ['Big Mana'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + # Spells with mana value 5 or greater + if row['manaValue'] >= 5: + tag_type = ['Big Mana'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + # X spells + if ('{X}' in row['manaCost'] + ): + tag_type = ['Big Mana'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + # Keywords that care about big mana if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Cascade' in row['keywords'].lower() + or 'Convoke' in row['keywords'].lower() + or 'Discover' in row['keywords'].lower() ): - tag_type = [] + tag_type = ['Big Mana'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + # Already tagged things + if ('Cost Reduction' in row['manaCost'] + ): + tag_type = ['Big Mana'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Big Mana" themed cards in {color}_cards.csv have been tagged.\n') ## Blink def tag_for_blink(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Blink/Flicker" theme.\n' + 'Cards here can generally also fit an ETB matters theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('creature entering causes' in row['text'].lower() + or 'exile any number of other' in row['text'].lower() + or 'exile one or more cards from your hand' in row['text'].lower() + or 'permanent entering the battlefield' in row['text'].lower() + or 'permanent you control, then return' in row['text'].lower() + or 'permanent you control enters' in row['text'].lower() + or 'permanents you control, then return' in row['text'].lower() + or 'return it to the battlefield' in row['text'].lower() + or 'return that card to the battlefield' in row['text'].lower() + or 'return them to the battlefield' in row['text'].lower() + or 'return those cards to the battlefield' in row['text'].lower() + or 'triggered ability of a permanent' in row['text'].lower() + or 'whenever another creature enters' in row['text'].lower() + or 'whenever another nontoken creature enters' in row['text'].lower() + or f'when {row['name']} enters' in row['text'].lower() + or f'when {row['name']} leaves' in row['text'].lower() + or 'when this creature enters' in row['text'].lower() + or 'when this creature leaves' in row['text'].lower() + or 'whenever this creature enters' in row['text'].lower() + or 'whenever this creature leaves' in row['text'].lower() + or f'whenever {row['name']} enters' in row['text'].lower() + or f'whenever {row['name']} leaves' in row['text'].lower() ): - tag_type = [] - for tag in tag_type: - if tag not in theme_tags: - theme_tags.extend([tag]) - df.at[index, 'themeTags'] = theme_tags - if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() - ): - tag_type = [] + tag_type = ['Blink', 'Enter the Battlefield', 'Leave the Battlefield'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Blink/Flicker" cards in {color}_cards.csv have been tagged.\n') ## Burn def tag_for_burn(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Burn" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] + damage_list = list(range(1, 101)) + damage_list = list(map(str, damage_list)) + damage_list.append('x') if pd.notna(row['text']): - if ('' in row['text'].lower() + # Deals damage from 1-100 or X + for i in damage_list: + if (f'deals {i} damage' in row['text'].lower() + or f'lose {i} life' in row['text'].lower() + or f'loses {i} life' in row['text'].lower() + ): + tag_type = ['Burn'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + # Deals damage triggers + if ( + 'deals combat damage' in row['text'].lower() + or 'deals damage' in row['text'].lower() + or 'deals noncombat damage' in row['text'].lower() + or 'deals that much damage' in row['text'].lower() + or 'each 1 life' in row['text'].lower() + or 'excess damage' in row['text'].lower() + or 'excess noncombat damage' in row['text'].lower() + or 'loses that much life' in row['text'].lower() + or 'opponent lost life' in row['text'].lower() + or 'opponent loses life' in row['text'].lower() + or 'player loses life' in row['text'].lower() + or 'would deal an amount of noncombat damage' in row['text'].lower() + or 'would deal damage' in row['text'].lower() + or 'would deal noncombat damage' in row['text'].lower() + or 'would lose life' in row['text'].lower() ): - tag_type = [] + tag_type = ['Burn'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + + # Pingers + if ('deals 1 damage' in row['text'].lower() + or 'exactly 1 damage' in row['text'].lower() + or 'loses 1 life' in row['text'].lower() ): - tag_type = [] + tag_type = ['Pingers'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + # Keywords + if pd.notna(row['keywords']): + if ('Bloodthirst' in row['keywords'].lower() + or 'Spectacle' in row['keywords'].lower() + ): + tag_type = ['Burn'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Burn" cards in {color}_cards.csv have been tagged.\n') ## Clones def tag_for_clones(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Clones" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('a copy of a creature' in row['text'].lower() + or 'a copy of an aura' in row['text'].lower() + or 'a copy of a permanent' in row['text'].lower() + or 'a token that\'s a copy of' in row['text'].lower() + or 'as a copy of' in row['text'].lower() + or 'becomes a copy of' in row['text'].lower() + or '"legend rule" doesn\'t apply' in row['text'].lower() + or 'twice that many of those tokens' in row['text'].lower() ): tag_type = [] for tag in tag_type: @@ -3350,7 +3539,7 @@ def tag_for_clones(df, color): theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Myriad' in row['keywords'] ): tag_type = [] for tag in tag_type: @@ -3358,31 +3547,41 @@ def tag_for_clones(df, color): theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Clones" cards in {color}_cards.csv have been tagged.\n') ## Control def tag_for_control(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Control" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('a player casts' in row['text'].lower() + or 'can\'t attacok you' in row['text'].lower() + or 'cast your first spell during each opponent\'s turns' in row['text'].lower() + or 'choose new target' in row['text'].lower() + or 'choose target opponent' in row['text'].lower() + or 'counter target' in row['text'].lower() + or 'of an opponent\'s choice' in row['text'].lower() + or 'opponent cast' in row['text'].lower() + or 'return target' in row['text'].lower() + or 'tap an untapped creature' in row['text'].lower() + or 'your opponents cast' in row['text'].lower() ): - tag_type = [] + tag_type = ['Control'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Council\'s dilemma' in row['keywords'] ): - tag_type = [] + tag_type = ['Control'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Control" cards in {color}_cards.csv have been tagged.\n') ## Infect def tag_for_infect(df, color): @@ -3390,7 +3589,8 @@ def tag_for_infect(df, color): for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('poison counter' in row['text'].lower() + if ('one or more counter' in row['text'].lower() + or 'poison counter' in row['text'].lower() or 'toxic 1' in row['text'].lower() ): tag_type = [] @@ -3506,147 +3706,244 @@ def tag_for_mill(df, color): ## Planeswalkers def tag_for_planeswalkers(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Planeswalkers/Super Friends" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('a planeswalker' in row['text'].lower() + or 'affinity for planeswalker' in row['text'].lower() + or 'a noncreature' in row['text'].lower() + or 'enchant planeswalker' in row['text'].lower() + or 'historic permanent' in row['text'].lower() + or 'legendary permanent' in row['text'].lower() + or 'loyalty ability' in row['text'].lower() + or 'one or more counter' in row['text'].lower() + or 'planeswalker spells' in row['text'].lower() + or 'planeswalker type' in row['text'].lower() ): - tag_type = [] + tag_type = ['Planeswalkers', 'Super Friends'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Proliferate' in row['keywords'] ): - tag_type = [] + tag_type = ['Planeswalkers', 'Super Friends'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + if 'Planeswalker' in row['type']: + tag_type = ['Planeswalkers', 'Super Friends'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Planeswalkers/Super Friends" cards in {color}_cards.csv have been tagged.\n') ## Reanimator def tag_for_reanimate(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Reanimate" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('descended' in row['text'].lower() + or 'discard your hand' in row['text'].lower() + or 'from a graveyard' in row['text'].lower() + or 'in a graveyard' in row['text'].lower() + or 'into a graveyard' in row['text'].lower() + or 'leave a graveyard' in row['text'].lower() + or 'from a graveyard' in row['text'].lower() + or 'in your graveyard' in row['text'].lower() + or 'into your graveyard' in row['text'].lower() + or 'leave your graveyard' in row['text'].lower() ): - tag_type = [] + tag_type = ['Reanimate'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Blitz' in row['keywords'] + or 'Connive' in row['keywords'] + or 'Descend' in row['keywords'] + or 'Escape' in row['keywords'] + or 'Flashback' in row['keywords'] + or 'Mill' in row['keywords'] ): - tag_type = [] + tag_type = ['Reanimate'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + if ('Loot' in theme_tags + ): + tag_type = ['Reanimate'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags + + if ('Zombie' in row['creatureTypes'] + ): + tag_type = ['Reanimate'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Reanimate" cards in {color}_cards.csv have been tagged.\n') ## Stax def tag_for_stax(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() - ): - tag_type = [] - for tag in tag_type: - if tag not in theme_tags: - theme_tags.extend([tag]) - df.at[index, 'themeTags'] = theme_tags - if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('an opponent controls' in row['text'].lower() + or 'can attack you' in row['text'].lower() + or 'can\'t attack' in row['text'].lower() + or 'can\'t be cast' in row['text'].lower() + or 'can\'t be activated' in row['text'].lower() + or 'can\'t cast spells' in row['text'].lower() + or 'can\'t enter' in row['text'].lower() + or 'can\'t search' in row['text'].lower() + or 'can\'t untap' in row['text'].lower() + or 'don\'t untap' in row['text'].lower() + or 'don\'t cause abilities' in row['text'].lower() + or 'each other player\'s' in row['text'].lower() + or 'each player\'s upkeep' in row['text'].lower() + or 'opponent would search' in row['text'].lower() + or 'opponents cast cost' in row['text'].lower() + or 'opponents can\'t' in row['text'].lower() + or 'opponents control' in row['text'].lower() + or 'opponents control can\'t' in row['text'].lower() + or 'opponents control enter tapped' in row['text'].lower() + or 'spells cost {1} more' in row['text'].lower() + or 'spells cost {2} more' in row['text'].lower() + or 'spells cost {3} more' in row['text'].lower() + or 'spells cost {4} more' in row['text'].lower() + or 'spells cost {5} more' in row['text'].lower() + or 'that player doesn\'t' in row['text'].lower() + or 'unless that player pays' in row['text'].lower() + or 'you control your opponent' in row['text'].lower() + or 'you gain protection' in row['text'].lower() ): tag_type = [] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + if ('Control' in theme_tags + ): + tag_type = [] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"" cards in {color}_cards.csv have been tagged.\n') ## Toughness Matters def tag_for_toughness(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Toughness Matters" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ( + 'card\'s toughness' in row['text'].lower() + or 'creature\'s toughness' in row['text'].lower() + or 'damage equal to its toughness' in row['text'].lower() + or 'lesser toughness' in row['text'].lower() + or 'total toughness' in row['text'].lower() + or 'toughness greater' in row['text'].lower() + or 'with defender' in row['text'].lower() ): - tag_type = [] + tag_type = ['Toughness Matters'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Defender' in row['keywords'] ): - tag_type = [] + tag_type = ['Toughness Matters'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags + + if row['toughness'] > row['power']: + tag_type = ['Toughness Matters'] + for tag in tag_type: + if tag not in theme_tags: + theme_tags.extend([tag]) + df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Toughness Matters" cards in {color}_cards.csv have been tagged.\n') ## Topdeck def tag_for_topdeck(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "Topdeck" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): - if ('' in row['text'].lower() + if ('from the top' in row['text'].lower() + or 'look at the top' in row['text'].lower() + or 'reveal the top' in row['text'].lower() + or 'scries' in row['text'].lower() + or 'surveils' in row['text'].lower() + or 'top of your library' in row['text'].lower() + or 'you scry' in row['text'].lower() + or 'you surveil' in row['text'].lower() ): - tag_type = [] + tag_type = ['Topdeck'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('Miracle' in row['keywords'] + or 'Scry' in row['keywords'] + or 'Surveil' in row['keywords'] ): - tag_type = [] + tag_type = ['Topdeck'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"Topdeck" cards in {color}_cards.csv have been tagged.\n') ## X Spells def tag_for_x_spells(df, color): - print(f'Tagging cards in {color}_cards.csv that have "".') + print(f'Tagging cards in {color}_cards.csv that fit the "X Spells" theme.') for index, row in df.iterrows(): theme_tags = row['themeTags'] if pd.notna(row['text']): if ('' in row['text'].lower() ): - tag_type = [] + tag_type = ['X Spells'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags if pd.notna(row['keywords']): - if ('' in row['keywords'].lower() + if ('' in row['keywords'] ): - tag_type = [] + tag_type = ['X Spells'] for tag in tag_type: if tag not in theme_tags: theme_tags.extend([tag]) df.at[index, 'themeTags'] = theme_tags - print(f'Cards with "" in {color}_cards.csv have been tagged.\n') + print(f'"X Spells" cards in {color}_cards.csv have been tagged.\n') #regenerate_csv_by_color('colorless')