3

I am from a programming background and trying to write a game for fun.

I am trying to write a battle calculator and which ever way I think about it I seem to run into trouble.

Basically the scenario is this:

Both the attacking force and the defending force have, lets say soldiers. Each side can have, but not always, lets say mercenaries to help. Each side holds an arsenal of 10 possible weapons, each of which give a different hit force. Each side also has a small random force to bring in an element of luck.

After the battle I need to work out how many of the total kills were made by both player and mercenaries (if they join in) on both sides.

My simple approach to this so far is to work out the best possible weapons each side can have. That might be 50% weapon 7, 20% weapon 6 and the rest weapon 5 for example. I then calculate the total hit force this give and divide by the total number of soldier to give an average. I add any other hit mods the player qualifies for and use that to work out the kill amount. So if the total hit force is 3.6 I divide 3.6 by 100 then use number of soldiers * my hit force to give number of kills. I am sure this isn't the best way to do it though.

I am not expecting anyone to do this for me however handy that might be. On the face of it it seems a relatively simple calculation and maybe it is for someone who totally understands maths. I am at a loss to know what kind of maths I should be looking at. Can anyone make a suggestion as to how to approach this?

If anyone know of a website I can go to pay for this to be done for me I would be interested.

Tommi
  • 1,425
Fred
  • 83
  • Let me ask a a clarifying question: Are you looking for pseudocode to implement your system, a better system, modifications to what you currently have, or consultation with the mathematics you need with the current idea? The previous comment of mine gives a link to different approach. Please clarify what you are looking for. – Tommi Mar 06 '15 at 08:26
  • You need to clarify the type of battle you have. In the simplest scenario, with just two opposing soldiers, what do you want the effect of one side having a higher hit force to be? – tomi Mar 08 '15 at 00:02
  • You need to clarify the type of battle you have. In the simplest scenario, with just two opposing soldiers, what do you want the effect of one side having a higher hit force to be? Options include (1) the soldier with higher hit force always wins (2) the soldier with higher hit force has a higher probability of winning. – tomi Mar 08 '15 at 00:02
  • @tomi the side with the higher hit force always wins unless... it is only marginally higher say 5% then its just higher probability. – Fred Mar 08 '15 at 15:54
  • @TommiBrander to be honest I am open to suggestions from someone that knows better than I do about the best way to implement a battle calc. This game is a learning exercise before I attempt a more complex game. – Fred Mar 08 '15 at 15:56
  • Ok. You then need to define what is meant by a win. Is a total kill of the opposition? Is there a body count on the winning side? – tomi Mar 08 '15 at 19:14
  • Ok. You then need to define what is meant by a win. Is a total kill of the opposition? Is there a body count on the winning side? By your definition' two soldiers with hit force 1 weapons could be defeated by one soldier with a hit force 3 weapon. Are they both dead? That would reflect accurately a situation where a soldier with a revolver is against two soldiers with knives. But one soldier with a hit force 3 revolver would be beaten by ten soldiers with hit force 1 knives. Maybe that's realistic, but he would kill many of the ten before being killed himself. – tomi Mar 08 '15 at 19:14
  • I think you maybe need to use relative hit force to deal with the basic question of who wins. Then start thinkng about the lethality of the weapons as a separate matter to work out the number of survivors that your winning side has. – tomi Mar 08 '15 at 19:22
  • @Fred If you are interested, I can give further consultation. Contact me at [email protected], with the first and last name as in my user name. – Tommi Mar 09 '15 at 12:11
  • @TommiBrander I will email you after work. I think you have exactly what I am looking for as long as I can work out how to translate it into c# code! :) – Fred Mar 09 '15 at 12:35

1 Answers1

3

Suppose $w_1, w_2, \ldots, w_{10}$ are the weapon effectiveness numbers, and $m_j$ are the amount of people equipped with $w_j$.

To calculate the total effectiveness of a force, first calculate the total number of combatants $M$, which with the notation I use is $$M = m_1 + \ldots + m_{10} = \sum_{j=1}^{10} m_j.$$

According to Lanchester's square law http://en.wikipedia.org/wiki/Lanchester%27s_laws, the effectiveness of a force is proportional to the square of combatants, so we use $M^2$.

We want to involve the weapon technology in a linear manner. The simplest way that comes to mind is to multiply $M^2$ by the weighted average of weapon effectiveness, which would be $$\frac{1}{M} (m_1 w_1 + \ldots + m_{10}w_{10}) = \frac{1}{M}\sum_{j=1}^{10}m_j w_j,$$ so the total effectiveness $E$ of a force would be $$E = M^2 \frac{1}{M}\sum_{j=1}^{10}m_j w_j = M\sum_{j=1}^{10}m_j w_j.$$

An alternative, and I think theoretically nicer, way of using weapon effectiveness would be to have $$E = (\sum_{j=1}^{10} \sqrt{w_j} m_j)^2.$$ There are other fairly similar methods. You would need to be more precise with what you want in order to get more specific answers.

You can add other factors (random factors, morale, etc.) in similar way to weapon effectiveness - just add more multipliers.


You also asked for the ratio of kills between the main force and the mercenaries. To get it, first calculate the effectiveness of the main force (I write it as $E_s$) and the mercenaries $E_m$ as above. Then figure out the total number of kills in whatever way you do; let us write it as $K$.

The number of kills committed by the main force would then be $$\frac{E_s}{E_s+E_m}K$$ and the number of kills by mercenaries would be $$\frac{E_m}{E_s+E_m}K.$$

Tommi
  • 1,425