Big battle simulation

I need to simulate a battle between two players. It can last from one to six rounds. The attacker can have 13 different types of spaceships, the defender - an additional 9 types of defensive structures. The fact is that I will limit the simulation to 1 kk units on each side, so it will be quite large.

Each unit will be an instance of the following class.

class Unit() { UInt16 id; // unit type Int32 structuralIntegrity; Int16 shieldPower; public Unit(UInt16 unitType, Int16 playerId) { id = unitType; switch (playerId) { case 0: {structuralIntegrity = player0BaseStructuralIntegrity[id]; shieldPower = player0BaseshieldPower[id];} case 1: {structuralIntegrity = player1BaseStructuralIntegrity[id]; shieldPower = player1BaseshieldPower[id];} } } }; 

Arrays for immutable values.

player1technolgies

  • armor
  • technology protection
  • weapon technology

player2technolgies

  • armor
  • technology protection
  • weapon technology

player1BaseStructuralIntegrity

equall default * armor tech

And so on...

Then I will distribute two lists with each gaming device.

One round is as follows:

  • Choose a random unit // actually I donโ€™t think it matters if it is random or not
  • Choose a random target
  • If the strength of the weapon is below 1% of the targetโ€™s shield, it does no damage.
  • Target shields absorb damage, the rest goes to the goal of structural integrity.
  • If the target structural integrity is below 30% of its initial value, it is likely that 1-structureIntegrity / baseStructuralIntegrity will explode
  • Check the likelihood of a quick fire if it falls into step 2
  • Go to step 1 until all blocks attack | THE NOTE! Wrecked ships - with structural integrity below 1, can still be attacked. EDIT: They can also attack this round.
  • Repeat steps 1-7 for the opponent.
  • Delete destroyed ships
  • Restore screens

The battle lasts six rounds or until one side is defeated.

Let's consider an attacking fleet of 100 bombers against 200 missile launchers. Bombers have a 95% chance of shooting again after attacking a rocket. Thus, each bomber will attack 96 times on average, giving us 9600 attacks. Assume the defender was lucky and one rocket launcher survived. He also destroyed 10 bombers. We now have 90 bombers attacking one missile launcher, giving us another 8,640 rounds. Think of 100kg bombers and 200k launchers.

Do you have any suggestions for improving this model (performance)? How many times should I run it to get plausible average results?

Update

I think that I will probably stick to my modeling, because even if you found a mathematical solution for this, I would not understand it because of my current level of education.

Someone asked for more details.

Each level of correspondent technology increases the initial cost by 10%, but this is not important for modeling, so suppose that both players have 0 technologies. Let's look at the attacking fleet 1 "Cruiser vs. 2 missile launchers + 1 heavy laser." The cruiser has 2700 structural integrity, 50 shields and 400 weapons. I will write it as 2700: 50: 400

  • Cruiser 2700: 50: 400 x1
    vs
  • 200: 20: 80 x2 missile launcher
  • Heavy Laser 800: 100: 250 x1

The booster rocket and heavy laser do not have fast fire. The cruiser has 0 quick fire against a heavy laser and 10 against a missile launch, giving it a (10-1) / 10 = 0.90 probability of firing again after attacking a missile launcher.

One possible outcome could be the following:

round 1

the attacker attacks the defender

A cruiser from 2700: 50: 400 fires a Laucher rocket from 200: 20: 80; the result is Missile Laucher with -180: 0: 80

Quick fire:

  • The cruiser has fast fire against the Booster.
  • the bones were 0.62, compared with 0.90: Cruiser gets another shot.

A cruiser from 2700: 50: 400 fires a Laucher rocket from 200: 20: 80; the result is a missile launcher with -180: 0: 80

Quick fire:

  • The cruiser has fast fire against the Booster.
  • the bones were 0.09, compared to 0.90: Cruiser gets another shot.

A cruiser from 2700: 50: 400 fires at a rocket launcher from -180: 0: 80; the result is a rocket launcher with -580: 0: 80

Quick fire:

  • The cruiser has fast fire against the Booster.
  • the game was 0.83, compared with 0.90: Cruiser gets another shot.

Cruiser with 2700: 50: 400 lights on a heavy laser with 800: 100: 250; The result is Heavy Laser with 500: 0: 250

Quick fire:

  • The cruiser does not have fast fire against a heavy laser.

defender shoots the attacker

Missile Laucher with -580: 0: 80 fires on the cruiser from 2700: 50: 400; result is Cruiser from 2670: 0: 400

Missile launcher with fire -180: 0: 80 on a cruiser from 2670: 0: 400; result is Cruiser with 2590: 0: 400

A heavy laser with 500: 0: 250 lights on a cruiser with 2590: 0: 400; The result is a Cruiser with 2340: 0: 400

remove ships and restore shields

The cruiser still has integrity, restores its screen.

Rocket Laucher lost all its integrity, removed it from the battle.

Rocket Laucher lost all its integrity, removed it from the battle.

The heavy laser still has integrity, restores its screen.

round 2

the attacker attacks the defender

The cruiser from 2340: 50: 400 shoots with a heavy laser from 500: 100: 250; The result is Heavy Laser with 200: 0: 250

  • probability of explosion 75.00% (1-200 / 800): value in the bone 0.30 compared with 0.75: the unit exploded.
Result

is Heavy Laser with 9: 0: 250

Quick fire:

