예제 #1
0
def decode(deck):
    codes = list(LoRDeck.from_deckcode(deck))
    cards = []
    for code in codes:
        for i in range(int(code[0])):
            cards.append(code[2:])
    return " ".join(cards)
예제 #2
0
def deck_to_image(deckcode):
    unit_images = [0]
    champion_images = [0]
    spell_images = [0]
    deck = LoRDeck.from_deckcode(deckcode)
    newdeck = [
        Card(CardCode=card_string.split(':')[1],
             count=card_string.split(':')[0]) for card_string in deck
    ]
    newdeck.sort(key=lambda x: x.cost, reverse=False)
    for card in newdeck:
        if card.cardType == 'Unit':
            if card.isChampion:
                champion_images[0] += card.count
                champion_images.append(make_card_image(card))
            else:
                unit_images[0] += card.count
                unit_images.append(make_card_image(card))
        else:
            spell_images[0] += card.count
            spell_images.append(make_card_image(card))
        #im.save(card.cardCode + '.png', 'png')

    final = make_final_image(champion_images, unit_images, spell_images)
    return final
예제 #3
0
def get_cards_infos_from_code(code):
    deck = LoRDeck.from_deckcode(code)
    cards = []
    for c in deck.cards:
        qte, code = str(c).split(":")
        cards.append((qte, cards_infos[code]))
    return cards
예제 #4
0
def deck_select(deck_code):
    deck = LoRDeck.from_deckcode(deck_code)
    #iterate through each card of the deck
    df = []
    for card in deck.cards:
        d = {'cardCode': card.card_code, 'count': card.count}
        df.append(d)
    current_deck = pd.DataFrame(df)
    current_deck = current_deck.join(all_cards.set_index('cardCode'),
                                     on='cardCode',
                                     how='left')
    current_deck = current_deck[[
        'name', 'count', 'cost', 'type', 'supertype', 'spellSpeed'
    ]]
    current_deck.sort_values(by=['cost'], inplace=True)
    deck_table = current_deck.to_html(classes='data', header="true")
    round_num = 1
    mana = 1
    spellmana = 0
    all_checked = 'checked'
    return render_template('deck_test.html',
                           deck_table=deck_table,
                           round_num=round_num,
                           mana=mana,
                           spellmana=spellmana,
                           all_checked=all_checked,
                           deck_code=deck_code)
예제 #5
0
def GetCardCount(deck):
    unpackedDeck = LoRDeck.from_deckcode(deck)
    cardCount = 0

    for card in list(unpackedDeck):
        cardCount += int(card[0])
    return cardCount
예제 #6
0
def deck_filter(deck_code):
    round_num = request.args['turn']
    mana = request.args['mana']
    spellmana = request.args['spellmana']
    card_type = request.args['card_type']
    #iterate through each card of the deck
    deck = LoRDeck.from_deckcode(deck_code)
    df = []
    for card in deck.cards:
        d = {'cardCode': card.card_code, 'count': card.count}
        df.append(d)
    current_deck = pd.DataFrame(df)
    current_deck = current_deck.join(all_cards.set_index('cardCode'),
                                     on='cardCode',
                                     how='left')
    current_deck = current_deck[[
        'name', 'count', 'cost', 'type', 'supertype', 'spellSpeed'
    ]]
    current_deck.sort_values(by=['cost'], inplace=True)
    opp_deck = current_deck
    if card_type == 'all_cards':
        all_checked = 'checked'
        fast_checked = ''
        burst_checked = ''
        spells = opp_deck.query(
            'type=="Spell" and cost<={mana}+{spellmana}'.format(
                mana=mana, spellmana=spellmana))
        units = opp_deck.query(
            'type=="Unit" and cost<={mana}'.format(mana=mana))
        all_possible = pd.concat([spells, units])
    elif card_type == 'fast':
        all_checked = ''
        fast_checked = 'checked'
        burst_checked = ''
        spells = opp_deck.query(
            'type=="Spell" and spellSpeed!="Slow" and cost<={mana}+{spellmana}'
            .format(mana=mana, spellmana=spellmana))
        all_possible = spells
    elif card_type == 'burst':
        all_checked = ''
        fast_checked = ''
        burst_checked = 'checked'
        spells = opp_deck.query(
            'type=="Spell" and spellSpeed=="Burst" and cost<={mana}+{spellmana}'
            .format(mana=mana, spellmana=spellmana))
        all_possible = spells
    deck_table = all_possible.to_html(
        classes='table table-striped p-3 my-3 border table-hover',
        header="true")
    return render_template('deck_test.html',
                           deck_table=deck_table,
                           round_num=round_num,
                           mana=mana,
                           spellmana=spellmana,
                           card_type=card_type,
                           all_checked=all_checked,
                           fast_checked=fast_checked,
                           burst_checked=burst_checked,
                           deck_code=deck_code)
예제 #7
0
파일: LoR_Game.py 프로젝트: dunkean/LoR_NN
 def generate_deck(self, code):
     deck_list = LoRDeck.from_deckcode(code)
     deck = []
     for cnc in deck_list.cards:
         for i in range(cnc.count):
             cd = CardDesc()
             cd.from_json(cnc.card_code)
             deck.append(cd)
     return deck
예제 #8
0
 def get_deck(self, deck_code):
     deck = []
     lor_deck = LoRDeck.from_deckcode(deck_code)
     for c in list(lor_deck):
         [nb, code] = c.split(":")
         for _ in range(int(nb)):
             card_desc = CardDesc()
             card_desc.from_json(code)
             deck.append(card_desc)
     return deck
예제 #9
0
    def add_deck_fields(self, deck_code):
        deck_from_code = LoRDeck.from_deckcode(deck_code)

        deck_cards = [DeckCard.get_or_create(ccac) for ccac in list(deck_from_code)]
        regions = list(set(deck_card.card.region for deck_card in deck_cards))
        champions = [deck_card.card for deck_card in deck_cards if deck_card.card.supertype == "Champion"]

        self.regions.add(*regions)
        self.deck_cards.add(*deck_cards)
        self.champions.add(*champions)
예제 #10
0
def deckCompiler(deckcode):
    outputmsg = f">>> "
    data = card_identify.cards_data
    target = LoRDeck.from_deckcode(deckcode)
    card_list = list(target)
    for card in card_list:
        subject = cardParser(card)
        chunkInfo = f"**{subject['amount']} lá **- {(data[subject['cardCode']])['Name']}"
        print(chunkInfo)
        outputmsg += f"{chunkInfo}\n"
    return generateEmbed(outputmsg, deckcode)
def buildFromCode(code):
    data = get_dataframe()
    deck = LoRDeck.from_deckcode(code)

    # codes = [(card.card_code, card.count) for card in deck.cards]
    newDeck = pd.DataFrame(columns=data.columns)

    for i, card in enumerate(deck.cards):
        row = data.loc[data['cardCode'] == card.card_code]
        newDeck = newDeck.append(row, ignore_index=True)
        newDeck.loc[i, 'count'] = int(card.count)
    newDeck['count'] = newDeck['count'].astype(int)
    return newDeck
예제 #12
0
def handleData(data):
    global playerDeckCode
    global playerDeck
    if data['GameState'] == 'InProgress':
        req = requests.get('http://127.0.0.1:21337/static-decklist')
        deckJson = req.json()
        deckCode = deckJson['DeckCode']
        # get player deck
        if (not playerDeck) or (playerDeckCode != deckCode):
            playerDeckCode = deckCode
            deck = LoRDeck.from_deckcode(deckCode)
            for cardStr in deck:
                card = CardCodeAndCount.from_card_string(cardStr)
                playerDeck[card.card_code] = card.count

        rectangles = data['Rectangles']
        for rect in rectangles:
            if not rect['LocalPlayer']:
                continue

            if rect['CardID'] in knownIDs:
                continue
            knownIDs.append(rect['CardID'])

            cardCode = rect['CardCode']
            if cardCode not in playerDeck:
                continue

            if playerDeck[cardCode] < 1:
                continue

            playerDeck[cardCode] -= 1

        playerName = data['PlayerName']
        printDeck(playerName)

    else:
        # for windows
        if name == 'nt':
            _ = system('cls')

        # for mac and linux(here, os.name is 'posix')
        else:
            _ = system('clear')

        print('Start a game to see your deck!')

        playerDeck = {}
        playerDeckCode = ""
