Unraveling some myths regarding the battle engine

  • Thread starter DeletedUser2754
  • Start date

DeletedUser2754

Guest
In the last weeks I was able to crackdown the battle engine and build a replica of it for the use of the community (it is available in the "Player Projects" section of the forum). Anyway, many things have been said in the past, some were wrong, some were right, I will use this space to try and clear up the myths and the doubts regarding the way the battle engine works.

How it works:
Each battle is divided into 5 rounds.
1. Pre-round:
This round is used to calculate the kills inflicted by the trebs on the rams & cats of the offensive army. Each defensive trebuchet kills 1 rams or 1 cat and it kills them proportionally to the amount sent. The attack and defense modifiers do not apply here.
This round is also used to calculate the damage inflicted by the rams on the wall that will define the bonus wall for the whole battle. The number of "active" rams for this calculation comes from a correlation between the provisions of offensive army minus the provisions of the rams, and the overall provisions of the defensive army plus the basedefense given by the initial wall level of the village. The defense modifier is not considered in any of this calculus, you'll get the same results for the bonus wall if the defending village has no faith or a level 3 church in it.

2. Round 1:
The offensive troops fight in groups according to their type: general (spears, swords, axeman, bezerkers); cavalry (light cavalry, heayvy cavalry); archer (archer, mounted archer). You then have a few special units that will fight with the largest group, and largest is not the one that takes the most provisions, but the one with highest numbers (1500LC is larger than 1400MA even if the MA group takes more provisions). The special units are rams, cats, trebs and the paladin. And no, I'm not forgetting the noble. The noble does not fight. So in round 1 the offensive army is divided according to the above groups.
For defense there are no unit types, all units fight in all groups in the right proportion. It's the offensive army that rules the way troops are distributed in the fighting groups according to the provisions each group takes. For instance if the offensive army had 50% provisions in cavalry units, 30% in the archer group and the remaining 20% in general group, then the defensive army will be decomposed in the same percentages. So the offensive cavalry will fight 50% of the defensive army and so on. And the defensive units will use their defensive skills (power) according to the group they were assigned to face. So a spear will have 25 strength when in the general group, 45 when against cavalry and 10 in the archer group.
The relation of powers between offense and defense will dictate the winner and the number of killings on both sides. The formula to determine the killings has a parabola shaped graph which means the more the difference the less kills on the winning side. That's why you'll always get better results if you send, 4000lc in one attack than two attacks of 2000lc each.
If all the mini-battles have the same winner, the battle goes directly to the final round. If you have different winners in the 3 minibattles, the surviving units move on to the next round.

3. Round 2:
Same mechanics as round 1. But the basedefense provided by the wall, which in Round 1 was added to each group in the defense strength, here is not considered.

4. Round 3:
Same mechanics as round 2.

5. Final round:
On the final round, the surviving cats and rams take a hit at their target building/wall.



The formulas:
TREBS effect: RamsKilled=Trebs*(Rams/(Rams+Cats)) > rounded
RAMS active ratio: RamRatio=(OffenseProvisions-RamsProvisions)/(DefenseProvisions+WallBaseDefense)
PRE-BASEDEFENSE: (1.2515^(WallLevel-1))*20
BONUS WALL calculation: WallDamage=(Rams*RamRatio*OffModifier*PaladinModifier)/(WallLevelHitpoints*2) > rounded

BaseDefense: (1.2515^(WallLevelAfterPreRound-1))*20
Offense strength: (∑UnitType*OffStrength)*OffModifier
Defense strength for round 1: (∑UnitType*OffStrength)*DefModifier+BaseDefense
Defense strength for round 2&3: (∑UnitType*OffStrength)*DefModifier
KILL ratio: (MiniBattleLooserStrength/MiniBattleWinnerStrength)^(1/2)/(MiniBattleWinnerStrength/MiniBattleLooserStrength)
KILLS: NumberOfKills=NumberOfUnits*KillRatio

Ram final damage: WallDamage=(SurvivingRams*OffModifier*PaladinModifier)/(WallLevelHitpoints*2) > rounded
Cat final damage: BuildingDamage=(SurvivingCats*OffModifier*PaladinModifier)/(BuildingLevelHitpoints*DefModifier) > rounded



The noble conundrum:
In the wiki it says the noble has 30 of offensive power. Yet the noble gets killed if sent alone to villages with no wall which have 0 of base defense. A ram has 2 of offense strength and survives the same battle. So what happens there? What happens is that the noble doesn't fight. Its offensive strength is irrelevant. It could have 0 or 1000 or even 1mil., it would not influence in any way the outcome of the battle.
We all have seen reports with surviving units on both sides. What happens is that the noble doesn't fight but his provisions are considered in the battle rounds. For instance, let's say we sent 200lc+1noble against 150hc. To make it easier let's consider no wall, no bonus, everything at 100%. What happens is that the offensive army has a total of 200*4+100=900 provisions. But since the noble doesn't fight, on the 1st round the 200lc will only fight (800/900)*150=~133hc. The remaining 17hc go directly to the next round. 148lc get killed in the process, killing all the 133hc they fought. So, for the 2nd round we have 52lc+1noble vs. 17hc. The process of leaving the noble out is repeated. (52*4)/(52*4+100)*17=~11hc. For the 3rd round we have 45lc+1noble vs. 6hc. (45*4)/(45*4+100)*6=~2hc. In the end 43lc survive but on the other side there are 2 hc that never fight. So you have troops surviving on both sides.
 

DeletedUser2084

Guest
I have a question though: How come a noble can sometimes live even though 95% of the attacking army dies (5% lives whilst the defending army is completely wiped). Is there some sort of increasing factor per round that says "50% of the time a noble will die in round 2 and 75% in round 3"?
You say the noble does not participate in the fight but at what point does a noble die within the game engine?
 

DeletedUser2754

Guest
That part I don't know. In the spreadsheet I created the survival of the noble is not correct. As far as I know, it is the only thing that is not correct there. But when you get your hands on those kind of odd reports, please forward them to me and I will try to figure out how they work and give you a better answer ;)
 
I have a question though: How come a noble can sometimes live even though 95% of the attacking army dies (5% lives whilst the defending army is completely wiped). Is there some sort of increasing factor per round that says "50% of the time a noble will die in round 2 and 75% in round 3"?
You say the noble does not participate in the fight but at what point does a noble die within the game engine?

well its a odd one. personally i think luck has a thing to do with it really , like as long as 70+1% of your troops survive the nobleman is secure that passed and as your causality increases your chance of losing your noble will growth.
something like this :
70% troops survive(secure nobleman) > Random Chance of dying in each of rounds for noble > 20% troops survive(nobleman is dead)
 

DeletedUser3016

Guest
well its a odd one. personally i think luck has a thing to do with it really , like as long as 70+1% of your troops survive the nobleman is secure that passed and as your causality increases your chance of losing your noble will growth.
something like this :
70% troops survive(secure nobleman) > Random Chance of dying in each of rounds for noble > 20% troops survive(nobleman is dead)
Though I don't know the actual equation for it, I would say that I have seen it hitting from as low as 50% and above, for my nobles to die.
 

DeletedUser2754

Guest
I have seen that happening as well andy.

It could be as someone once told me that there is a chance of survival that increases in the opposite increase with the percentage of overall units that get killed. That would mean there is no real formula, just a random thing. Like the loyalty reduction, for instance.
Or it could be that it depends on specific factors of each attack and sometimes the specifics are odd and the result just seems odd, but can be translated by a mathematical formula.
If you have odd reports of nobles that shouldn't have died or nobles that should have died, please forward them to me and I will take a look at them and see if I can figure it out.

Thanks in advance ;)
 

DeletedUser3016

Guest
I will do, but honestly, in the war I am in currently... My nobles don't die :p
 

DeletedUser1323

Guest
Nobles have always stacked with the final group as an escort unit and should never be sent alone. It has an attack power to be used in the calculation of survival or not, if x units in infantry survive then the noble survives and it will lower loyalty. That has always been the case. There has to be at least 1 or more units with > 30 total attack power with that noble.

Back in the beta days it used to stack only with infantry and if sent with other unit types it would instantly die much like rams would die without axes.
 
Last edited by a staff member:

DeletedUser2084

Guest
if x units in infantry survive then the noble survives and it will lower loyalty.

That's interesting because I've seen nobles survive when 95% of the army dies and I've seen nobles die when 40% of the army lives. I don't think it's a flat number that ensures a nobles survival. What sounds more plausible is an increasing factor in terms of percentage of the noble surviving according to the percentage of surviving troops.

Something like:

If =<70% of the army survives - 99.99% chance the noble lives
If =<60% & >70% - 95% chance the noble lives
If =<50% & >60% - 85% chance the noble lives

This is where I think I think the chances of a noble lower drastically.

If =<40% & <50% - 50% chance the noble lives
If =<30% & <40% - 35% chance the noble lives
If =<20% & <30% - 20% chance the noble lives
If <20% - 5-10% chance the noble lives

Something like that is how I've always thought of how the noble decides to live or not.
 

DeletedUser2754

Guest
jehzir, the noble is lazy. He really doesn't fight, not even on the final round. If their offense power mattered they would survive when sent against a barb without escort. Rams have 15 times less strength and they survive. If you don't believe me, next time you have a report with survivors on both sides, test the numbers in the simulator and you'll see I'm right. And if your 3rd round theory was correct, since there are so few battles that are dragged to the last round, almost everytime the offense won the battle, the noble would get through, because the last round would be offense+noble against nothing.
This is from a convo between me and kropovs in skype, the example in there are from true reports:
[2016-06-03 18:53:18] hibakusha: It happens that strange thing that sometimes happens where both attacker and defender end up with units. But I'm not sure I have the settings for the nobles right
[2016-06-03 18:54:05] kropovs: Yeah ive seen those ones, have no clue what causes them
[2016-06-03 18:56:02] kropovs: I never even go to testing the nobles as to where the provisions are counted etc
[2016-06-03 18:54:17] hibakusha: I'm not sure. But what I think happens is that whenever you send an attack with nobles, the provisions of the defensive army corresponding to the provisions of your noble are removed from the battle and go on to the next round without fighting. Same thing in round 2 and round 3. On most circumstances, the troops get all killed in the process.
[2016-06-03 18:57:10] kropovs: Hmm! Are the survivors 100 provisions?
[2016-06-03 18:58:53] hibakusha: Not 100 provisions. On the report you gave me, it's 0.67% of the defensive troops that don't fight the first round, because the noble is 0,67% of the offensive army on the first round.
...
[2016-06-05 01:54:58] hibakusha: just got a report with survivors on both sides:
OFF: church 3, morale 100%, luck -9%, weapon mastery 10%, no officer > 25hc+1noble > result -6hc
DEF: no church, no wall > 30hc > result -28hc
[2016-06-05 01:55:09] hibakusha: my theory was correct
[2016-06-05 01:55:11] hibakusha: lol
[2016-06-05 02:05:18] hibakusha: and another one
OFF: same village specs but luck -5 > 25hc+1noble > result -15hc-1noble
DEF: church 3, no wall > 25hc > result -21hc
[2016-06-05 02:05:18] hibakusha: the sheet is working perfect for both
[2016-06-05 04:01:01] kropovs: Sweet, good to know that

sephyrx, that's the partially random approach I was implying in my last post. In the simulator, right now I made it simple. If 50% or more of the offensive army survives, the noble will survive. If it's a random thing, I guess that's the best I can do. If I find out it's something else, I will update the simulator.
 
Last edited by a staff member:

DeletedUser1323

Guest
jehzir, the noble is lazy. He really doesn't fight, not even on the final round. If their offense power mattered they would survive when sent against a barb without escort. Rams have 15 times less strength and they survive. If you don't believe me, next time you have a report with survivors on both sides, test the numbers in the simulator and you'll see I'm right. And if your 3rd round theory was correct, since there are so few battles that are dragged to the last round, almost everytime the offense won the battle, the noble would get through, because the last round would be offense+noble against nothing.
Right, the noble does not fight, it is an escorted unit. Maybe you just did not understand what I posted earlier.

According to the original code there is for lack of a better term an if/else statement based on the formula I put in the prior post that X number of units > 30 fighting power that must survive the final round, which includes all bonuses/modifiers and completed calculations, if those values fall below that 30 fighting power the noble died or there were units that survived that was higher than its defensive modifier could survive against. 10 defending axes can kill an noble, the wall level 0 can kill a noble by itself, since these have defensive modifiers greater than the value of its unaided attack.

I brought up the example of the axemen as escorts with rams as there are still portions of code that are similar to the effect that axemen had with rams. This was adjusted back in 2015 for rams to be assisted by any unit, the exception to this is a 0 level wall and no defending units in the villa, the ram survives, however, these similar adjustments was NOT made for the nobles.
 

DeletedUser2754

Guest
I'm probably not understanding what you are saying. Try giving me a true example from a report explaining all the steps to the noble survival calculation.

Because from what I understand of what you are saying, for instance if:
OFF: 100% overall modifier > 1800LC+2400MA+200ZERKS+1NOBLE
DEF: 100% overall modifier > 4000SP+2000AR+2000HC
The outcome of this should be offense wins killing all defense. No troops and the defense survive the 1st round. That means 360LC+443MA+125ZERKS+1NOBLE will fight the last round without any opposition (all got killed in round 1&2). By what you are saying and if I understood you correctly, the noble will survive. I don't know if you are right or not, for this specific case. But what I know is that in 90% of the attacks where offense wins, the last round will be against no one. So the noble is likely to survive almost every time. And I know that is not the case.

And I have nobled villages with 1ram+1noble more than once. So the escort for the noble was 1 ram, which equals to 2 of strength. Yet the noble survived. According to your proposals I should need more than 30... But I could have understood it wrong.

Also the rams case doesn't apply the way you are saying. Rams escort effect only applies in the pre-round for the bonus wall calculation, and have nothing to do with the rams own strength by themselves but with the enemy's base defense provided by the wall, and the provisions of the defense. 200 rams need 1420 provision worth escort to hit at full power against a wall 20 village with no troops inside. And that escort must be raised by as much provisions as the defender provisions in the village. The same amount of escort would be required for 1000 rams alike. But you would only need 151 provision worth escort to hit a wall 10 village at full power by the rams whatever their amount. So it has nothing to do with the units own strength.

And if you have access to the original code, please do share. I mean I like puzzles, but if I can have some help in reverse engineering the battle engine, I will use it for sure :D
 
the wall level 0 can kill a noble by itself, since these have defensive modifiers greater than the value of its unaided attack.
this statement is false , but you just reminded me that nobling an empty village with no walls in tw1 was possible with sole nobleman and its not here.

the most probable theory here is the same thing mentioned above by hiba , i think to one break point nobleman is totally secure like when 70% of your troops will survive the battle. from there its only a matter of chance and as your causalities raise the chance of your nobleman being eliminated raises as well so basically when you are at 20% or 30% surviving troops nobleman is most certainly dead.

to understand that i suggest a test , we can send 1000 axe and 4nobleman against a village with enough def to kill 50%+-luck of attacking army.
we repeat that enough times and compare the results. if luck is a huge factor for nobles these results will be quite different from each other. if not then at least we know it has a formula or something.
 

DeletedUser2754

Guest
I will follow Hawk.eye's suggestion and try to test it whenever I have nobles needing of relocation. It might take a bit of time until I have some clear answers.
In the meantime I found two minor bugs in the battlesim. I will upload a new version of it later today.
 

DeletedUser3586

Guest
There are some misconceptions tho. As far as I understand the battle system, wall bonus is considered in all rounds. Another thing is if the attacking troops doesn't have different types. Let's say pure lc. And there will only be 1 round. All the defensive force will defend.
 

DeletedUser2754

