-3

i try to find an algorithm for strategy game battles like travian or lord of ultima or ... but every program that i wrote it had bug for calculating dead Soldiers, some examples of this critical points is:

  1. in real world when 100 soldiers attack to 1 soldier,its usual that all 100 soldiers is alive and 1 defender soldier is dead.
  2. finding winner of battle

data example is:

attacker:
Soldiers | defending-power | attacking-power | Soldier Count |
---------|-----------------|-----------------|---------------|
A        | 20              | 45              | 5
B        | 22              | 77              | 4
C        | 41              | 32              | 7
D        | 38              | 54              | 6
E        | 27              | 41              | 6

defender:
Soldiers | defending-power | attacking-power | Soldier Count |
---------|-----------------|-----------------|---------------|
A        | 44              | 12              | 6
B        | 59              | 18              | 6
C        | 73              | 40              | 7
D        | 26              | 61              | 2
E        | 7               | 24              | 4
Mehdi Yeganeh
  • 2,019
  • 2
  • 24
  • 42

1 Answers1

1

I would suggest that both players' soldier counts follows an exponential decay like curve, being dependent on each others' soldier counts. As in, at any point in time, soldier count of player X is being reduced by a factor of (Y's soldiers)*(Y's attacking power)/(Y's defending power), and same for player Y's soldier count.

If both players' strengths are similar, then both sides' soldier counts are going down as an exponential decay like curve, but if one player's strength greatly overwhelms the other's, then the other side's soldier count will feel a linear drop over time. (Yes, treat soldier count as a floating point until the battle ends.)

Getting the algorithm to match the data will be a process of determining how often you run the calculation (basically, how big you multiply that factor by), determining if you run both sides simultaneously or if one side reduces the other's soldier count first, whether you round up or down at the end and whether the attacking power/defending power part is really as simple as dividing one by the other, or whether you have diminishing or runaway returns for having the advantage.

Patashu
  • 21,443
  • 3
  • 45
  • 53