# Battle Algorithm

To explain the algorithm, an example of a battle between 2 teams of 6 heroes is proposed, each hero equipped with 6 items.

### Step 1. Calculation of the individual stats of each hero

{% hint style="info" %} <mark style="color:blue;">Stat</mark> <mark style="color:orange;">Global</mark> <mark style="color:purple;">Heroe</mark> <mark style="color:green;">Item</mark> <mark style="color:yellow;">Constant</mark> <mark style="color:red;">Decision</mark>
{% endhint %}

<mark style="color:blue;">Total Health</mark>: Sum (<mark style="color:purple;">Hero Vitality</mark> \* <mark style="color:green;">Item Vitality</mark>) for each item

<mark style="color:blue;">Total Strength</mark>: Sum (<mark style="color:purple;">Hero Strength</mark> \* <mark style="color:green;">Item Strength</mark>) for each item

<mark style="color:blue;">Total Speed</mark>: Sum (<mark style="color:purple;">Hero Speed</mark> \* <mark style="color:green;">Item Speed</mark>) for each item

<mark style="color:blue;">Total Aim</mark>: Sum (<mark style="color:purple;">Hero Vitality</mark> \* <mark style="color:green;">Item Aim</mark>) for each item

<mark style="color:blue;">Total Intelligence</mark>: Sum (<mark style="color:purple;">Hero Intelligence</mark> \* <mark style="color:green;">Item Intelligence</mark>) for each item

<mark style="color:blue;">Total Luck</mark>: Sum (<mark style="color:purple;">Hero Luck</mark> \* <mark style="color:green;">Item Luck</mark>) for each item

<mark style="color:orange;">Total Damage</mark>: <mark style="color:blue;">(Hero's Total Strength</mark>/<mark style="color:yellow;">10</mark> + <mark style="color:yellow;">1</mark><mark style="color:blue;">)</mark> \* (Sum(<mark style="color:green;">Item Damage</mark>) for each item)

<mark style="color:orange;">Total Shield</mark>: <mark style="color:blue;">(Hero's Total Strength</mark>/<mark style="color:yellow;">10</mark> + <mark style="color:yellow;">1</mark><mark style="color:blue;">)</mark> \* (Sum(<mark style="color:green;">Item Shield</mark>) for each item)

<mark style="color:orange;">Total Courage</mark>: (<mark style="color:yellow;">1</mark> + (<mark style="color:yellow;">5</mark> \* (<mark style="color:yellow;">3</mark> - <mark style="color:red;">#Battle Line</mark>))/<mark style="color:yellow;">100</mark>) \* Level \* <mark style="color:yellow;">CF</mark> \* (Sum(<mark style="color:green;">Item Courage</mark>) for each item)

* Items equipped on heroes of the same race will have a 10% bonus on all their stats

### Step 2. Calculation of synergies

Synergies will be implemented in the future and will be bonuses and special effects.&#x20;

Example: If you have 6 heroes of the same race, they all get a bonus of +200 life&#x20;

Example: If you put 2 Celts on the same # battle line, they will get +20 damage

### Step 3. Beginning of battle

Once the global stats and synergies and their respective bonuses have been calculated, the battle begins.&#x20;

The battle lasts a maximum of <mark style="color:yellow;">T</mark> turns and ends when a team runs out of heroes. The battle begins and the hero with the highest speed attacks. If there is a tie, the Hero with the highest Intelligence attacks. If it is still a tie, the Hero with the lowest # ID attacks. This Hero attacks one of the 6 opponents with a probability determined for each opponent by the following function:&#x20;

The probability that <mark style="color:blue;">A</mark> decides to attack <mark style="color:red;">E</mark> is proportional to <mark style="color:red;">E</mark>'s courage.&#x20;

There is a chance that the gods will intervene and prevent the attack, even if <mark style="color:blue;">A</mark> hits <mark style="color:red;">E</mark>. This probability is:&#x20;

P (Attack Avoided) depends on luck and <mark style="color:yellow;">AAF</mark>

<mark style="color:yellow;">AAF</mark>: Attack Avoided =?&#x20;

Since the blow affects the damage done, it is calculated as follows:&#x20;

<mark style="color:blue;">A</mark>'s damage to <mark style="color:red;">E</mark> depends on <mark style="color:blue;">A</mark>'s total damage and <mark style="color:red;">E</mark>'s shield

If the hit is critical, the hit does 200% damage

<mark style="color:red;">E</mark> loses an amount of life equal to the damage dealt by <mark style="color:blue;">A</mark>

### Step 4. Winner of the battle

If the <mark style="color:yellow;">T</mark> rounds are not reached, the team whose heroes remain alive wins. If the battle reaches <mark style="color:yellow;">T</mark> rounds without a winner, the team with the most heroes alive wins. If there are an equal number of Heroes alive, the team that dealt the most damage wins. If the two teams did equal amounts of damage, the team with the most health wins. Finally, and to avoid any sort of tie if all else fails, the team that has a hero with the lowest # ID wins the game.&#x20;

<mark style="color:yellow;">T</mark> = 15 rounds

### Step 5. Battle summary

You will see a summary of the fight with the number of rounds and the total damage of the battle, as well as a detailed report of everything that happened in each round. This way you can analyze what went well or wrong and get familiar with the battles.
