Added logic for more themes

Adjusted setup to exclude unsets and Heroes of the realm cards
This commit is contained in:
mwisnowski 2024-12-17 12:02:53 -08:00
parent 94d42d93cf
commit 4a3d9c423e
3 changed files with 441 additions and 118 deletions

View file

@ -29,7 +29,7 @@ colors = ['colorless', 'white', 'blue', 'black', 'red', 'green',
'bant', 'esper', 'grixis', 'jund', 'naya', 'bant', 'esper', 'grixis', 'jund', 'naya',
'abzan', 'jeskai', 'mardu', 'sultai', 'temur', 'abzan', 'jeskai', 'mardu', 'sultai', 'temur',
'dune', 'glint', 'ink', 'witch', 'yore', 'wubrg', 'dune', 'glint', 'ink', 'witch', 'yore', 'wubrg',
'legendary'] 'commander']
counter_types = ['+0/+1', '+0/+2', '+1/+0', '+1/+2', '+2/+0', '+2/+2', 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', '-0/-1', '-0/-2', '-1/-0', '-1/-2', '-2/-0', '-2/-2',

View file

@ -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'] columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'text', 'power', 'toughness', 'keywords']
filtered_df = filtered_df[columns_to_keep] filtered_df = filtered_df[columns_to_keep]
filtered_df.sort_values(by='name', key=lambda col: col.str.lower(), inplace=True) filtered_df.sort_values(by='name', key=lambda col: col.str.lower(), inplace=True)
filtered_df.to_csv(new_csv_name, index=False) filtered_df.to_csv(new_csv_name, index=False)
def determine_legendary(): def determine_commanders():
print('Generating legendary_cards.csv, containing all Legendary Creatures elligible to be commanders.') print('Generating commander_cards.csv, containing all cards elligible to be commanders.')
# Filter dataframe # Filter dataframe
while True: while True:
try: try:
@ -66,7 +68,7 @@ def determine_legendary():
# Load cards.csv file into pandas dataframe so it can be further broken down # 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) 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))] 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 Save the filtered dataframe to a new csv file, and narrow down/rearranges the columns it
@ -74,6 +76,21 @@ def determine_legendary():
Additionally attempts to remove as many duplicates (including cards with reversible prints, Additionally attempts to remove as many duplicates (including cards with reversible prints,
as well as taking out Arena-only cards. 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.sort_values('name')
filtered_df = filtered_df.loc[filtered_df['layout'] != 'reversible_card'] filtered_df = filtered_df.loc[filtered_df['layout'] != 'reversible_card']
filtered_df = filtered_df[filtered_df['availability'].str.contains('paper')] filtered_df = filtered_df[filtered_df['availability'].str.contains('paper')]
@ -89,8 +106,8 @@ def determine_legendary():
columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'text', 'power', 'toughness'] columns_to_keep = ['name', 'faceName','edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'text', 'power', 'toughness']
filtered_df = filtered_df[columns_to_keep] filtered_df = filtered_df[columns_to_keep]
filtered_df.sort_values(by='name', key=lambda col: col.str.lower(), inplace=True) 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) filtered_df.to_csv(f'{csv_directory}/commander_cards.csv', index=False)
print('legendary_cards.csv file generated.') print('commander_cards.csv file generated.')
def initial_setup(): def initial_setup():
print('Checking for cards.csv file.\n') 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') 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 # Once by-color lists have been made, Determine legendary creatures
determine_legendary() determine_commanders()
# Once Legendary creatures are determined, generate staple lists # Once Legendary creatures are determined, generate staple lists
# generate_staple_lists() # generate_staple_lists()
@ -144,11 +161,19 @@ def regenerate_csvs_all():
outputfile.write(r.content) outputfile.write(r.content)
# Load cards.csv file into pandas dataframe so it can be further broken down # 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 # Set frames that have nothing for color identity to be 'Colorless' instead
df['colorIdentity'] = df['colorIdentity'].fillna('Colorless') 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 # Color identity sorted cards
print('Regenerating color identity sorted files.\n') 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') print(f'A new {colors[i]}_cards.csv file has been made.\n')
# Once files are regenerated, create a new legendary list # Once files are regenerated, create a new legendary list
determine_legendary() determine_commanders()
def regenerate_csv_by_color(color): 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') print(f'A new {color}_cards.csv file has been made.\n')
# Once files are regenerated, create a new legendary list # Once files are regenerated, create a new legendary list
determine_legendary() determine_commanders()
def generate_staple_lists(): def generate_staple_lists():
for color in colors: for color in colors:
@ -257,5 +282,6 @@ def setup():
break break
break break
#setup() #regenerate_csvs_all()
#regenerate_csv_by_color('white') #regenerate_csv_by_color('white')
#determine_commanders()

519
tagger.py
View file

@ -11,9 +11,6 @@ from utility import pluralize, sort_list
karnstruct = '0/0 colorless Construct' karnstruct = '0/0 colorless Construct'
df = pd.DataFrame()
color = ''
### Setup ### Setup
## Load the dataframe ## Load the dataframe
def load_dataframe(color): def load_dataframe(color):
@ -27,6 +24,13 @@ def load_dataframe(color):
# Setup dataframe # Setup dataframe
while True: while True:
try: try:
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') check_df = pd.read_csv(f'{csv_directory}/{color}_cards.csv')
column_checks = ['creatureTypes', 'themeTags'] column_checks = ['creatureTypes', 'themeTags']
if 'themeTags' not in check_df.columns or 'creatureTypes' not in check_df.columns: if 'themeTags' not in check_df.columns or 'creatureTypes' not in check_df.columns:
@ -40,14 +44,8 @@ def load_dataframe(color):
if column == 'themeTags': if column == 'themeTags':
create_theme_tags(check_df, color) create_theme_tags(check_df, color)
if 'themeTags' in check_df.columns and 'creatureTypes' in check_df.columns: 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}) df = pd.read_csv(f'{csv_directory}/{color}_cards.csv', converters={'themeTags': pd.eval, 'creatureTypes': pd.eval})
break
except FileNotFoundError:
print(f'{color}_cards.csv not found, regenerating it.')
regenerate_csv_by_color(color)
tag_by_color(df, color) tag_by_color(df, color)
## Tag cards on a color-by-color basis ## Tag cards on a color-by-color basis
@ -68,7 +66,7 @@ def tag_by_color(df, color):
create_theme_tags(df, color) create_theme_tags(df, color)
print('====================\n') print('====================\n')
# Go through each type of tagging """# Go through each type of tagging
#keyboard.wait('space') #keyboard.wait('space')
add_creatures_to_tags(df, color) add_creatures_to_tags(df, color)
print('====================\n') print('====================\n')
@ -115,6 +113,9 @@ def tag_by_color(df, color):
tag_for_themes(df, color) tag_for_themes(df, color)
print('====================\n') print('====================\n')
"""
tag_for_toughness(df, color)
# Lastly, sort all theme tags for easier reading # Lastly, sort all theme tags for easier reading
sort_theme_tags(df, color) sort_theme_tags(df, color)
df.to_csv(f'{csv_directory}/{color}_cards.csv', index=False) 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 # Overwrite file with Spells Matter tag added
print(f'"Cantrip" themed cards in {color}_cards.csv have been tagged.\n') 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 ### Ramp
def tag_for_ramp(df, color): def tag_for_ramp(df, color):
# Tag for ramp # Tag for ramp
@ -3145,30 +3170,57 @@ def tag_for_themes(df, color):
print('==========\n') print('==========\n')
tag_for_x_spells(df, color) tag_for_x_spells(df, color)
## Aggro ## Aggro
def tag_for_aggro(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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 ## Aristocrats
def search_for_aristocrats(df, color): def search_for_aristocrats(df, color):
@ -3266,83 +3318,220 @@ def search_for_aristocrats(df, color):
## Big Mana ## Big Mana
def tag_for_big_mana(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']):
if ('' in row['text'].lower() # 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 = [] 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['keywords']):
if ('' in row['keywords'].lower()
):
tag_type = []
for tag in tag_type: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') if pd.notna(row['text']):
# 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()
):
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 ('Cascade' in row['keywords'].lower()
or 'Convoke' in row['keywords'].lower()
or 'Discover' in row['keywords'].lower()
):
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'"Big Mana" themed cards in {color}_cards.csv have been tagged.\n')
## Blink ## Blink
def tag_for_blink(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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 = [] 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
if pd.notna(row['keywords']):
if ('' in row['keywords'].lower()
):
tag_type = []
for tag in tag_type: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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 ## Burn
def tag_for_burn(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] 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 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 = [] 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()
):
tag_type = []
for tag in tag_type: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') # 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 = ['Burn']
for tag in tag_type:
if tag not in theme_tags:
theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags
# 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 = ['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'"Burn" cards in {color}_cards.csv have been tagged.\n')
## Clones ## Clones
def tag_for_clones(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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 = [] tag_type = []
for tag in tag_type: for tag in tag_type:
@ -3350,7 +3539,7 @@ def tag_for_clones(df, color):
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): if pd.notna(row['keywords']):
if ('' in row['keywords'].lower() if ('Myriad' in row['keywords']
): ):
tag_type = [] tag_type = []
for tag in tag_type: for tag in tag_type:
@ -3358,31 +3547,41 @@ def tag_for_clones(df, color):
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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 ## Control
def tag_for_control(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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 ## Infect
def tag_for_infect(df, color): def tag_for_infect(df, color):
@ -3390,7 +3589,8 @@ def tag_for_infect(df, color):
for index, row in df.iterrows(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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() or 'toxic 1' in row['text'].lower()
): ):
tag_type = [] tag_type = []
@ -3506,67 +3706,132 @@ def tag_for_mill(df, color):
## Planeswalkers ## Planeswalkers
def tag_for_planeswalkers(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') 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'"Planeswalkers/Super Friends" cards in {color}_cards.csv have been tagged.\n')
## Reanimator ## Reanimator
def tag_for_reanimate(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') 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'"Reanimate" cards in {color}_cards.csv have been tagged.\n')
## Stax ## Stax
def tag_for_stax(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): if pd.notna(row['text']):
if ('' in row['text'].lower() if ('an opponent controls' in row['text'].lower()
): or 'can attack you' in row['text'].lower()
tag_type = [] or 'can\'t attack' in row['text'].lower()
for tag in tag_type: or 'can\'t be cast' in row['text'].lower()
if tag not in theme_tags: or 'can\'t be activated' in row['text'].lower()
theme_tags.extend([tag]) or 'can\'t cast spells' in row['text'].lower()
df.at[index, 'themeTags'] = theme_tags or 'can\'t enter' in row['text'].lower()
if pd.notna(row['keywords']): or 'can\'t search' in row['text'].lower()
if ('' in row['keywords'].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 = [] tag_type = []
for tag in tag_type: for tag in tag_type:
@ -3574,79 +3839,111 @@ def tag_for_stax(df, color):
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') 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 in {color}_cards.csv have been tagged.\n')
## Toughness Matters ## Toughness Matters
def tag_for_toughness(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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()
):
tag_type = []
for tag in tag_type: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
print(f'Cards with "" in {color}_cards.csv have been tagged.\n') if pd.notna(row['keywords']):
if ('Defender' in row['keywords']
):
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'"Toughness Matters" cards in {color}_cards.csv have been tagged.\n')
## Topdeck ## Topdeck
def tag_for_topdeck(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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 ## X Spells
def tag_for_x_spells(df, color): 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(): for index, row in df.iterrows():
theme_tags = row['themeTags'] theme_tags = row['themeTags']
if pd.notna(row['text']): if pd.notna(row['text']):
if ('' in row['text'].lower() if ('' in row['text'].lower()
): ):
tag_type = [] tag_type = ['X Spells']
for tag in tag_type: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags df.at[index, 'themeTags'] = theme_tags
if pd.notna(row['keywords']): 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: for tag in tag_type:
if tag not in theme_tags: if tag not in theme_tags:
theme_tags.extend([tag]) theme_tags.extend([tag])
df.at[index, 'themeTags'] = theme_tags 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') #regenerate_csv_by_color('colorless')