Note that there are some explanatory texts on larger screens.

plurals
  1. POSimulating a large battle
    primarykey
    data
    text
    <p>I have to simulate a battle between two players. It can last from one to six rounds. Attacker can have 13 different types of spaceships, defender - additional 9 types of defence structures. The thing is I'm going to limit the simulation to 1kk units on each side, so it's going to be pretty big.</p> <p>Every unit is going to be instance of the following class</p> <pre><code>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];} } } }; </code></pre> <p>Arrays for unchanging values.</p> <p>player1technolgies</p> <ul> <li>armour tech</li> <li>shield tech</li> <li>weapon tech</li> </ul> <p>player2technolgies</p> <ul> <li>armour tech</li> <li>shield tech</li> <li>weapon tech</li> </ul> <p>player1BaseStructuralIntegrity</p> <p>equall to default*armour tech </p> <p>And so on...</p> <p>Then I would propagate two lists with each player units. </p> <p>One round goes like that:</p> <ol> <li>Pick random unit // actually I don't think it matters if it's random or not</li> <li>Pick random target</li> <li>If weapon power is lower than 1% of target's shield it deals no damage</li> <li>Target's shields absorbs damage, rest of it goes to target's structural integrity</li> <li>If target's structural integrity is lower than 30% of its initial value, it has the probability of 1-structuralIntegrity/baseStructuralIntegrity to explode</li> <li>Check the probability of rapid fire, if it hits go to step 2</li> <li>Go to step 1 until all units attack | NOTE! Destroyed ships - with structural integrity below 1 can still be attacked. EDIT: they also can attack this round</li> <li>Repeat steps 1-7 for opponent.</li> <li>Remove destroyed ships</li> <li>Restore shields</li> </ol> <p>The battle lasts for six rounds or until one side is defeated.</p> <p>Lets consider an attacking fleet of 100 bombers vs 200 rocket launchers. Bombers have 95% chance to fire again after attacking rocket launcher. So every bomber will attack 96 times on average giving us 9600 attacks. Assume defender was lucky and one rocket launcher survived. He also destroyed 10 bombers. Now we have 90 bombers attacking one rocket launcher giving us another 8640 shots. Think about 100k bombers and 200k rocket launchers.</p> <p>Do you have any suggestions how to improove this simulation(performance)? How many times should I run it to get believable average results?</p> <h1>Update</h1> <p>I think I will probably stick to my simulation because even if you found a mathematical solution for this I wouldn't understand it due to my current education level.</p> <p>Someone asked for more details.</p> <p>Every level of correspondent technology increases initial value by 10%, but it's not important for simulation so assume both players have 0 technology. Let's consider an attacking fleet of 1 Cruiser vs 2 Missile Launchers + 1 Heavy Laser. Cruiser has 2700 structural integrity, 50 shield and 400 weaponry. I will write it as 2700:50:400</p> <ul> <li>Cruiser 2700:50:400 x1<br> vs </li> <li>Missile Launcher 200:20:80 x2</li> <li>Heavy Laser 800:100:250 x1 </li> </ul> <p>Missile Launcher and Heavy Laser don't have rapid fire. Cruiser has 0 rapid fire against Heavy Laser and 10 against Missile Launcher giving it (10-1)/10=<strong>0.90</strong> probability to fire again after attacking Missile Launcher.</p> <p>One possible outcome could be the following:</p> <h2>round 1</h2> <p><strong>attacker fires at defender</strong></p> <p>Cruiser with 2700:50:400 fires at Missile Laucher with 200:20:80; result is Missile Laucher with -180:0:80</p> <p>Rapid Fire:</p> <ul> <li>Cruiser has rapid fire against Missile Launcher. </li> <li>dice was 0.62, comparing with 0.90: Cruiser gets another shot. </li> </ul> <p>Cruiser with 2700:50:400 fires at Missile Laucher with 200:20:80; result is Missile Launcher with -180:0:80</p> <p>Rapid Fire:</p> <ul> <li>Cruiser has rapid fire against Missile Launcher.</li> <li>dice was 0.09, comparing with 0.90: Cruiser gets another shot. </li> </ul> <p>Cruiser with 2700:50:400 fires at Missile Launcher with -180:0:80; result is Missile Launcher with -580:0:80</p> <p>Rapid Fire:</p> <ul> <li>Cruiser has rapid fire against Missile Launcher. </li> <li>dice was 0.83, comparing with 0.90: Cruiser gets another shot. </li> </ul> <p>Cruiser with 2700:50:400 fires at Heavy Laser with 800:100:250; result is Heavy Laser with 500:0:250</p> <p>Rapid Fire:</p> <ul> <li>Cruiser doesn't have rapid fire against Heavy Laser. </li> </ul> <p><strong>defender fires at attacker</strong></p> <p>Missile Laucher with -580:0:80 fires at Cruiser with 2700:50:400; result is Cruiser with 2670:0:400</p> <p>Missile Laucher with -180:0:80 fires at Cruiser with 2670:0:400; result is Cruiser with 2590:0:400</p> <p>Heavy Laser with 500:0:250 fires at Cruiser with 2590:0:400; result is Cruiser with 2340:0:400</p> <p><strong>remove ships and restore shields</strong></p> <p>Cruiser still has integrity, restore its shield.</p> <p>Missile Laucher lost all its integrity, remove it from battle.</p> <p>Missile Laucher lost all its integrity, remove it from battle.</p> <p>Heavy Laser still has integrity, restore its shield.</p> <h2>round 2</h2> <p><strong>attacker fires at defender</strong></p> <p>Cruiser with 2340:50:400 fires at Heavy Laser with 500:100:250; result is Heavy Laser with 200:0:250</p> <ul> <li>probability of exploding of 75.00%(1-200/800): dice value of 0.30 comparing with 0.75: unit exploded. </li> </ul> <p>result is Heavy Laser with 9:0:250</p> <p>Rapid Fire:</p> <ul> <li>Cruiser doesn't have rapid fire against Heavy Laser. </li> </ul> <p><strong>defender fires at attacker</strong></p> <p>Heavy Laser with 9:0:250 fires at Cruiser with 2340:50:400; result is Cruiser with 2140:0:400</p> <p><strong>remove ships and restore shields.</strong></p> <p>Cruiser still has integrity, restore its shield.</p> <p>Heavy Laser lost all its integrity, remove it from battle.</p> <p><strong>The battle ended after 2 rounds with attacker winning.</strong> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload