Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buffs = {}
- #[current lvl, health, attack, defense, magic, crit chance, revive, loot drop]
- buffs[''] = (0, 0, 0, 0, 0, False, False, 0)
- buffs['Potion'] = (3, 1, 0, 0, 0, False, True, 0)
- buffs['Heart'] = (3, 7, 0, 0, 0, False, False, 0.25)
- buffs['Well'] = (3, 0, 0, 0, 2, False, False, 0.15)
- buffs['Mana Potion'] = (3, 0, 0, 0, 5, False, False, 0.2)
- buffs['Shield'] = (3, 0, 4, 0, 0, False, False, 0.25)
- buffs['Beer'] = (3, 0, 5, -2, -2, False, False, 0)
- buffs['Chest'] = (3, 0, 4, 0, 0, False, False, 0.3)
- buffs['Jar of Death'] = (3, 0, 2, 0, 0, True, False, 0.3)
- buffs['Windmill'] = (1, 7, 5, 5, 0, False, False, 0.35)
- buffs['Helmet'] = (1, 0, 8, 0, -2, False, False, 0.35)
- buffs['Gem'] = (1, -5, 0, 0, 6, False, False, 0.35)
- buffs['Meteor'] = (1, 0, 8, -6, 0, False, False, 0)
- buffs['Tavern'] = (1, 5, 2, 2, 2, False, False, 0.35)
- heroes = {}
- #[current lvl, health, attack, defense, magic]
- heroes['Swordsman'] = (3, 10, 4, 1, 2)
- heroes['Valkyrie'] = (3, 12, 4, 3, 4)
- heroes['Rogue'] = (3, 8, 14, 2, 6)
- heroes['Viking'] = (3, 24, 8, 4, 3)
- heroes['Dwarf'] = (3, 16, 6, 10, 1)
- heroes['Assassin'] = (1, 15, 22, 6, 8)
- heroes['Girl'] = (1, 24, 15, 12, 9)
- heroes['Pikeman'] = (1, 26, 19, 10, 7)
- heroes['Necromancer'] = (1, 19, 6, 11, 21)
- monsters = {}
- #[current lvl, health, attack, defense, magic, gold, wood]
- monsters['Goblin'] = (3, 8, 4, 1, 2, 10, 0)
- monsters['Toad'] = (3, 10, 6, 1, 2, 15, 0)
- monsters['Parrot'] = (3, 12, 6, 2, 2, 20, 0)
- monsters['Roo'] = (3, 14, 8, 3, 4, 25, 0)
- monsters['Greedy Bird'] = (3, 40, 4, 4, 4, 35, 0)
- monsters['Arachnid'] = (3, 20, 10, 3, 4, 30, 0)
- monsters['Dingo'] = (3, 20, 10, 4, 8, 0, 10)
- monsters['Scarecrow'] = (3, 24, 14, 2, 8, 0, 15)
- monsters['Dead Fish'] = (3, 1, 1, 1, 1, 1, 0)
- monsters['Marauder'] = (1, 22, 8, 8, 22, 0, 100)
- monsters['Flying Pig'] = (1, 18, 12, 10, 6, 200, 0)
- monsters['Reptile'] = (1, 30, 11, 11, 12, 400, 0)
- monsters['Skeleton'] = (1, 26, 13, 13, 12, 100, 100)
- monsters['Kobold'] = (1, 30, 22, 10, 10, 0, 150)
- monsters['Werewolf'] = (1, 32, 23, 11, 17, 0, 250)
- monsters['Heathen'] = (1, 44, 33, 16, 14, 0, 600)
- results = []
- #(monster buff name, monster buff level, monster name, monster level, hero name, hero level, hero buff name, hero buff level, gold/s, wood/s)
- def solveBattle(mHP, hHP, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = 1):
- #(average rounds, win chance)
- #if the enemy never gets damaged use 1 round and 0 win chance instead of infinite rounds and undetermined win chance
- if hDMG <= 0:
- return 1, 0
- #if you die and cannot revive you lose
- elif hHP <= 0 and not revive:
- return round, 0
- #if the opponent dies and you haven't lost then you win
- elif mHP <= 0:
- return round, 1
- #if you are dead but haven't lost, take a turn to revive. your hp is replaced by your max hp and a round passes
- elif hHP <= 0:
- return solveBattle(mHP, hMaxHP, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
- #otherwise the battle continues, get the average rounds it takes if the branches leading up to this spot occur for each combination of hero crit and monster crit
- else:
- averageRounds0, winChance0 = solveBattle(mHP - hCritDMG, hHP - mCritDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
- averageRounds1, winChance1 = solveBattle(mHP - hDMG, hHP - mDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
- averageRounds2, winChance2 = solveBattle(mHP - hCritDMG, hHP - mDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
- averageRounds3, winChance3 = solveBattle(mHP - hDMG, hHP - mCritDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
- #modify these rounds and chances by the chance of following each branch
- chance0 = (hCritChance) * (mCritChance)
- chance1 = (1 - hCritChance) * (1 - mCritChance)
- chance2 = (hCritChance) * (1 - mCritChance)
- chance3 = (1 - hCritChance) * (mCritChance)
- #pass the average rounds, win chance and loss chance back to the previous branch
- return averageRounds0 * chance0 + averageRounds1 * chance1 + averageRounds2 * chance2 + averageRounds3 * chance3, winChance0 * chance0 + winChance1 * chance1 + winChance2 * chance2 + winChance3 * chance3
- #Iterate over all possible combinations of a monster, that monster's level, a buff for the monster (or no buff indicated by an empty string), a hero, and a buff for the hero using a pentuple for loop.
- for mName in monsters:
- for mLvl in range(1, monsters[mName][0] + 1):
- for hName in heroes:
- for mBuffName in buffs:
- for hBuffName in buffs:
- #get the lists of values from the dictionaries to make easier typing
- m = monsters[mName]
- h = heroes[hName]
- mBuff = buffs[mBuffName]
- hBuff = buffs[hBuffName]
- #get the remaining lvls
- mBuffLvl = mBuff[0]
- hLvl = h[0]
- hBuffLvl = hBuff[0]
- #calculate the lvl multipliers
- mMult = (1 + mLvl) / 2
- mBuffMult = (1 + mBuffLvl) / 2
- hMult = (1 + hLvl) / 2
- hBuffMult = (1 + hBuffLvl) / 2
- #calculate the monster/hero stats after lvl and buff cards are applied
- mHP = m[1] * mMult + mBuff[1] * mBuffMult
- hHP = h[1] * hMult + hBuff[1] * hBuffMult
- mAtk = m[2] * mMult + mBuff[2] * mBuffMult
- hAtk = h[2] * hMult + hBuff[2] * hBuffMult
- mDef = m[3] * mMult + mBuff[3] * mBuffMult
- hDef = h[3] * hMult + hBuff[3] * hBuffMult
- mMag = m[4] * mMult + mBuff[4] * mBuffMult
- hMag = m[4] * hMult + hBuff[4] * hBuffMult
- #calculate the amount of physical and magical damage each card does
- mPhysDmg = max(0, mAtk - hDef)
- hPhysDmg = max(0, hAtk - mDef)
- mMagDmg = max(0, mMag - hMag)
- hMagDmg = max(0, hMag - mMag)
- #calculate the damage done with and without a crit for each card
- mDMG = mPhysDmg + mMagDmg
- mCritDMG = mPhysDmg * 2 + mMagDmg
- hDMG = hPhysDmg + hPhysDmg
- hCritDMG = hPhysDmg * 2 + hMagDmg
- #determine the crit chance
- mCritChance = 0.1 + 0.1 * mBuff[5]
- hCritChance = 0.1 + 0.1 * hBuff[5]
- #determine if the hero may revive
- revive = hBuff[6]
- #calculate the average number of rounds and the chance of winning
- averageRounds, winChance = solveBattle(mHP, hHP, mDMG, hDMG, mCritDMG, hCritDMG, mCritChance, hCritChance, revive, hHP)
- #get the amount of gold and wood the monster drops
- mGold = m[-2]
- mWood = m[-1]
- #calculate the gold/s and wood/s by dividing by the average time taken and multiplying by the chance of winning
- goldRate = mGold / averageRounds * winChance
- woodRate = mWood / averageRounds * winChance
- #stick the results in a list
- results.append((mBuffName, mBuffLvl, mName, mLvl, hName, hLvl, hBuffName, hBuffLvl, goldRate, woodRate))
- def sortKey(combination):
- return combination[-1] + combination[-2]
- results.sort(key=sortKey)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement