Python 如何将正确的卡添加到基本mtg卡组?
我正在制作一个python程序,只是为了好玩,它将创建一个基本的魔术:集合牌组。Python 如何将正确的卡添加到基本mtg卡组?,python,arraylist,percentage,Python,Arraylist,Percentage,我正在制作一个python程序,只是为了好玩,它将创建一个基本的魔术:集合牌组。目前的主要测试是它是否可以制作一个合法的mtg牌组,这对初学者来说很好。 问题:到目前为止,构造函数返回[],因为它从未添加任何内容。我想知道如何将一张卡的3组或4组(加上40%的基本焊盘)添加到卡组,使其成为NCARD卡实例的数组,并遵循下面指定的百分比要记住的东西有时一组中没有足够的牌,必须添加其他组中未使用的牌以保留60张牌。此外,牌组中的牌数可能会有所不同,这就是我在描述问题时使用百分比的原因 规格: 在未
目前的主要测试是它是否可以制作一个合法的mtg牌组,这对初学者来说很好。
问题:到目前为止,
构造
函数返回[]
,因为它从未添加任何内容。我想知道如何将一张卡的3组或4组(加上40%的基本焊盘)添加到卡组
,使其成为NCARD
卡
实例的数组,并遵循下面指定的百分比要记住的东西有时一组中没有足够的牌,必须添加其他组中未使用的牌以保留60张牌。此外,牌组中的牌数可能会有所不同,这就是我在描述问题时使用百分比的原因
规格:
你的问题是什么?如果您正在查找审阅,并且代码运行正常且已完成,则应该在代码审阅中,而不是在此处。到目前为止,
构造
函数返回一个空数组,因为从未向组
添加任何内容。我在问如何将卡片添加到牌组中
,这样就有15%的低成本生物,15%的高成本生物,等等。希望在每张卡片的3到4张中,我才意识到我甚至没有陈述这个问题!你的问题是什么?如果您正在查找审阅,并且代码运行正常且已完成,则应该在代码审阅中,而不是在此处。到目前为止,构造
函数返回一个空数组,因为从未向组
添加任何内容。我在问如何将卡片添加到牌组中
,这样就有15%的低成本生物,15%的高成本生物,等等。希望在每张卡片的3到4张中,我才意识到我甚至没有陈述这个问题!
'''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