= $toHit) { $hits++; } } return $hits; } function calculateDamageDone($army, $toHit) { $combatStrength = min(5, $army[0] + $army[1] + $army[3]); $hits = calculateHits($combatStrength, $toHit); $leaderReroll = min($army[2], $combatStrength - $hits); $hits += calculateHits($leaderReroll, $toHit); return $hits; } function takeDamage($army, $damage, $defender, $presses) { global $pressesAvailableToReduceElite; // while we have damage to process and units left in army while ($damage > 0 && $army[0] + $army[1] > 0) { // if we have more than 5 units, lose a regular if ($army[0] + $army[1] + $army[3] > 5) { // confirm we have a regular to lose if ($army[0] > 0) { $army[0]--; } // reduce an elite because no regulars to lose else { $army[1]--; $army[0]++; } } // if it's the defender, always reduce elites if possible elseif ($defender) { if ($army[1] > 0) { $army[1]--; $army[0]++; } // must kill a regular because no elites left else { $army[0]--; } } // we need to lose a regular below 5 or reduce an elite else { // if we have enough presses, it's OK to reduce an elite if ($army[1] + $presses >= $pressesAvailableToReduceElite) { // reduce an elite if ($army[1] > 0) { $army[1]--; $army[0]++; } // must kill a regular because no elites left else { $army[0]--; } } // we don't have enough presses, so lose a regular if possible else { // confirm we have a regular to lose if ($army[0] > 0) { $army[0]--; } // reduce an elite because no regulars to lose else { $army[1]--; $army[0]++; } } } // take the damage $damage--; } return $army; } function printGames ($start, $results) { global $tempSum; // rough error checking if ($start < 0 || $start > count($results)) { return; } echo " \n"; echo " ".($start)."\n"; echo " ".$results[$start]."\n"; $tempSum += $results[$start]; echo " ".$tempSum."\n"; echo " \n"; } $aMaxHP = $aArmy[0]+ 2*$aArmy[1]; $dMaxHP = $dArmy[0]+ 2*$dArmy[1]; $aResults = array(); $dResults = array(); $rResults = array(); $aVictory = array(); $dVictory = array(); $draw = array(); // do each choice of onslaught (TODO: Remove this) $onslaught = 0; $aResults[$onslaught] = array_fill(0, $aMaxHP + 1, 0); $dResults[$onslaught] = array_fill(0, $dMaxHP + 1, 0); $rResults[$onslaught] = array_fill(0, $freePresses + $aArmy[1] + 1, 0); $aVictory[$onslaught] = 0; $dVictory[$onslaught] = 0; $draw[$onslaught] = 0; for ($g = 0; $g < $GAMES; $g++) { // process the battle $aCurrent = $aArmy; $dCurrent = $dArmy; $pressesCurrent = $freePresses; $press = false; $rounds = 0; // can we press to next round? if ($pressesCurrent > 0) { $pressesCurrent--; $press = true; } elseif ($aCurrent[1] > 0) { // reduce an elite $aCurrent[1]--; $aCurrent[0]++; $press = true; } // while we have armies left while ($dCurrent[0] + $dCurrent[1] > 0 && $aCurrent[0] + $aCurrent[1] > 0 && $press) { $rounds++; $dDamageTaken = calculateDamageDone($aCurrent, 6); $aDamageTaken = calculateDamageDone($dCurrent, 5); $aCurrent = takeDamage($aCurrent, $aDamageTaken, false, $pressesCurrent); $dCurrent = takeDamage($dCurrent, $dDamageTaken, true, $pressesCurrent); // Do we need to press to the next round? if ($dCurrent[0] + $dCurrent[1] > 0) { // can we press to next round? if ($pressesCurrent > 0) { $pressesCurrent--; } elseif ($aCurrent[1] > 0) { // reduce an elite $aCurrent[1]--; $aCurrent[0]++; } // can't press any more else { $press = false; } } } // track the results. $aHP = $aCurrent[0] + 2*$aCurrent[1]; $dHP = $dCurrent[0] + 2*$dCurrent[1]; $aResults[$onslaught][$aHP]++; $dResults[$onslaught][$dHP]++; $rResults[$onslaught][$rounds]++; if ($aHP > 0 && $dHP == 0) { $aVictory[$onslaught]++; } elseif ($dHP > 0) { $dVictory[$onslaught]++; } elseif ($aHP == 0 && $dHP == 0) { $draw[$onslaught]++; $dVictory[$onslaught]++; } else { echo "LOGIC ERROR
"; } } // for each game ?>

A WotR FPMV Attempt Battle Simulation with trials

The attackers won times. The defenders kept the stronghold times,
including mutual destructions. The battles took an average of rounds.
Attacker HP
Remaining
Frequency Sum
Defender HP
Remaining
Frequency Sum


Reg Elite Leader
Attacker:
Defender:
Captains of the West:
Presses left before
reducing an Elite:
Trials:

Presses left before reducing an Elite controls how you take casualties. For example, if you have 2 regulars and 3 elites and need to take a casualty, should you reduce an elite or lose a regular? If you lose a regular, you're only rolling 4 dice, but you could potentially have an extra press.

Say you have 4 elites in your army, so you have 4 presses left. If "Presses left before reducing an elite" is set to 4 or lower, you'll reduce an elite when you need to take a casualty (and then you'll have only 3 presses left). If the value is set to 5 or higher, you'll lose a regular (reducing your combat strength below 5).

Of course, if you have more than 5 combat strength (including Captains of the West), the simulation will always take regulars as casualties first.

The attacker always fights until the defender is destroyed or there's no way to press any more.