def sv_home():
	avoidTables = ['set', 'API']

	# get dataframe of db
	cnx = sqlite3.connect("card_data/stattracker.db")
	df = pd.read_sql_query("select name from sqlite_master where type = 'table'", cnx)

	# extract deck names
	deckNames = []
	for index, row in df.iterrows():
		if row['name'] not in avoidTables:
			deckNames.append(row['name'])
	
	framesToConcat = []
	for i in range(len(deckNames)):

		# get stats for deck
		unnamedDf = pd.read_sql_query("select * from " + deckNames[i], cnx)

		# add deck name to data
		# https://stackoverflow.com/a/53236864/13157180
		nameCol = []
		for j in range(len(unnamedDf.index)):
			nameCol.append(deckNames[i])
		nameDf = pd.DataFrame(nameCol, columns=['Deck Name'])
		unnamedDf.append(nameDf)

		# add frames to array
		framesToConcat.append(pd.concat([unnamedDf, nameDf], axis=1))

	# make df out of array
	deckData = pd.concat(framesToConcat)
	deckData.reset_index(drop=True, inplace=True) # reset indexes

	# make df of cards in each deck
	CardDataCardCode = []
	CardDataDeckCode = []
	for deckName in deckNames:
		try:
			deck = LoRDeck.from_deckcode(deckName)
			for card in deck.cards:
				CardDataCardCode.append(str(card)[2:]) # trim quantity
				CardDataDeckCode.append(deckName)
		except ValueError:
			# Invalid deck code, skip
			pass
	cardData = pd.DataFrame(data={'Deck Name':CardDataDeckCode, 'Card Code':CardDataCardCode})

	return render_template('statsviewer/index.html', deckData=deckData.to_json(), cardData=cardData.to_json())
예제 #14
0
def AssignStaticValues():
    global playerName, opponentName, screenDimensions, activeDeck, cardsInDeck, expWins, expLosses, regions
    playerName, opponentName, screenDimensions = GetGameInfo()
    activeDeck, cardsInDeck = GetActiveDeck()
    regions = []
    deck = LoRDeck.from_deckcode(activeDeck)
    for card in list(deck):
        if card[4:6] == "DE" and "Demacia" not in regions:
            regions.append("Demacia")
        elif card[4:6] == "FR" and "Freljord" not in regions:
            regions.append("Freljord")
        elif card[4:6] == "IO" and "Ionia" not in regions:
            regions.append("Ionia")
        elif card[4:6] == "NX" and "Noxus" not in regions:
            regions.append("Noxus")
        elif card[4:6] == "PZ" and "Piltover & Zaun" not in regions:
            regions.append("Piltover & Zaun")
        elif card[4:6] == "SI" and "Shadow Isles" not in regions:
            regions.append("Shadow Isles")
    regions = sorted(regions)
    expWins, expLosses = GetExpeditionInfo()
예제 #15
0
 def fromUnfinishedDeck(deckCode: str,
                        genres: list = [basicCheck],
                        regions=None):
     cards = []
     if regions == None: tempRegion = set()
     for i in LoRDeck.from_deckcode(deckCode).cards:
         cards += [(i.count, i.card_code)]
         if regions == None:
             temp = i.faction
             if temp == "IO": temp = "Ionia"
             if temp == "SI": temp = "Shadow Isles"
             if temp == "DE": temp = "Demacia"
             if temp == "FR": temp = "Freljord"
             if temp == "NX": temp = "Noxus"
             if temp == "PZ": temp = "Piltover & Zaun"
             tempRegion |= {temp}
     if regions == None: regions = tempRegion
     rDeck = Deck(*regions, *genres)
     for i in cards:
         rDeck.cardOverride(i[1], i[0])
     return rDeck
