Polytopia Battle Calculator
(by FrothFrenzy)Result:
So how does the calculator work?
The calculator uses the same code posted by the developer on the game wikia forums some time ago. You can find a link to this thread on the bottom of this FAQ. Here is the simplified code:
accelerator = 4.5
attackForce = attacker.attack * (attacker.health / attacker.maxHealth)
defenseForce = defender.defense * (defender.health / defender.maxHealth)
totalDamage = attackForce + defenseForce
attackResult = round((attackForce / totalDamage) * attacker.attack * accelerator)
defenseResult = round((defenseForce / totalDamage) * defender.defense * accelerator)
As for the actual usage - you simply input all of the fields, click the Calculate! button, and your battle result will pop up at the bottom. All of the fields are required because every variable affects the result. You can use drop-down unit templates to fill the fields quicker, although these can also be useful if you don't remember the unit stats. Additional details such as unit veterancy and variable ship HP will appear next to the template box once you have selected a relevant unit.
Defender's current HP is automatically updated if the defender survives, so you can keep pressing Calculate! repeatedly until it is destroyed. This is useful for quickly calculating how many units of the same power are needed to take down a stronger unit, and you don't need to manually change the defender's current HP every time you want to perform an attack with a different unit.
If checkboxes appear too small on your screen, you can instead click or tap on the text pertaining to the checkbox to activate it. This applies both to veterancy status and defense/wall bonus checkboxes.
Also note that you can access a history of all the recent battles you performed in the current session. Tap or click three times on any text that appears below Result: to activate the history. Likewise, you can turn it off by tapping or clicking three times in that same area. The history showcases 10 entries by default. If for some reason you would like to keep a bigger (or smaller) history for the current session, fill all the fields so there are no invalid values, set the attack value to 123, set the defense value to the number of entries you want to keep and then press the Calculate! button. A message will appear as a confirmation. All entries are formatted as Attacker (stats) - Defender (stats|D/W), where stats are shown in the same order as they appear on the calculator, and D/W representing the defense/wall bonus for the defender.
Where does the defense bonus come in?
The defenceForce variable is increased by a factor of 1.5 if the defender is on a tile that provides a standard defense bonus (see below). If the defender is behind a wall, it's increased by a factor of 4. This corresponds to a 50% or 300% increase in defense, respectively. Because only the defenceForce variable is affected by this, you won't get the correct retaliation result if you were to apply the same factor to the defense value of the unit instead.
Which tiles provide the standard defense bonus?
Non-walled cities and defensive terrain for which you researched the relevant technology - Aquatism for water, Archery for forests and Meditation for mountains. If a player has any of these technologies, their units will have a shield appear around their HP when they are on tiles that provide the bonus. The shield will also appear on units that are in friendly cities, with a few exceptions - Aquarion amphibians, crabs and tridentions never receive the defense bonus from cities, even if they are walled.
My unit is attacking from a tile that provides a defense bonus. Why is there no option that accounts for this?
Contrary to popular belief, this has no effect on the result. You forfeit the bonus entirely. Your unit will receive full damage when the enemy unit retaliates.
How does the retaliation damage work? Why does the calculator sometimes report that the defender was destroyed but no word on what happened to the attacker?
The unit's defense value is used in place of its attack value to calculate the return damage. This is why some units deal significantly less damage when retaliating, while the defender unit and units with defense bonuses deal more. Because all of the modifiers are already applied before dealing damage takes place, the defender's HP loss doesn't affect its retaliation result. Instead, it deals damage based on HP it had before combat began. However, if the attack outright destroys the defender, there is no retaliation. The attacker is unphased, so there's nothing for the calculator to report.
I'm attacking an enemy with a ranged unit, but that enemy doesn't hit back. The calculator says I receive damage anyway. Does this affect my damage result?
No. The calculator has no way of knowing if you're attacking a unit next to you, away from you, or a ranged unit that doesn't retaliate because you're in your enemy's fog of war. Simply disregard the retaliation damage - the damage you deal is not affected in any of these cases.
Where can I see all the unit stats?
If you use drop-down unit templates, the calculator will automatically fill all the stats for the selected unit. For more info, you should read the unit page on the game's wikia site. You can find the link to this page at the bottom of this FAQ.
How does the fire dragon's splash damage work?
It is calculated in the same way as a regular attack. However, an additional line of code is added at the end:
defender.health = defender.health - floor(attackResult / 2);
This means that the unit receives half the damage it would normally receive if it was the main target, rounded down. So e.g. if the fire dragon would deal 11 damage to a unit by attacking it directly, that same unit would receive 5 damage (11/2=5.5=5) if it was splashed instead. Since nothing is altered in the original formula, the unit also benefits from its defense bonus, if any. It is also worth noting that only the fire dragon's main target can retaliate, provided it survives the initial attack.
Both the main attack and splash damage results are provided to you simultaneously, calculated separately for the same defending unit. You either take one result or the other, depending on your follow-up. This is convenient if you're testing for damage in a group of units, so you can quickly get an idea which unit would be the most optimal to choose for the dragon's main attack. The calculator assumes the main attack will be the follow-up, and deducts that result from the defender's current HP.
Can I use the calculator offline?
Yes you can. Follow these instructions:
PC: Go to the calculator website, right-click on any empty space and press Save as... or Save Page As... to get the index.html file. Alternatively, you can download the file from my Google Drive or GitHub. After you downloaded it, simply drag the .html file into your browser to run the calculator.
iOS: Repeat the PC process. Download an app called HTML Viewer Q by Spica. Connect your device to iTunes. In iTunes, select your device and go to File Sharing. Select HTML Viewer, press Add File and find the .html file you downloaded on your PC. Disconnect your device, run HTML Viewer and press on a book-like icon at the bottom right. Switch from Bookmarks to Files and select the downloaded .html file.
Android: Either repeat the PC process, or download the Google Drive app to fetch the .html file from my Google Drive. If you used the PC, connect your device and transfer the .html file to it. If you used Google Drive, the file should be in your Downloads folder. Download the HTML Viewer app by Yogev Haham and run it. Press the paper-like icon at the upper right. Find and select the downloaded .html file, then press the browser view icon in the upper right.
Who are you?
I'm a big fan of the game and I've been playing it since early 2017. I have a tendency to learn every game I play in great detail as I'm hoping to pursue game design at some point. For about a year I was active over at the game's Discord server, which you should definitely join if you want to improve your game and meet other players. An invite to the server is posted at the bottom of this FAQ. I have since left Discord so I can focus on other things.
How can I contact you?
You can contact me via e-mail. By all means contact me if you have any suggestions or bug reports regarding the calculator.
What are Discord challenges?
These are player-made, self-imposed limitations that alter the gameplay in some fundamental way. You can find the challenge list at the bottom of this FAQ. To be eligible for the scoreboard, you have to join Discord and post your results in the appropriate channel.
How can I become a better player?
Read through strategies on the game wikia, Reddit and Discord. Watch videos of experienced players on Youtube. Ask the player-base for help. Most important of all - play a lot, maximize your income and try to learn the mechanics behind the game. It will come in time. The links to help you with this are provided below.
Links:
Discord
Wikia
Reddit
Official Game Website
Official Game Facebook
Midjiwan's Twitter
Midjiwan's Instagram
Midjiwan's Youtube Channel
Midjiwan's Wikia Post
Wikia Unit Page
My Screenshots
My Videos
Tupp's Videos
Dued03's Videos
Ze Biggest Potato's Videos
Domination Guide by Airgibbo
Perfection Guide by Tupp
Perfection Guide by Illinois_Jones
Multiplayer Guide by Will2Brown
Challenge List
Changelog
<<< Back to the calculator!