mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-09-22 04:50:46 +02:00
Started working on basic staples lists
This commit is contained in:
parent
d7e275e38a
commit
00ae707d16
1 changed files with 262 additions and 21 deletions
281
main.py
281
main.py
|
@ -1,30 +1,46 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
#import os
|
#import os
|
||||||
import requests # type: ignore
|
import inquirer.prompt # type: ignore
|
||||||
import pandas as pd # type: ignore
|
import pandas as pd # type: ignore
|
||||||
|
import requests # type: ignore
|
||||||
#import scrython # type: ignore
|
#import scrython # type: ignore
|
||||||
|
|
||||||
|
banned_cards = ['Ancestral Recall', 'Balance', 'Biorhythm', 'Black Lotus',
|
||||||
|
'Braids, Cabal Minion', 'Chaos Orb', 'Coalition Victory',
|
||||||
|
'Channel', 'Dockside Extortionist', 'Emrakul, the Aeons Torn',
|
||||||
|
'Erayo, Soratami Ascendant', 'Falling Star', 'Fastbond',
|
||||||
|
'Flash', 'Gifts Ungiven', 'Golos, Tireless Pilgrim',
|
||||||
|
'Griselbrand', 'Hullbreacher', 'Iona, Shield of Emeria',
|
||||||
|
'Karakas', 'Jeweled Lotus', 'Leovold, Emissary of Trest',
|
||||||
|
'Library of Alexandria', 'Limited Resources', 'Lutri, the Spellchaser',
|
||||||
|
'Mana Crypt', 'Mox Emerald', 'Mox Jet', 'Mox Pearl', 'Mox Ruby',
|
||||||
|
'Mox Sapphire', 'Nadu, Winged Wisdom', 'Panoptic Mirror',
|
||||||
|
'Paradox Engine', 'Primeval Titan', 'Prophet of Kruphix',
|
||||||
|
'Recurring Nightmare', 'Rofellos, Llanowar Emissary', 'Shahrazad',
|
||||||
|
'Sundering Titan', 'Sway of the Stars', 'Sylvan Primordial',
|
||||||
|
'Time Vault', 'Time Walk', 'Tinker', 'Tolarian Academy',
|
||||||
|
'Trade Secrets', 'Upheaval', 'Yawgmoth\'s Bargain']
|
||||||
|
|
||||||
def filter_by_color(df, column_name, value, new_csv_name):
|
def filter_by_color(df, column_name, value, new_csv_name):
|
||||||
# Filter dataframe
|
# Filter dataframe
|
||||||
filtered_df = df[df[column_name] == value]
|
filtered_df = df[df[column_name] == value]
|
||||||
# Save the filtered dataframe to a new csv file
|
# Save the filtered dataframe to a new csv file
|
||||||
columns_to_keep = ['name', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'power', 'toughness']
|
columns_to_keep = ['name', 'edhrecRank','colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'text', 'power', 'toughness', 'printings']
|
||||||
filtered_df = filtered_df[columns_to_keep]
|
filtered_df = filtered_df[columns_to_keep]
|
||||||
filtered_df.drop_duplicates(subset='name', inplace=True)
|
filtered_df.drop_duplicates(subset='name', inplace=True)
|
||||||
filtered_df.to_csv(new_csv_name, index=False)
|
filtered_df.to_csv(new_csv_name, index=False)
|
||||||
|
|
||||||
def initial_setup():
|
def initial_setup():
|
||||||
# Check if the overall cards.csv file exists
|
# Check if the overall cards.csv file exists
|
||||||
print('Checking if setup was previously finished.')
|
print('Checking if setup was previously finished.\n')
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with open('setup_done.txt', 'r') as setup:
|
with open('setup_done.txt', 'r'):
|
||||||
setup.close()
|
print('Setup is done.\n')
|
||||||
print('Setup is done.')
|
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('Checking for cards.csv file.')
|
print('Checking for cards.csv file.\n')
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with open('csv_files/cards.csv', 'r', encoding='utf-8'):
|
with open('csv_files/cards.csv', 'r', encoding='utf-8'):
|
||||||
|
@ -39,17 +55,17 @@ def initial_setup():
|
||||||
df = pd.read_csv('csv_files/cards.csv')
|
df = pd.read_csv('csv_files/cards.csv')
|
||||||
df['colorIdentity'] = df['colorIdentity'].fillna('None')
|
df['colorIdentity'] = df['colorIdentity'].fillna('None')
|
||||||
|
|
||||||
print('Checking for color identity sorted files.')
|
print('Checking for color identity sorted files.\n')
|
||||||
print('Checking for colorless_cards.csv.')
|
print('Checking for colorless_cards.csv.\n')
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with open('csv_files/colorless_cards.csv', 'r', encoding='utf-8'):
|
with open('csv_files/colorless_cards.csv', 'r', encoding='utf-8'):
|
||||||
print('colorless_cards.csv exists.')
|
print('colorless_cards.csv exists.\n')
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('colorless_cards.csv not found, creating it.')
|
print('colorless_cards.csv not found, creating it.\n')
|
||||||
filter_by_color(df, 'colorIdentity', 'None', 'csv_files/colorless_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'None', 'csv_files/colorless_cards.csv')
|
||||||
print('Checking for mono-color card lists.')
|
print('Checking for mono-color card lists.\n')
|
||||||
while True:
|
while True:
|
||||||
print('Checking for white_cards.csv.')
|
print('Checking for white_cards.csv.')
|
||||||
while True:
|
while True:
|
||||||
|
@ -97,7 +113,7 @@ def initial_setup():
|
||||||
print('green_cards.csv not found, creating it.')
|
print('green_cards.csv not found, creating it.')
|
||||||
filter_by_color(df, 'colorIdentity', 'G', 'csv_files/green_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'G', 'csv_files/green_cards.csv')
|
||||||
break
|
break
|
||||||
print('Checking for color-pair lists')
|
print('Checking for color-pair lists.\n')
|
||||||
while True:
|
while True:
|
||||||
print('Checking for azorius_cards.csv.')
|
print('Checking for azorius_cards.csv.')
|
||||||
while True:
|
while True:
|
||||||
|
@ -190,7 +206,7 @@ def initial_setup():
|
||||||
print('gruul_cards.csv not found, creating it.')
|
print('gruul_cards.csv not found, creating it.')
|
||||||
filter_by_color(df, 'colorIdentity', 'G, R', 'csv_files/gruul_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'G, R', 'csv_files/gruul_cards.csv')
|
||||||
break
|
break
|
||||||
print('Checking for three-color sets.')
|
print('Checking for three-color sets.\n')
|
||||||
while True:
|
while True:
|
||||||
print('Checking for bant_cards.csv.')
|
print('Checking for bant_cards.csv.')
|
||||||
while True:
|
while True:
|
||||||
|
@ -274,7 +290,7 @@ def initial_setup():
|
||||||
print('temur_cards.csv not found, creating it.')
|
print('temur_cards.csv not found, creating it.')
|
||||||
filter_by_color(df, 'colorIdentity', 'G, R, U', 'csv_files/temur_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'G, R, U', 'csv_files/temur_cards.csv')
|
||||||
break
|
break
|
||||||
print('Checking for four color sets.')
|
print('Checking for four color sets.\n')
|
||||||
while True:
|
while True:
|
||||||
print('Checking for dune_cards.csv.')
|
print('Checking for dune_cards.csv.')
|
||||||
while True:
|
while True:
|
||||||
|
@ -322,7 +338,7 @@ def initial_setup():
|
||||||
print('yore_cards.csv not found, creating it.')
|
print('yore_cards.csv not found, creating it.')
|
||||||
filter_by_color(df, 'colorIdentity', 'B, R, U, W', 'csv_files/yore_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'B, R, U, W', 'csv_files/yore_cards.csv')
|
||||||
break
|
break
|
||||||
print('Checking for wubrg_cards.csv.')
|
print('Checking for wubrg_cards.csv.\n')
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with open('csv_files/wubrg_cards.csv', 'r', encoding='utf-8'):
|
with open('csv_files/wubrg_cards.csv', 'r', encoding='utf-8'):
|
||||||
|
@ -331,12 +347,237 @@ def initial_setup():
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('wubrg_cards.csv not found, creating it.')
|
print('wubrg_cards.csv not found, creating it.')
|
||||||
filter_by_color(df, 'colorIdentity', 'B, G, R, U, W', 'csv_files/wubrg_cards.csv')
|
filter_by_color(df, 'colorIdentity', 'B, G, R, U, W', 'csv_files/wubrg_cards.csv')
|
||||||
print('Creating setup_done.txt file')
|
print('Creating setup_done.txt file.\n')
|
||||||
with open('setup_done.txt', 'w') as f:
|
with open('setup_done.txt', 'w') as f:
|
||||||
f.write('Setup is done')
|
f.write('Setup is done.')
|
||||||
f.close()
|
f.close()
|
||||||
|
staple_lists = ['Colorless', 'White', 'Blue', 'Black']
|
||||||
|
colorless_staples = [] # type: ignore
|
||||||
|
white_staples = [] # type: ignore
|
||||||
|
blue_staples = [] # type: ignore
|
||||||
|
black_staples = [] # type: ignore
|
||||||
|
def make_staples_list():
|
||||||
|
# Generate list of staples by color. This is subjective and can be modified as seen fit.
|
||||||
|
# At present it's based on top cards from edhrec, using the first 15 or so of each color
|
||||||
|
print('Making staple lists.\n')
|
||||||
|
print('Colorless staples:')
|
||||||
|
global colorless_staples
|
||||||
|
colorless_staples = [
|
||||||
|
'Sol Ring',
|
||||||
|
'Arcane Signet',
|
||||||
|
'Fellwar Stone',
|
||||||
|
'Skullclamp',
|
||||||
|
'Lightning Greaves',
|
||||||
|
'Swiftfoot Boots',
|
||||||
|
'Thought Vessel',
|
||||||
|
'Solemn Simulacrum',
|
||||||
|
'Mind Stone',
|
||||||
|
'Wayfarer\'s Bauble',
|
||||||
|
'Commander\'s Sphere'
|
||||||
|
]
|
||||||
|
colorless_staples.sort()
|
||||||
|
print(colorless_staples)
|
||||||
|
print('White staples:')
|
||||||
|
global white_staples
|
||||||
|
white_staples = [
|
||||||
|
'Swords to Plowshares',
|
||||||
|
'Path to Exile',
|
||||||
|
'Generous Gift',
|
||||||
|
'Smothering Tithe',
|
||||||
|
'Esper Sentinel',
|
||||||
|
'Teferi\'s Protection',
|
||||||
|
'Enlightened Tutor',
|
||||||
|
'Farewell',
|
||||||
|
'Austere Command',
|
||||||
|
'Ghostly Prison',
|
||||||
|
'Sun Titan',
|
||||||
|
'Flawless Maneuver',
|
||||||
|
'Akroma\'s Will',
|
||||||
|
'Annointed Procession',
|
||||||
|
'Wrath of God'
|
||||||
|
]
|
||||||
|
print(white_staples)
|
||||||
|
print('Blue staples:')
|
||||||
|
global blue_staples
|
||||||
|
blue_staples = [
|
||||||
|
'Counterspell',
|
||||||
|
'Cyclonic Rift',
|
||||||
|
'Rhystic Study',
|
||||||
|
'Negate',
|
||||||
|
'Brainstorm',
|
||||||
|
'An Offer You Can\'t Refuse',
|
||||||
|
'Arcane Denial',
|
||||||
|
'Mystic Remora',
|
||||||
|
'Fierce Guardianship',
|
||||||
|
'Swan Song',
|
||||||
|
'Mana Drain',
|
||||||
|
'Mystical Tutor',
|
||||||
|
'Windfall',
|
||||||
|
'Ponder',
|
||||||
|
'Frantic Search',
|
||||||
|
'Pongify',
|
||||||
|
'Propoganda',
|
||||||
|
'Preordain',
|
||||||
|
'Opt',
|
||||||
|
'Rapid Hybridization'
|
||||||
|
]
|
||||||
|
print(blue_staples)
|
||||||
|
print('Black staples:')
|
||||||
|
global black_staples
|
||||||
|
black_staples = [
|
||||||
|
'Demonic Tutor',
|
||||||
|
'Dark Ritual',
|
||||||
|
'Vampiric Tutor',
|
||||||
|
'Feed the Swarm',
|
||||||
|
'Toxic Deluge',
|
||||||
|
'Reanimate',
|
||||||
|
'Phyrexian Arena',
|
||||||
|
'Blood Artist',
|
||||||
|
'Victimize',
|
||||||
|
'Deadly Dispute',
|
||||||
|
'Deadly Rollick',
|
||||||
|
'Black Market Connections',
|
||||||
|
'Zulaport Cutthroat',
|
||||||
|
'Village Rites',
|
||||||
|
'Sign in Blood',
|
||||||
|
'Animate Dead',
|
||||||
|
'Bolas\'s Citadel',
|
||||||
|
'Gray Merchant of Asphodel',
|
||||||
|
'Syr Konrad, the Grim',
|
||||||
|
'Diabolic Intent'
|
||||||
|
]
|
||||||
|
print(black_staples)
|
||||||
|
|
||||||
#df = pd.read_csv('cards.csv')
|
return colorless_staples, white_staples, blue_staples, black_staples
|
||||||
|
|
||||||
|
def generate_staple_lists():
|
||||||
|
# Colorless staples
|
||||||
|
global colorless_staples
|
||||||
|
print('Colorless staples:')
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
with open('staples/colorless.txt', 'r') as file:
|
||||||
|
colorless_staples = file.read().split('\n')
|
||||||
|
del colorless_staples[-1]
|
||||||
|
print('\n'.join(colorless_staples), '\n')
|
||||||
|
break
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('Generating colorless staples list.')
|
||||||
|
df = pd.read_csv('csv_files/colorless_cards.csv')
|
||||||
|
df['edhrecRank'] = pd.to_numeric(df['edhrecRank'], downcast='integer', errors='coerce')
|
||||||
|
df = df.dropna(subset=['edhrecRank'])
|
||||||
|
df['edhrecRank'] = df['edhrecRank'].astype(int)
|
||||||
|
columns_to_keep = ['name', 'edhrecRank', 'type']
|
||||||
|
df = df[columns_to_keep]
|
||||||
|
i = 1
|
||||||
|
while len(colorless_staples) < 20:
|
||||||
|
for index, row in df.iterrows():
|
||||||
|
if row['edhrecRank'] == i:
|
||||||
|
if 'Land' not in row['type'] and row['name'] not in banned_cards:
|
||||||
|
colorless_staples.append(row['name'])
|
||||||
|
i += 1
|
||||||
|
#print(colorless_staples)
|
||||||
|
with open('staples/colorless.txt', 'w') as f:
|
||||||
|
for items in colorless_staples:
|
||||||
|
f.write('%s\n' %items)
|
||||||
|
# White staples
|
||||||
|
print('White staples:')
|
||||||
|
global white_staples
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
with open('staples/white.txt', 'r') as file:
|
||||||
|
white_staples = file.read().split('\n')
|
||||||
|
del white_staples[-1]
|
||||||
|
print('\n'.join(white_staples), '\n')
|
||||||
|
break
|
||||||
|
except FileNotFoundError:
|
||||||
|
print('Generating white staples list.')
|
||||||
|
df = pd.read_csv('csv_files/white_cards.csv')
|
||||||
|
df['edhrecRank'] = pd.to_numeric(df['edhrecRank'], downcast='integer', errors='coerce')
|
||||||
|
df = df.dropna(subset=['edhrecRank'])
|
||||||
|
df['edhrecRank'] = df['edhrecRank'].astype(int)
|
||||||
|
columns_to_keep = ['name', 'edhrecRank', 'type']
|
||||||
|
df = df[columns_to_keep]
|
||||||
|
i = 1
|
||||||
|
while len(white_staples) < 20:
|
||||||
|
for index, row in df.iterrows():
|
||||||
|
if row['edhrecRank'] == i:
|
||||||
|
if row['name'] not in banned_cards:
|
||||||
|
white_staples.append(row['name'])
|
||||||
|
i += 1
|
||||||
|
#print(white_staples)
|
||||||
|
with open('staples/white.txt', 'w') as f:
|
||||||
|
for items in white_staples:
|
||||||
|
f.write('%s\n' %items)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_card_info():
|
||||||
|
question = [
|
||||||
|
inquirer.List(
|
||||||
|
'staple_list',
|
||||||
|
message='Choose a staple list to check through',
|
||||||
|
choices=staple_lists,
|
||||||
|
carousel=True
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answer = inquirer.prompt(question)
|
||||||
|
staple_list_choice = answer['staple_list']
|
||||||
|
if staple_list_choice == 'Colorless':
|
||||||
|
staple = 'colorless'
|
||||||
|
question = [
|
||||||
|
inquirer.List(
|
||||||
|
'card_list',
|
||||||
|
message='Choose a card from the list.',
|
||||||
|
choices=colorless_staples,
|
||||||
|
carousel=True
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answer = inquirer.prompt(question)
|
||||||
|
card_choice = answer['card_list']
|
||||||
|
elif staple_list_choice == 'White':
|
||||||
|
staple = 'white'
|
||||||
|
question = [
|
||||||
|
inquirer.List(
|
||||||
|
'card_list',
|
||||||
|
message='Choose a card from the list.',
|
||||||
|
choices=white_staples,
|
||||||
|
carousel=True
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answer = inquirer.prompt(question)
|
||||||
|
card_choice = answer['card_list']
|
||||||
|
elif staple_list_choice == 'Blue':
|
||||||
|
staple = 'blue'
|
||||||
|
question = [
|
||||||
|
inquirer.List(
|
||||||
|
'card_list',
|
||||||
|
message='Choose a card from the list.',
|
||||||
|
choices=blue_staples,
|
||||||
|
carousel=True
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answer = inquirer.prompt(question)
|
||||||
|
card_choice = answer['card_list']
|
||||||
|
elif staple_list_choice == 'Black':
|
||||||
|
staple = 'black'
|
||||||
|
question = [
|
||||||
|
inquirer.List(
|
||||||
|
'card_list',
|
||||||
|
message='Choose a card from the list.',
|
||||||
|
choices=black_staples,
|
||||||
|
carousel=True
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answer = inquirer.prompt(question)
|
||||||
|
card_choice = answer['card_list']
|
||||||
|
df = pd.read_csv(f'csv_files/{staple}_cards.csv')
|
||||||
|
filtered_df = df[df['name'] == card_choice]
|
||||||
|
columns_to_keep = ['name', 'colorIdentity', 'colors', 'manaCost', 'manaValue', 'type', 'keywords', 'power', 'toughness', 'text']
|
||||||
|
filtered_df = filtered_df[columns_to_keep]
|
||||||
|
print(filtered_df)
|
||||||
|
|
||||||
#
|
|
||||||
initial_setup()
|
initial_setup()
|
||||||
|
#make_staples_list()
|
||||||
|
generate_staple_lists()
|
||||||
|
#get_card_info()
|
Loading…
Add table
Add a link
Reference in a new issue