Advertisement
Guest User

Plains Of War Solution

a guest
Dec 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.94 KB | None | 0 0
  1. buffs = {}
  2. #[current lvl, health, attack, defense, magic, crit chance, revive, loot drop]
  3.  
  4. buffs[''] = (0, 0, 0, 0, 0, False, False, 0)
  5. buffs['Potion'] = (3, 1, 0, 0, 0, False, True, 0)
  6. buffs['Heart'] = (3, 7, 0, 0, 0, False, False, 0.25)
  7. buffs['Well'] = (3, 0, 0, 0, 2, False, False, 0.15)
  8. buffs['Mana Potion'] = (3, 0, 0, 0, 5, False, False, 0.2)
  9. buffs['Shield'] = (3, 0, 4, 0, 0, False, False, 0.25)
  10. buffs['Beer'] = (3, 0, 5, -2, -2, False, False, 0)
  11. buffs['Chest'] = (3, 0, 4, 0, 0, False, False, 0.3)
  12. buffs['Jar of Death'] = (3, 0, 2, 0, 0, True, False, 0.3)
  13. buffs['Windmill'] = (1, 7, 5, 5, 0, False, False, 0.35)
  14. buffs['Helmet'] = (1, 0, 8, 0, -2, False, False, 0.35)
  15. buffs['Gem'] = (1, -5, 0, 0, 6, False, False, 0.35)
  16. buffs['Meteor'] = (1, 0, 8, -6, 0, False, False, 0)
  17. buffs['Tavern'] = (1, 5, 2, 2, 2, False, False, 0.35)
  18.  
  19. heroes = {}
  20. #[current lvl, health, attack, defense, magic]
  21.  
  22. heroes['Swordsman'] = (3, 10, 4, 1, 2)
  23. heroes['Valkyrie'] = (3, 12, 4, 3, 4)
  24. heroes['Rogue'] = (3, 8, 14, 2, 6)
  25. heroes['Viking'] = (3, 24, 8, 4, 3)
  26. heroes['Dwarf'] = (3, 16, 6, 10, 1)
  27. heroes['Assassin'] = (1, 15, 22, 6, 8)
  28. heroes['Girl'] = (1, 24, 15, 12, 9)
  29. heroes['Pikeman'] = (1, 26, 19, 10, 7)
  30. heroes['Necromancer'] = (1, 19, 6, 11, 21)
  31.  
  32. monsters = {}
  33. #[current lvl, health, attack, defense, magic, gold, wood]
  34.  
  35. monsters['Goblin'] = (3, 8, 4, 1, 2, 10, 0)
  36. monsters['Toad'] = (3, 10, 6, 1, 2, 15, 0)
  37. monsters['Parrot'] = (3, 12, 6, 2, 2, 20, 0)
  38. monsters['Roo'] = (3, 14, 8, 3, 4, 25, 0)
  39. monsters['Greedy Bird'] = (3, 40, 4, 4, 4, 35, 0)
  40. monsters['Arachnid'] = (3, 20, 10, 3, 4, 30, 0)
  41. monsters['Dingo'] = (3, 20, 10, 4, 8, 0, 10)
  42. monsters['Scarecrow'] = (3, 24, 14, 2, 8, 0, 15)
  43. monsters['Dead Fish'] = (3, 1, 1, 1, 1, 1, 0)
  44. monsters['Marauder'] = (1, 22, 8, 8, 22, 0, 100)
  45. monsters['Flying Pig'] = (1, 18, 12, 10, 6, 200, 0)
  46. monsters['Reptile'] = (1, 30, 11, 11, 12, 400, 0)
  47. monsters['Skeleton'] = (1, 26, 13, 13, 12, 100, 100)
  48. monsters['Kobold'] = (1, 30, 22, 10, 10, 0, 150)
  49. monsters['Werewolf'] = (1, 32, 23, 11, 17, 0, 250)
  50. monsters['Heathen'] = (1, 44, 33, 16, 14, 0, 600)
  51.  
  52. results = []
  53. #(monster buff name, monster buff level, monster name, monster level, hero name, hero level, hero buff name, hero buff level, gold/s, wood/s)
  54.  
  55. def solveBattle(mHP, hHP, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = 1):
  56.     #(average rounds, win chance)
  57.  
  58.     #if the enemy never gets damaged use 1 round and 0 win chance instead of infinite rounds and undetermined win chance
  59.     if hDMG <= 0:
  60.         return 1, 0
  61.  
  62.     #if you die and cannot revive you lose
  63.     elif hHP <= 0 and not revive:
  64.         return round, 0
  65.    
  66.     #if the opponent dies and you haven't lost then you win
  67.     elif mHP <= 0:
  68.         return round, 1
  69.  
  70.     #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
  71.     elif hHP <= 0:
  72.         return solveBattle(mHP, hMaxHP, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
  73.  
  74.     #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
  75.     else:
  76.         averageRounds0, winChance0 = solveBattle(mHP - hCritDMG, hHP - mCritDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
  77.         averageRounds1, winChance1 = solveBattle(mHP - hDMG, hHP - mDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
  78.         averageRounds2, winChance2 = solveBattle(mHP - hCritDMG, hHP - mDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
  79.         averageRounds3, winChance3 = solveBattle(mHP - hDMG, hHP - mCritDMG, mDMG, hDMG, mCritDMG, hCritDmg, mCritChance, hCritChance, revive, hMaxHP, round = round + 1)
  80.  
  81.         #modify these rounds and chances by the chance of following each branch
  82.         chance0 = (hCritChance) * (mCritChance)
  83.         chance1 = (1 - hCritChance) * (1 - mCritChance)
  84.         chance2 = (hCritChance) * (1 - mCritChance)
  85.         chance3 = (1 - hCritChance) * (mCritChance)
  86.  
  87.         #pass the average rounds, win chance and loss chance back to the previous branch
  88.         return averageRounds0 * chance0 + averageRounds1 * chance1 + averageRounds2 * chance2 + averageRounds3 * chance3, winChance0 * chance0 + winChance1 * chance1 + winChance2 * chance2 + winChance3 * chance3
  89.  
  90. #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.
  91. for mName in monsters:
  92.     for mLvl in range(1, monsters[mName][0] + 1):  
  93.         for hName in heroes:
  94.             for mBuffName in buffs:
  95.                 for hBuffName in buffs:
  96.  
  97.                     #get the lists of values from the dictionaries to make easier typing
  98.                     m = monsters[mName]
  99.                     h = heroes[hName]
  100.                     mBuff = buffs[mBuffName]
  101.                     hBuff = buffs[hBuffName]
  102.                    
  103.                     #get the remaining lvls
  104.                     mBuffLvl = mBuff[0]
  105.                     hLvl = h[0]
  106.                     hBuffLvl = hBuff[0]
  107.  
  108.                     #calculate the lvl multipliers
  109.                     mMult = (1 + mLvl) / 2
  110.                     mBuffMult = (1 + mBuffLvl) / 2
  111.                     hMult = (1 + hLvl) / 2
  112.                     hBuffMult = (1 + hBuffLvl) / 2
  113.                    
  114.                     #calculate the monster/hero stats after lvl and buff cards are applied
  115.                     mHP = m[1] * mMult + mBuff[1] * mBuffMult
  116.                     hHP = h[1] * hMult + hBuff[1] * hBuffMult
  117.                     mAtk = m[2] * mMult + mBuff[2] * mBuffMult
  118.                     hAtk = h[2] * hMult + hBuff[2] * hBuffMult      
  119.                     mDef = m[3] * mMult + mBuff[3] * mBuffMult
  120.                     hDef = h[3] * hMult + hBuff[3] * hBuffMult
  121.                     mMag = m[4] * mMult + mBuff[4] * mBuffMult
  122.                     hMag = m[4] * hMult + hBuff[4] * hBuffMult
  123.  
  124.                     #calculate the amount of physical and magical damage each card does
  125.                     mPhysDmg = max(0, mAtk - hDef)
  126.                     hPhysDmg = max(0, hAtk - mDef)              
  127.                     mMagDmg = max(0, mMag - hMag)
  128.                     hMagDmg = max(0, hMag - mMag)
  129.                    
  130.                     #calculate the damage done with and without a crit for each card
  131.                     mDMG = mPhysDmg + mMagDmg
  132.                     mCritDMG = mPhysDmg * 2 + mMagDmg
  133.                     hDMG = hPhysDmg + hPhysDmg
  134.                     hCritDMG = hPhysDmg * 2 + hMagDmg
  135.  
  136.                     #determine the crit chance
  137.                     mCritChance = 0.1 + 0.1 * mBuff[5]
  138.                     hCritChance = 0.1 + 0.1 * hBuff[5]
  139.                    
  140.                     #determine if the hero may revive
  141.                     revive = hBuff[6]
  142.                    
  143.                     #calculate the average number of rounds and the chance of winning
  144.                     averageRounds, winChance = solveBattle(mHP, hHP, mDMG, hDMG, mCritDMG, hCritDMG, mCritChance, hCritChance, revive, hHP)
  145.  
  146.                     #get the amount of gold and wood the monster drops
  147.                     mGold = m[-2]
  148.                     mWood = m[-1]
  149.  
  150.                     #calculate the gold/s and wood/s by dividing by the average time taken and multiplying by the chance of winning
  151.                     goldRate = mGold / averageRounds * winChance
  152.                     woodRate = mWood / averageRounds * winChance
  153.  
  154.                     #stick the results in a list
  155.                     results.append((mBuffName, mBuffLvl, mName, mLvl, hName, hLvl, hBuffName, hBuffLvl, goldRate, woodRate))
  156.            
  157. def sortKey(combination):
  158.     return combination[-1] + combination[-2]        
  159. results.sort(key=sortKey)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement