我正在制作一个python程序,只是为了好玩,它将创建一个基本的 Magic:the Gathering 套牌。
现在的主要测试是它是否可以制作合法的mtg套牌这对初学者来说没问题。
'''a mtg deck designer'''
from collections import Counter
import mtgsdk.card as card
colors = ['black']
#colors = input("What are your colors?").split(', ')
ncolors = len(colors)
ncards = 60
#ncards = int(input("how many cards?"))
mytype = 'Vampire'
#mytype = input('what creature type should the deck be based on?')
def myrange(l):
'''create an assignable array with l pieces'''
result = []
i = 0
while i != l:
result.append(i)
i += 1
return result
def add(grp, queryresult):
'''add queryresult[0] to grp'''
try:
grp += [queryresult[0]]
except IndexError:
'''help!'''
def figure_out_basic_land(clr):
'''figure out the basic land name of a given color'''
if clr.lower() == 'colorless':
return 'Waste'
if clr.lower() == 'white':
return 'Plains'
if clr.lower() == 'blue':
return 'Island'
if clr.lower() == 'black':
return 'Swamp'
if clr.lower() == 'red':
return 'Mountain'
if clr.lower() == 'green':
return 'Forest'
return 0
def d1():
'''first portion of debugging message'''
print('getting cards', end='...')
def d2():
'''second portion of debugging message'''
print('done.')
def construct():
'''the actual deck-constructing function'''
#define groups
basiclands = []
lowcostcreatures = []
highcostcreatures = []
lowcostspells = []
highcostspells = []
#assign cards to groups
for i in colors:
d1()
add(basiclands, card.Card.where(types='land').where(supertypes='Basic').where(name=figure_out_basic_land(i)).all())
d2()
d1()
add(lowcostcreatures, card.Card.where(types='creature').where(subtypes=mytype).where(colors=i).where(cmc='1').all())
add(lowcostcreatures, card.Card.where(types='creature').where(subtypes=mytype).where(colors=i).where(cmc='2').all())
d2()
d1()
add(lowcostspells, card.Card.where(types='instant').where(text=mytype).where(colors=i).where(cmc='1').all())
add(lowcostspells, card.Card.where(types='sorcery').where(text=mytype).where(colors=i).where(cmc='2').all())
d2()
d1()
add(highcostcreatures, card.Card.where(types='creature').where(subtypes=mytype).where(colors=i).where(cmc='3').where(rarity='rare').all())
add(highcostcreatures, card.Card.where(types='creature').where(subtypes=mytype).where(colors=i).where(cmc='4').where(rarity='rare').all())
d2()
d1()
add(highcostspells, card.Card.where(types='instant').where(subtypes=mytype).where(colors=i).where(cmc='3').where(rarity='rare').all())
add(highcostspells, card.Card.where(types='sorcery').where(subtypes=mytype).where(colors=i).where(cmc='4').where(rarity='rare').all())
d2()
print()
#put results into card suggestion pool
cards = [lowcostcreatures,highcostcreatures,lowcostspells,highcostspells,basiclands]
#define deck
deck = []
#figure out how to get the cards into the deck in sets of 4, with almost correct numbers of each group (30% lowcost,30% highcost,40% land)
if len(deck) > (ncards):
while en(deck) > (ncards):
del deck[-1]
if len(deck) != ncards:
print('warning: card num = {0}'.format(len(deck)))
return deck
问题:到目前为止,construct
函数返回[]
,因为没有添加任何内容。我想知道如何将卡片的3或4组(加上40%基本区域)添加到deck
,以便它是一个ncards
Card
个实例的数组,按照百分比以下指定。 需要记住的东西!有时组中的卡片数量不足,必须添加其他组中未使用的卡片以保留60张卡片。此外,卡片中卡片的数量可能会有所不同,这就是我在问题描述中使用百分比的原因。
规格: