Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The battle formula does not work properly #450

Open
velhbxtyrj opened this issue Jan 4, 2018 · 53 comments
Open

The battle formula does not work properly #450

velhbxtyrj opened this issue Jan 4, 2018 · 53 comments
Assignees
Milestone

Comments

@velhbxtyrj
Copy link
Collaborator

Please review the code in which the bonuses for the troops are summed up from the hero and from the Blacksmith and Armoury. According to my calculations, these bonuses are not taken into account.

There is a possibility that I made improvements through the admin panel. But it is unlikely that the problem arose because of this.

@Shadowss
Copy link
Collaborator

Shadowss commented Jan 4, 2018

Works in combat simulator. Why you don`t give us a screen for an example :

Send 2000 Imperian with 20 level in Armoury to battle with 2000 Spearman with 20 level in Backsmith. Also send same 2000 Imperian level 0 in Armoury to battle with 2000 Spearman with level 10 in Blacksmith. And print us the screens.

@velhbxtyrj
Copy link
Collaborator Author

Most likely I was mistaken. But as for me, the formula does not work very well for calculating these bonuses.

@velhbxtyrj
Copy link
Collaborator Author

I understood what you meant

Here are some comparison attacks. And this happens in every report.

First Attack

1
2

Second Attack

3
4

@martinambrus
Copy link
Contributor

calculations, calculations....... @AL-Kateb would you care to investigate this math as well perhaps? :)

@AL-Kateb
Copy link
Contributor

AL-Kateb commented Jan 4, 2018

I'm on it :)

@AL-Kateb
Copy link
Contributor

AL-Kateb commented Jan 4, 2018

Here are some comparison attacks. And this happens in every report.

I tested the bonus from blacksmith and armory, according to the code, and according to my testing it is working fine, I did not check the hero bonus yet, but as for these two, the battle report matched the simulation 100%, even though it was a little bit off compared to the regular T4 legends simulator, but that's a different story.

I think I know why your reports are different from the simulation, as I noticed you entered 2677 in the population, there is no village that can go that high in population, clearly you're assuming the population taken into account here is the account population, but this is inaccurate, the population used in calculation is the VILLAGE POPULATION not the account population, hence the real attack does not match the simulation.

As a side note, while I was at it, I was transferring troops from one village to another (Same account), and apparently there's something wrong with that code, something is wrong with returning the troops, after a few actions I was able to change the home for my troops from one village to another! Which is a big issue, players can exploit this to produce troops from one village and send them all (change their home) to another, it is not as straight forward as this, some condition needs to be met, I am gonna check how to replicate this and see how to fix it, then I will get back to you.

@velhbxtyrj
Copy link
Collaborator Author

The general population is taken into account (the entire account), since there is an additional bonus of protection for weak players (when attacking the strong on the weak), this exists from the very first travian.

I'll give an example: I'm top in the houses and the strongest player on the server. I have a village with a small population (in which all my main attacking troops) in order that the bonus in the attack is not taken into account. It will be stupid compared to players who started playing much later and much weaker than me.

Perhaps this is the problem of calculating battles. Because of the fact that only the population of the village is attacked.

Sorry for the bad english. I write through translator.

In English, I could not find descriptions where it was said that the general population was taken into account, I could only find it in Russian.

@AL-Kateb
Copy link
Contributor

AL-Kateb commented Jan 4, 2018

I completely understand your logic, and it makes perfect sense, but as far as I remember, I was in an argument with a friend of mine over this a couple of years ago, we tested the original Travian and we concluded that the population used here is the one of the village, not the entire account. Which as you said defeats the purpose of the bonus.

But regardless of how original Travian behaves, the code as it stands today calculates the population of the village, not the account.

I will do more research to check what population original Travian uses, and if it is the account's population, it is easy to edit the code to reflect that.

@velhbxtyrj
Copy link
Collaborator Author

I can give you a link to the Russian-language text, which describes completely how the simulator of strife works. You can read this through an interpreter. There is also an excellent resource where this calculator is available in an expanded form. It is recommended by a lot of people to use. There is an account of everything that is present in the game of travian. Also this calculator is available here. If you are interested in calculating, then I think you can ask Kirilloid himself what and how to count. I will also give a link to the calculation of formulas (also in Russian). If there are difficulties with the translation, I can help.

http://travian.kirilloid.ru/warsim2.php - Advanced battles calculator (excellent resource), pay attention to the population (when hovering on the field is written what kind of population)
http://t4.answers.travian.ru/?view=answers&action=answer&aid=261 - How does the battle simulator work? (http://t4.answers.travian.com/index.php?aid=289 - I found this in English.)

An important factor is the total population of the attacker and defender (not just of the village, but the total pop of the account across all villages).

http://travian.wikia.com/wiki/Combat_simulator - on this site speak about Kirilloid
https://github.com/kirilloid/travian - from Kirilloid for travian

@AL-Kateb
Copy link
Contributor

AL-Kateb commented Jan 4, 2018

I just tested on Travian, even though the result was not exactly as the simulator it was closer to the one where I put the whole population instead of just the village population, so you're right.

I will modify the code accordingly

@velhbxtyrj
Copy link
Collaborator Author

http://t4.answers.travian.ru/index.php?aid=345 - it's in Russian, I could not find it on the English site (The battle system: formulas) I'll try to find it in English, but it's unlikely.

@martinambrus
Copy link
Contributor

A very nice debate guys, I appreciate the time you took to look into this :)

@velhbxtyrj
Copy link
Collaborator Author

@AL-Kateb you have not forgotten about this problem? :)

@velhbxtyrj
Copy link
Collaborator Author

@iopietro Please pay attention to this problem, it is very serious for the game process.

@velhbxtyrj velhbxtyrj changed the title Bonuses for the types of troops The battle formula does not work properly Apr 5, 2018
@iopietro iopietro self-assigned this Apr 5, 2018
@iopietro
Copy link
Owner

iopietro commented Apr 5, 2018

Fixed in c3e2bae.

simulation
attack

@velhbxtyrj Let me know if i can close this issue.

@velhbxtyrj
Copy link
Collaborator Author

With the game calculator this perfectly matches. But a little different from that of another calculator :)

@iopietro
Copy link
Owner

iopietro commented Apr 5, 2018

Which calculator do you use? I've tried kirilloid and it works fine. (without walls, palace/residence and blacksmith/armoury)
kirilloid

@kirilloid
Copy link

kirilloid commented Apr 7, 2018

Step 6: rounds to the nearest multiple of 0.0002, the formula should be

2 * round(1.8592 - pow($total_units, 0.015), 4); // 1.3268946071185956

K = 1.3268

@iopietro
Copy link
Owner

iopietro commented Apr 7, 2018

Ok, I modified the formula from:

round(2*(1.8592-pow($involve,0.015)),4);

To:

2*round((1.8592-pow($involve,0.015)),4);

($involve = total units)

But there's still a very little difference (without bonuses):

simulation2
simulation1

Infantry attacking points = 1635870
Cavalry attacking points = 628080

Infantry defensive points = 805660
Cavalry defensive points = 2275410

Total attack points = 2263950
Total defensive points = (Infantry defensive points * (Infantry attacking points/Total attacking points)) + (Cavalry defensive points * (Cavalry attacking points/Total Attacking points)) + 10 = 1213417,7771152

K = 1,3634

Attacker final result = round((Total defensive points/Total attacking points)^K),8) = 0.42728169
Defender final result = 1

Attacker losses:
19293 * 0,42728169 = 8243,54564517 = 8244 Leggionaires
12345 * 0,42728169 = 5274,79246305 = 5275 Imperians
5234 * 0,42728169 = 2236,39236546 = 2236 Equites Imperatoris

Defender losses: all troops are dead.

@iopietro
Copy link
Owner

iopietro commented Apr 7, 2018

I changed that formula with your formula and it seems to work great:

 $rdp = round($cap/$rap, 4)*($cdp) + round($ap/$rap, 4)*($dp) + 10;
  1. $rdp = Defender result points
  2. $cap = Cavalry attacking points
  3. $ap = Infantry attacking points
  4. $cdp = Cavalry defending points
  5. $dp = Defensive points

@kirilloid
Copy link

Yes, wanted to say about the mix of infantry and cavalry, should be round to 4 decimal places.
Total defensive points would be 1213418 rather than 1213417,7771152, total points are rounded to the nearest integer (that's obviously important for small values).
Attacker final result no need to rounded with round(... , 8) Doesn't really matter, though.

@iopietro
Copy link
Owner

iopietro commented Apr 7, 2018

Ok, thanks, i modified it and now it works great, with all kinds of bonus (walls, residence/palace + base defense, troops upgrades) except for the morale bonus, i don't know how it should be approximated (i tried 3 decimal digits):

If Total attacking points < Total defending points

$moralbonus = round(min(1.5, pow($attpop / $defpop, 0.2 * ($rap / $rdp))), 3);

else

$moralbonus = round(min(1.5, pow($attpop / $defpop, 0.2)), 3);

But it's slightly different than your simulator.

@kirilloid
Copy link

kirilloid commented Apr 7, 2018

Yes. I use a single expression with min function, but the logic is the same.
The trick is inverse value should be rounded. You might think about it as a handicap for attacker rather than moralebonus.

// here it's still a bonus, you multipy it the same way in all other parts of code.
$moralebonus = 1 / round(max(0.667, pow($defpop / $attpop, 0.2 * min(1, $rap / $rdp))), 3);

Also I don't see from the code your shown, whether there's a check that moralebonus cannot be less than 1.

@iopietro
Copy link
Owner

iopietro commented Apr 7, 2018

Nice, it works perfectly :)! Yes, it's a huge handicap in certain cases.
Yeah, there's a control which decides if it should apply or not the formula, this is the whole code:

        if($attpop > $defpop) {
            $moralbonus = 1 / round(max(0.667, pow($defpop / $attpop, 0.2 * min(1, $rap / $rdp))), 3);  
        }else{
            $moralbonus = 1.0;
        }

@iopietro
Copy link
Owner

iopietro commented Apr 7, 2018

I've another question, what is the formula which determines the new level of a building partially demolished by catapults/rams (I can't find it in your guide)?

For example (with no bonuses, no defenses, no losses):

10 catapults will bring a building from level 20 to level 18, how can i know that the new level must be 18?

@kirilloid
Copy link

kirilloid commented Apr 9, 2018

https://wbb.forum.travian.com/thread/75248-combat-system-formulas/
See 3.a Catapults
Target level N.
For every level k find amount of catapults enough to demolish building completely.
Find minimum k such that (amount of catapults to demolish N) minus (amount of catapults to demolish level k), that would be final level.

Actually I don't know why do you need super-precise calculations. My research is not ideal anyway. There are problems with stonemason or/and artifact. Formula gives big error for lower level buildings.

@iopietro
Copy link
Owner

iopietro commented Apr 9, 2018

Thanks! Yeah, I saw that chapter, but I haven't thought about that formula.
Because your combat system simulator is the best external tool for simulating travian battles :)!
It could give errors for lower level buildings and stonemason/artifact, but it's much better than our previous formula (not the actual one that I've made, that works pretty good) that used to calculate square roots of negative numbers, lol (resulting in an error, obviously).

@Shadowss
Copy link
Collaborator

Can be closed ?

@iopietro
Copy link
Owner

iopietro commented Jun 28, 2018

Not yet, there's still a discrepancy with the battle formula, when you attack a village with a wall and you damage/destroy it, the whole battle is recalculated, but battle results are a lot different than the original travian.

@Shadowss
Copy link
Collaborator

Ahh ok

@Shadowss
Copy link
Collaborator

I wanna ask if is counted in battle formula next attributes :

  • Earth wall (teutons) is harder to destroy then other walls (roman and gauls walls)
  • City wall (romans) is the easyest wall to destroy
  • Palisade (gauls) is the half between romans and teutos walls

@kirilloid
Copy link

kirilloid commented Jun 29, 2018

Maybe, create a separate issue for rams?
For me “combat formulas” seems more like an epic, rather than one issue. But it’s up to you.

Walls durability coefficients are:

  • city wall: 1
  • palisade: 2
  • earth wall: 5

@kirilloid
Copy link

Also you might be interested in
kirilloid/travian@4a78db0

@iopietro
Copy link
Owner

iopietro commented Jul 2, 2018

@Shadowss, Yes, they're already implemented.

@kirilloid, The only wrong formula is the one that recalculates the battle after the destruction/damaging of the walls, while the formulas that calculate how much a building have to be damaged (for rams and catapults) are slightly different than yours.

@iopietro
Copy link
Owner

@kirilloid Sorry in advance for the distrubance, but I would ask you some questions:

  1. I implemented your exact formula ("demolishPoints" in kirilloid/travian@4a78db0), but I don't know the exact point of it in which I can divide or multiply the catapults morale bonus.
  2. In a forum thread, you talked about this:
    immagine
    How can this "virtual intermediate level" be calculated?

Thanks for the help!

@kirilloid
Copy link

Technically now I have a solution, but it is incorrect with low wall levels and artefacts.
Let me play with new simulator on PTR and I'll return back to you.

@iopietro
Copy link
Owner

Ok, thanks again :).

@kirilloid
Copy link

In new simulator rams works just incorrectly

@iopietro
Copy link
Owner

iopietro commented Aug 2, 2018

Lol, nice, did you report it to the Travian's devs?

@kirilloid
Copy link

kirilloid commented Aug 7, 2018

Yes, I reported and they accepted it.
I'm in the process of updating code, rams weren't added yet, but you might be interested in other aspects, illustrated with tests: kirilloid/travian@26b27f0

@iopietro
Copy link
Owner

iopietro commented Aug 7, 2018

Very good :).

Thanks! I'll take a look on that commit.

@kirilloid
Copy link

kirilloid commented Aug 9, 2018

Combat system is ready to be digested.

There are

  • army class (w/o hero now)
  • fns for utility functions
  • main combat object
  • plus combat-factory to supply data for calculator in proper format

The quirky logic for rams with two stages is here.

BTW if you wonder how earlyRamTable looks like, here's a graph for lines 10, 15 and 20. Except on this graph 0Y numbers are 4 times less than in the code, because of 4 in "D = 4σ∙C – ½" (you can see it in comments in fns

rams points

@iopietro
Copy link
Owner

Thanks a lot :)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants