Help making a formula

MasterSplinter

New member
Joined
Jul 22, 2015
Messages
9
Hi everyone. I hope I am posting this in the right place. I know this will contain some calculus, but since it looks a bit more complicated I will post it here. If it belongs somewhere else, please move it to the relevant thread. I know this one is a bit long, but I would really appreciate it if you take your time to help me. I am not from an english speaking country, so please excuse me if my english is a bit off.

I am trying to make a formula for a strategy game. To understand the problem better, I will give you a very brief introduction to the relevant parts of the game. In this game each player makes troops for multiple villages, that fight each other. There is a maximum amount of troops a player can make in each village, but I will get back to this in a moment. There are three kind of units that fight seperatly; infantery, cavalery and archers. Both of these kind of units have offensive and defensive units. Each of these units have attack/defence power. What I am trying to make is a formula that can say:

- What is the strongest offensive village you can make agaist a given defensive village?
- What is the strongest defensive village you can make against a given offensive village?

Before we head into the problem, Ill give you an overview of the units.

Infantery units:

Spearman

Attack power: 10
Infantery defence: 15
Cavalery defence: 45
Archer defence: 20
Population: 1

Now, lets get on to the problem:

Swordman

Attack power: 15
Infantery defence: 50
Cavalery defence: 15
Archer defence: 40
Population: 1

Axeman

Attack power: 40
Infantery defence: 10
Cavalery defence: 5
Archer defence: 10
Population: 1

Cavalery units:

Light cavalery

Attack power: 130
Infantery defence: 30
Cavalery defence: 40
Archer defence: 30
Population: 3

Heavy cavalery

Attack power: 150
Infantery defence: 200
Cavalery defence: 80
Archer defence: 180
Population: 6

Archer units:

Archer

Attack power: 15
Infantery defence: 50
Cavalery defence: 40
Archer defence: 5
Population: 1

Mounted Archer

Attack power: 120
Infantery defence: 40
Cavalery defence: 30
Archer defence: 30
Population: 5

Each village can have a population of maximum 18.500

Alright, lets get on to the math. I know that battle results are made out of this formula:

Winners losses = (Loosers strength/Winners strength)^1,5

This formula is used three times in a battle (one time for each unit type (infantery/cavalery/archer units). If you feel very confused so far, I will show an example of how a battle works below (I recommend skipping the quoted example until you have read the rest of this post):

Lets say you use an attacking force of 6000 axemen and 3000 light cavalery against a defending force of 5000 spearmen and 5000 swordmen.

First, lets look at the numbers for the attacking force:

Attack power:

Axemen (infantery strength)= 240000 (6000x40)
Light Cavalery (cavalery strength) = 390000 (3000x130)
Total attack power = 630000;

Since 24/63 of the total attack power is infantery strength 24/63 of the defensive units will defend against infantery. Multiply this number with the units infantery defence. This means that the defence will contain:


1904,762 spearmen (28571,428 infantery defence)
1904,762 swordmen (95238,095 infantery defence)



This means that the total defensive strength against infantery would be 123809,523

This means that the infantery attack strength is 2400000 while the infantery defence is 123809,523. Now, lets put these numbers into the formula above:

(123809,523/240000)^1.5 = 0,37052218207460881201358712215362

0,37052218207460881201358712215362 * 6000 (number of attacking axemen) = 2223,1330924476528720815227329217

The attacker looses 2223 Axemen

Now we will do the exact same thing for the cavalery battle:

Since 39/63 of the total attack power is cavalery attack, 39/63 of the defence will fight cavalery attack.

The attacking cavalery power is 390000.

The defensive power is

3095,238 Speamen (139285,714 cavalery defence)
3095,238 Swordmen (46428,571 cavalery defence)
Total of: 185714,285

Let put these numbers into the formula:


(185714,285/390000)^1,5 = 0,32860264541009845899038191059149

0,32860264541009845899038191059149 * 3000 (number of attacking light cavalery) = 985,80793623029537697114573177448

The attacker looses 986 light cavalery


By using the formla we calculated the result of a battle where 6000 axemen and 3000 light cavalery attacks 5000 spearmen and 5000 swordmen. The defender looses everything, while the attacker looses 2223 axemen and 986 light cavalery.

This example didnt contain archer units, since that would make it even more complicated, but it is calculated the exact same way.


Now, in this example I was given both the offensive and the defensive strength, but lets say I only knew one of them. What is I knew that the defense was 9250 spearmen and 9250 swordmen (total of 18500 population)? How will I be able to calculate what the best possible offensive army would be?

I have tried to calculate a bit with derivation, but since infantery strength, cavalery strength and archer unit strength all need to take each other into account, it is getting too hard for me.

I would really appreciate some help. Please explain how you are thinking, so that I can understand it too :smile: Thank you in advance!
 
Are you asking that we try to backwards-engineer a video game you're playing? :shock:
 
Are you asking that we try to backwards-engineer a video game you're playing? :shock:

Sounds something like it or possibly one of the MMO games [MMOG/MMORPG/...]. However, its really just a table look up and LP type problem.

Generally there are battle calculators available to settle on a strategy by a guess and correct method. The tables give you an initial guess and you refine them with battle calculator, i.e. Spearmen are good defense against Cavalry and Swordsmen defense against Infantry so if you know you have Cavalry and Infantry attacking in a particular ratio start a Spearman and Swordman defense in about the same ratio. If you are attacking, do it the other way around.
 
Oh, and I forgot to mention that if you really want to get the best attack (defense) you also need to account for the cost of your troops. For example, if you reduce the L Cavalry to 2000 in the example given, you lose 56 less Cavalry but 921 more Axemen. But if the cost for 1 Cavalry is 20 times the cost of 1 Axeman, you actually come out ahead in the game.
 
Oh, and I forgot to mention that if you really want to get the best attack (defense) you also need to account for the cost of your troops. For example, if you reduce the L Cavalry to 2000 in the example given, you lose 56 less Cavalry but 921 more Axemen. But if the cost for 1 Cavalry is 20 times the cost of 1 Axeman, you actually come out ahead in the game.

Im not taking cost into account as that would make the formula waay to complicated :)

