def sortByCost(kingdom, i): print(kingdom) highestCost=0 highestCostCard=i for x in xrange(i,len(kingdom)): if cards.cost_by_name(kingdom[x]) >= highestCost: highestCost = cards.cost_by_name(kingdom[x]) highestCostCard=x highCard = kingdom.pop(highestCostCard) kingdom.insert(i,highCard) i=i+1 if(i<len(kingdom)-1): sortByCost(kingdom,i) return kingdom
def create_buylist(self): kingdom = get_kingdoms(self) #remove copper, silver, gold, curse, and province- already accounted for in template strategy del kingdom[0] del kingdom[0] del kingdom[0] del kingdom[0] del kingdom[2] self.kingdom = kingdom # random kingdom placement # random.shuffle(kingdom); # initial buylist based on cost self.kingdom.sort(key=lambda c: -cards.cost_by_name(c)) #sortByCost(kingdom,0) print self.kingdom self.adaptiveBuyFile = "adaptiveBuylist.buys" + str(os.getpid()) #just random for now target = open (self.adaptiveBuyFile, 'w') for i, k in enumerate(self.kingdom): target.write("%s %d\n" % (k, 1)) if i == 0: target.write("Province 99\n") target.write("Gold 99\n") elif i == 5 or (len(kingdom) < 6 and i == len(kingdom)-1): target.write("Silver 99\n") target.close() return load_buylist(self.adaptiveBuyFile)