Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将正确的卡添加到基本mtg卡组?_Python_Arraylist_Percentage - Fatal编程技术网

Python 如何将正确的卡添加到基本mtg卡组?

Python 如何将正确的卡添加到基本mtg卡组?,python,arraylist,percentage,Python,Arraylist,Percentage,我正在制作一个python程序,只是为了好玩,它将创建一个基本的魔术:集合牌组。目前的主要测试是它是否可以制作一个合法的mtg牌组,这对初学者来说很好。 问题:到目前为止,构造函数返回[],因为它从未添加任何内容。我想知道如何将一张卡的3组或4组(加上40%的基本焊盘)添加到卡组,使其成为NCARD卡实例的数组,并遵循下面指定的百分比要记住的东西有时一组中没有足够的牌,必须添加其他组中未使用的牌以保留60张牌。此外,牌组中的牌数可能会有所不同,这就是我在描述问题时使用百分比的原因 规格: 在未

我正在制作一个python程序,只是为了好玩,它将创建一个基本的魔术:集合牌组。
目前的主要测试是它是否可以制作一个合法的mtg牌组,这对初学者来说很好。


问题:到目前为止,
构造
函数返回
[]
,因为它从未添加任何内容。我想知道如何将一张卡的3组或4组(加上40%的基本焊盘)添加到
卡组
,使其成为
NCARD
实例的数组,并遵循下面指定的百分比要记住的东西有时一组中没有足够的牌,必须添加其他组中未使用的牌以保留60张牌。此外,牌组中的牌数可能会有所不同,这就是我在描述问题时使用百分比的原因

规格:

  • 在未来,该计划将使用机器学习,但我还没有达到这一点,所以我只是尝试获得15%的低成本生物,15%的高成本生物,15%的低成本非创造法术,15%的高成本非创造法术,40%的基本土地
  • 当然,请随意评论我的百分比,我并不是一个专业的mtg玩家,我希望得到一些免费的建议/有用的批评
  • 最后,如果您发现代码中存在任何其他问题,请不要保持沉默!我会喜欢所有我能得到的帮助
    你的问题是什么?如果您正在查找审阅,并且代码运行正常且已完成,则应该在代码审阅中,而不是在此处。到目前为止,
    构造
    函数返回一个空数组,因为从未向
    添加任何内容。我在问如何将卡片添加到
    牌组中
    ,这样就有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