  • The cruiser does not have fast fire against a heavy laser.

defender shoots the attacker

A heavy laser with a fire of 9: 0: 250 on a cruiser from 2340: 50: 400; result is Cruiser from 2140: 0: 400

remove ships and restore shields.

The cruiser still has integrity, restores its screen.

The heavy laser lost all its integrity, removed it from the battle.

The battle ended after 2 rounds with the attacker's victory.

+4
source share
2 answers

For such quantities of units, I believe that it would be advisable to adopt a (kind of) statistical generalized approach.

Just summarize all statistics of units of this type, save the calculations, then calculate the total damage, full defense, remove the number of enemy units that were destroyed by damage as a percentage of the total defense.

I believe this is the approach used by Travian or other online strategy games. For such large numbers there is no effective way.

Special occasions

If the target structural integrity is below 30% of its original value, it has a 1-structureIntegrity / baseStructuralIntegrity probability for an explosion

I believe that you can use the Gaussian distribution to determine the number of blocks with extra spacing. The larger the value of ฯƒ , the greater the probability of failure.

Another approach would be to destroy the percentage of remaining ships. What a large percentage? Your choice.

Quick fire

Since you did not identify a quick fire, I cannot advise this. But I would suggest adding a special battle phase that takes this into account. You can also simply increase damage by a factor determined by the probability of a quick battle.

+3
source

I think your simulation should try to represent every unit acting independently and simultaneously. If so, you need to be very careful how you implement your modeling of each round. You do not want player 1 to have an advantage that can weaken or destroy opposition units, that they are less capable of retaliation just because their move is second. Therefore, all shield updates, integrity, and explosions must be stored and applied after both players have made their moves.

When you run the simulation, you will get the result that one or the other player won this battle. By running it an arbitrary number of times and calculating for player 1 wins / (wins + losses), you will receive an estimate of the percentage of times when player 1 would win taking into account the initial situation. It is like throwing a coin to determine if it is a fair coin (see Wikipedia).

You can also calculate the error score and use it to determine the confidence interval. This gives you a range of values โ€‹โ€‹that will contain the true probability that player 1 will win the script with an arbitrary percentage of the time (for example, 95%). If you want to be extremely confident that the range contains the true value and has a small margin of error, you will find yourself in the long night, since you will need to run many simulations. You will also need more simulations if the battle is evenly coordinated than if it were more one-sided.

I made some rough calculations according to the wikipedia article about throwing an honest coin. If you are satisfied with the 95% confidence interval and want the maximum error to be 0.01, you need 10,000 tests if the probability of winning is 50%. If it is only 25%, then you will need about 1350. If it is only 10%, you will need only 312. If you need a confidence interval of 99%, you will need about 3 times as many tests.

EDIT

I think that an analytical solution to this problem will be extremely difficult. I was going to suggest that you simplify your rules to make it more convenient.

Rule 3 - The requirement of minimum weapon strength to attack a specific shield is unlikely to greatly affect whether any structural damage will be inflicted on a unit unless one side is ahead of the other by 100: 1. Any small damage done if this rule was not in place, will be healed when the shields are restored at the end of the round. I suggest ignoring this rule.

Rule 6 - I think that if you have 100 blasters with a probability of 10% fast shooting, then this is the same (from the average damage done to an enemy point) to 110 blasters that do not shoot fast. Therefore, to calculate the effects of a quick fire, simply increase the average damage done by the percentage chance of a quick fire.

Rule 5 - This greatly complicates the situation, since now the difference in the values โ€‹โ€‹of structural integrity currently significantly affects how many units survive until the next round. Without this rule, you could simply work on using the average damage per unit to estimate the amount of damage done to the enemy, like the other suggestions given. If you would like to simplify this, I think that it will be similar to modeling units, which are 30% less than structural integrity in 85% of cases, which reduces the integrity of all units by 25.5%.

By doing this, you will essentially adhere to the Dariusz approach

 Eg if you have Side A: 100k bombers and 200k rocket launchers Side B: 130k bombers and 150k rocket launchers Expected total damage side A (ETDa) ETDa = 100k*BomberDamage*(1+rapidfire%bomber) + 200k*RLDamage*(1+rapidfire%rocketlauncher) This will be spread evenly between the units in side B based upon their percentage of the total number of units present. Expected total damage to bombers on side B (ETDBombersB) ETDBombersB = 130k/280k*ETDa Similarly ETDRocketLaunchersB = 150k/280k*ETDa Structural damage to bombers on side B is reduced by the amount of the bombers shields ESDBombersB = ETDBombersB - 130k*BombersShields Similarly ESDRocketLaunchersB = ETDRocketLaunchersB - 150k*RocketLaunchersShields Rather than have partly damaged units at the end of a round, I suggest you treat all existing units as fully healed, and apply the damage to units in turn until it is all used up. As above I am reducing the structural integrity by 25.5% to model the average chance of explosion. % of bombers destroyed = ESDBombersB / StructuralIntegrityBombers*(1-0.255)*130k % of rocket launchers destroyed = ESDRocketLauncherB / StructuralIntegrityRL*(1-0.255)*150k 

Also note that according to the central limit theorem, you are most likely to get an average result when you have more units in the simulation, the extreme amount of damage caused by one unit will decrease due to the low amounts that others do. That is, it is much more likely to get extreme values โ€‹โ€‹of 1 or 6 per cube when rolling it once, than to get 3 or 18 when rolling 3 times. Thus, this can make a statistically forged analysis still useful enough.

But if you are trying to simulate a situation in a real existing game, then the rules will be indicated, and you need to spend time working on a Monte Carlo simulation, as originally described, to get the most accurate result.

+1
source

Source: https://habr.com/ru/post/1484580/


All Articles