def __init__(self, teamName, uID, deckString, classification="NoClassify"): self.deck = deckstrings.Deck() self.classification = classification self.teamName = teamName self.uID = uID self.deckCode = deckString self.deck = deckstrings.Deck().from_deckstring(self.deckCode) self.cardList = [] #For Graphing with TSNE self.x = -1 self.y = -1 for cardTuple in self.deck.get_dbf_id_list(): self.cardList.append(cardTuple[0]) if cardTuple[1] == 2: self.cardList.append(cardTuple[0]) self.ingameClass = card_dict[self.deck.heroes[0]] self.ingameClass = self.ingameClass['cardClass'].lower()
def test_deckstrings(): for deckdata in DECKSTRING_TEST_DATA: # Encode tests deck = deckstrings.Deck() deck.cards = deckdata["cards"] deck.heroes = deckdata["heroes"] deck.format = deckdata["format"] assert deck.as_deckstring == deckdata["deckstring"] # Decode tests deck = deckstrings.Deck.from_deckstring(deckdata["deckstring"]) assert _decksorted(deck.cards) == _decksorted(deckdata["cards"]) assert deck.heroes == deckdata["heroes"] assert deck.format == deckdata["format"]
def test_empty_deckstring(): deck = deckstrings.Deck() deck.heroes = [0] assert deck.as_deckstring == "AAEAAQAAAAA="
def __init__(self, code): self.code = code self.deck = deckstrings.Deck().from_deckstring(code)
def generate_deck(request): hero_id = {"priest": 813, "warrior": 7, "rogue": 930, "mage": 637, "shaman": 1066, "paladin": 671, "hunter": 31, "warlock": 893, "druid": 274} gen_start_time = time.clock() desired_class = request.GET.get('hero') if desired_class == "random": desired_class = random.choice(list(hero_id.keys())) deck_format = request.GET.get('format') if deck_format == "standard": deck_format = FormatType.FT_STANDARD else: deck_format = FormatType.FT_WILD print("Getting collection from session") full_collection = request.session.get("full_collection") class_collection = get_filtered_collection(full_collection, desired_class) standard_sets = get_standard_sets() rarity_colors = { "Free": "#000", "Common": "#000", "Rare": "#0070dd", "Epic": "#a335ee", "Legendary": "#ff8000" } filtered_collection = [] for card in class_collection: card_object = Card.objects.get(name__exact=card[0]) # Only add cards from standard format if standard format is chosen if (deck_format == FormatType.FT_STANDARD and card_object.set not in standard_sets): pass else: # Add two cards if user owns more than two copies card_amount = card[1] if card_amount >= 2: filtered_collection += [ [card_object.name, card_object.img_url, card_amount, card_object.dbfId, rarity_colors[card_object.rarity], card_object.cost] ] * 2 else: filtered_collection.append([card_object.name, card_object.img_url, card_amount, card_object.dbfId, rarity_colors[card_object.rarity], card_object.cost]) # Create a deck by picking 30 random cards random_deck = random.sample(filtered_collection, 30) final_deck = [] # Merge duplicates for card in random_deck: name = card[0] rarity = card[4] cost = card[5] if card == random_deck[0]: final_deck.append((name, 1, rarity, cost)) elif card in final_deck: final_deck[final_deck.index(card)][1] = 2 else: final_deck.append((name, 1, rarity, cost)) # Sort cards by mana cost sorted_deck = sorted(final_deck, key=lambda x: x[3]) # Creates the deckstring using the hearthstone python module db_deck = create_dbfid_deck(random_deck) deck = deckstrings.Deck() deck.cards = db_deck deck.heroes = [hero_id[desired_class]] deck.format = deck_format deckstring = deck.as_deckstring gen_end_time = time.clock() print("Total gen time", gen_end_time - gen_start_time) context = { "cards": sorted_deck, "class": desired_class.title(), "deckstring": deckstring, } return render(request, "deck.html", context)