Combat Results

use an Array to store the Combat Results Table


// Combat Results Table values
var DE = 0;
var DR = 1;
var NR = 2;
var AR = 3;
var AE = 4;

this.combatResultsTable = new Array(
    new Array(DR, DR, DR, DE, DE, DE),
    new Array(NR, DR, DR, DR, DE, DE),
    new Array(NR, NR, DR, DR, DR, DE),
    new Array(AR, NR, NR, DR, DR, DR),
    new Array(AR, AR, NR, NR, DR, DR),
    new Array(AE, AR, AR, NR, DR, DR)
    );

During the combat setup phase, a click on a defending counter will setup the defender with unique combat number. Then, a click on an attacker will assign it the same combat number. A click on another defender will start a new combat.

During the combat resolution phase, a click on a defending counter will resolve the combat with the following:

total the attacking strength total and defending strength total with the combat number of the defending counter

find the combat ratio, (total attacker strength) / (total defender strength)

get the terrain adjustment from the Terrain object and apply it to the ratio

check the lower and upper limits of the ratio, this is the index number for the column in the table

use the random method to simulate a die roll, this is the die number for the row in the table

die = Math.floor(this.crt.dieSideCount * Math.random());

get the results from the array

results = this.combatResultsTable[die][index];

For C# code:

    int die;

    DateTime now = DateTime.Now;

    int seed = now.Millisecond;

    Random dieRoll = new Random(seed);

    die = dieRoll.Next(1, this.crt.dieMaxValue) - 1;

    results = this.combatResultsTable[die, index];