예제 #16
0
 def __init__(self, code):
     deck = LoRDeck.from_deckcode(code)
     cards = []
     self.champions = []
     self.regions = []
     self.cards_by_region = {}
     for cardcode in deck:
         card = CardCodeAndCount.from_card_string(cardcode)
         for card_data in set_data:
             if card_data["cardCode"] == cardcode[2:]:
                 if card_data["rarity"] == "Champion":
                     self.champions.append(card_data["name"])
                 if card_data["region"] not in self.regions:
                     self.regions.append(card_data["region"])
                     self.cards_by_region[card_data["region"]] = []
                 cards.append(Card(card.count, card_data))
                 self.cards_by_region[card_data["region"]].append(
                     Card(card.count, card_data))
     self.cards = sorted(cards, key=lambda x: x.data["cost"])
     for k, v in self.cards_by_region.items():
         self.cards_by_region[k] = sorted(v, key=lambda x: x.data["cost"])
예제 #17
0
# import neccessary libraries
import pandas as pd
from add_cards import all_cards
from lor_deckcodes import LoRDeck, CardCodeAndCount
#import seleniumtest

#load all decks
all_decks = pd.read_csv('results.csv')

#create list of all deck codes
all_deck_codes = all_decks['deck_code'].to_list()

#itirate through deck codes
deck_details = []
for deck_code in all_deck_codes:
    deck = LoRDeck.from_deckcode(deck_code)
    #iterate through each card of the deck
    df = []
    for card in deck.cards:
        d = {'cardCode': card.card_code, 'count': card.count}
        df.append(d)
    current_deck = pd.DataFrame(df)
    current_deck = current_deck.join(all_cards.set_index('cardCode'),
                                     on='cardCode',
                                     how='left')
    deck_champions = current_deck.loc[
        (current_deck['supertype'] == 'Champion')
        & (current_deck['type'] == 'Unit')].drop_duplicates()
    deck_champions = deck_champions['name'].drop_duplicates()
    deck_regions = current_deck['region'].drop_duplicates()
    #find region 1
예제 #18
0
파일: helpers.py 프로젝트: rachd/expLoRApi
def get_card_array(deck):
    codes = list(LoRDeck.from_deckcode(deck))
    cards = []
    for code in codes:
        cards.append(code[2:])
    return cards
예제 #19
0
from django.shortcuts import render, HttpResponse, redirect
from lor_deckcodes import LoRDeck, CardCodeAndCount
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
import json
import os

script_dir = os.path.dirname(__file__)
file_path = os.path.join(script_dir, 'static/returning_app/js/set1-en_us.json')
with open(file_path, 'r') as f:
    data = json.load(f)

deck = LoRDeck.from_deckcode('CEBAGAIDBMKS6BYBAUGBEFIXFAXC6AIEAECQIKRLGEBACAIDFIAQCBID')


def index(request):
    page = request.GET.get('page', 1)
    paginator = Paginator(data, 42)
    try:
        cards = paginator.page(page)
    except PageNotAnInteger:
        cards = paginator.page(1)
    except EmptyPage:
        cards = paginator.page(paginator.num_pages)

    return render(request, "returning_app/index.html", { 'cards' : cards} )

예제 #20
0
from lor_deckcodes import LoRDeck
from postgres import Postgres
import pandas as pd
import sys
from scipy.stats import hypergeom
import numpy as np

# Decoding
deck = LoRDeck.from_deckcode(sys.argv[1])

# list all cards with card format 3:01SI001
print(list(deck))


def sql_output_as_dataframe(output) -> list:
    return [
        pd.DataFrame(result[0], columns=[x[0] for x in result[1]]) for result in output
    ]


with Postgres("dev/guillaumelegoy") as conn:
    deck_info = []
    card_codes = []
    card_count = {}

    for card in list(deck):
        card_codes.append(card[-7:])
        card_count[card[-7:]] = card[:1]

    card_count = pd.DataFrame.from_dict(card_count, orient="index").reset_index()