Guest
There are some misconceptions tho. As far as I understand the battle system, wall bonus is considered in all rounds. Another thing is if the attacking troops doesn't have different types. Let's say pure lc. And there will only be 1 round. All the defensive force will defend.
The wall bonus is considered in all rounds, except the pre-round, because one of the functions of the pre-round is to calculate the wall bonus. And its value is part of the "DefModifier" you can see in the formulas. All defense bonus combined make the DefModifier, the same way, all offensive bonus combined make the OffModifier.

I guess I forgot to add the following two formulas:
DefModifier = Faith * (1 + WallBonus)
OffModifier = (Faith * Morale * (1 + Luck)) + (WeaponMasteryLevel * 2%) + Officer

Regarding one unit type attacks, that means that 100% of the offensive army is of a specific type, thus 100% of the defense will be allocated to defend in that mini-battle. So, the rule still applies.
 

DeletedUser1323

Guest
I'm probably not understanding what you are saying. Try giving me a true example from a report explaining all the steps to the noble survival calculation.

Because from what I understand of what you are saying, for instance if:
OFF: 100% overall modifier > 1800LC+2400MA+200ZERKS+1NOBLE
DEF: 100% overall modifier > 4000SP+2000AR+2000HC
The outcome of this should be offense wins killing all defense. No troops and the defense survive the 1st round. That means 360LC+443MA+125ZERKS+1NOBLE will fight the last round without any opposition (all got killed in round 1&2). By what you are saying and if I understood you correctly, the noble will survive. I don't know if you are right or not, for this specific case. But what I know is that in 90% of the attacks where offense wins, the last round will be against no one. So the noble is likely to survive almost every time. And I know that is not the case.

How you know that it is not the case? I know that goofy inexpiable things happen all the time with the game. I am telling you what I know of the original code when it was under discussion for release from beta into the first 1.0 version.
And I have nobled villages with 1ram+1noble more than once. So the escort for the noble was 1 ram, which equals to 2 of strength. Yet the noble survived. According to your proposals I should need more than 30... But I could have understood it wrong.
was the wall at 0 and no other unit in the villa at the time of the 1ram+1noble? If no units then this if else loop is not ran. The problem is that there is a conditional statement based on a varying parameter, which we all know leads to serious logic errors.
Also the rams case doesn't apply the way you are saying. Rams escort effect only applies in the pre-round for the bonus wall calculation, and have nothing to do with the rams own strength by themselves but with the enemy's base defense provided by the wall, and the provisions of the defense. 200 rams need 1420 provision worth escort to hit at full power against a wall 20 village with no troops inside. And that escort must be raised by as much provisions as the defender provisions in the village. The same amount of escort would be required for 1000 rams alike. But you would only need 151 provision worth escort to hit a wall 10 village at full power by the rams whatever their amount. So it has nothing to do with the units own strength.
Forget the rams, you have that right, what I was trying to do by giving you another example in the code where there is an escorted unit. This is a similar problem and use it as an attempt to solve the puzzle. I cannot help that you took it literally instead of figuratively. The rams equation and function is a model to examine to get your noble question correct.
And if you have access to the original code, please do share. I mean I like puzzles, but if I can have some help in reverse engineering the battle engine, I will use it for sure :D

I was asked not to produce or make anything from the code, but I do see that you have incorporated and refined several of the formulas, for the better, that we discussed in the past.
Personal note: I am not trying to put you down or make you look bad, I guess we are just having a hard time communicating with each other
 
Last edited by a staff member:

DeletedUser1323

Guest
The wall bonus is considered in all rounds, except the pre-round, because one of the functions of the pre-round is to calculate the wall bonus. And its value is part of the "DefModifier" you can see in the formulas. All defense bonus combined make the DefModifier, the same way, all offensive bonus combined make the OffModifier.

I guess I forgot to add the following two formulas:
DefModifier = Faith * (1 + WallBonus)
OffModifier = (Faith * Morale * (1 + Luck)) + (WeaponMasteryLevel * 2%) + Officer

Regarding one unit type attacks, that means that 100% of the offensive army is of a specific type, thus 100% of the defense will be allocated to defend in that mini-battle. So, the rule still applies.
This is absolutely correct and something that is the real misconception out there. I have been beating this drum for along time. I am glad to see another join the band :)
 
Top