I am basicly looking for a formula/generator that will calculate the best combination for an attacking/defending army, based on the army of your enemy. Is that possible to find out giving the numbers and the formula in the first post?
 
Im not taking cost into account as that would make the formula waay to complicated :)

I am basicly looking for a formula/generator that will calculate the best combination for an attacking/defending army, based on the army of your enemy. Is that possible to find out giving the numbers and the formula in the first post?

You could set up a program which would run through a lot of cases and give you an estimate. Best may depend on your definition. For example if it were smallest total losses, there may be more that one solution. You could set up something like a spread sheet and run through the different possibilities yourself. The formula's to be used are just the ones you gave.

To do it yourself, initial guesses could be made by choosing a winning number for all three battles (if you can) and work from there. As an example in the case given; 5000 spearmen and 5000 swordmen. Spearmen have least defense against infantry and best infantry is Axe, so you want Axe. Swordsmen have least defense against Cavelry [use L Cav]. Initially assume a 50/50 strength split so that there are 40 N Cav and 130 N Axe
IAttack = 130 N * 40 = 5200 N
CAttack = 40 N * 130 = 5200 N
Total Army = 170 N \(\displaystyle \le\) 18500 or N \(\displaystyle \le\) 108
IDefense = 0.5 * 5000 * (15 + 45) = 150000
CDefense = 0.5 * 5000 * (50 + 15) = 162500

So you want 5200 N greater than the larger of the IDefense or CDefense or 5200 N \(\displaystyle \ge\) 162500 or N \(\displaystyle \ge\) 32. Since, generally, greater forces take smaller losses in games like these, Pick N=108 [4320 Cav and 14040 Axe] and maybe add a few extra. You could play around with the numbers to see what other results you get and maybe get a better one.

If you write a program, just blindly (but systematically) run through cases and choose the best one(s).

EDIT: I noticed that L Cav had a pop of 3 which I didn't take into account but that could easily be added
 
Last edited:
For example if it were smallest total losses, there may be more that one solution. You could set up something like a spread sheet and run through the different possibilities yourself.

Well, not only smallest losses. Lets say you loose a battle and loose everything. It would still be helpful to have the combination that damage the enemy army the most.
 
Top