About this program...

Here are the gory details of how math is used to calculate the exact theoretical probability. (Version 5.40+ version)

We create a probabilistic finite state machine. Each state is of the form

    (life1, life2, halfTurnNumber, attacker, attackersLeft, attacksLeft, otherCrippled, attackDice, targettingSame,
negated, enemiesToAttack, smoked/skipTurn, (blasted1, blasted2), adjacentWolves, (limiteduse1,limiteduse2), numEngaged)
So Each state keeps track of:
  1. life1: number hit points or units left in player #1
  2. life2: number hit points or units left in player #2
  3. halfTurnNumber: This goes from 1 to 6, the half-turn number
  4. attacker: This is either 1 or 2, which player is attacking.
  5. attackersLeft: This is the number of figures yet to attack in this turn; this is only relevant for squads
  6. attacksLeft: This is the number of attacks yet to be executed by the current attacking figure; this is only relevant for Double Attack ability (or Triple Attack). Note that you cannot lump attackersLeft and attacksLeft together because conceivably you could have a squad of figures with multiple attacks and it is possible a figure could be killed in the middle of its first attack.
  7. otherCrippled: This is 0 or 1. It is 1 if the other player has been crippled or EMPResponse activated, with order markers removed, or Cloud of Darkness activated with turns skipped until your next turn.
  8. attackDice: This number keeps track of any attack modifier for this turn. For example, this is used for Unleashed Fury, for Wait And Fire, Stinger Drain.
  9. targettingSame: This is 0 or 1. It is 1 after a figure has fired and the target has not been destroyed. This is needed for Zettian Targetting bonus
  10. negated: This is 0, 1, or 2. This keeps track of whether abilities have been negated by the Rod of negation. A 1 or 2 refers to which player has been negated. Note that both players cannot be negated simultaneously.
  11. enemiesToAttack: This is used for the simplified ShaolinAttack ability. This field should have value 0 or x, where x is the number of extra attacks the last attacker gets; so only needed whether attackersLeft > 0.
  12. smoked/skipTurn: For use with Smoke Powder. 0 = normal. 1 = smoked by defender and all normal attacks are skipped. For use with Eternal Hatred or Stinger Drain, 0 = normal, 1 = skip rest of turn (i.e. no attacks).
  13. blasted1 is the number of player2's unrevealed order markers that have been discarded, blasted2 is the number of player1's unrevealed order markers that have been discarded,
  14. adjacentWolves is the number of Wolves of Badru that are adjacent; this is used for the Pounce ability.
  15. limiteduse1 is the number of limited use weapons left for player1, such as Ullar's Bolt, WraithAttack drows. limiteduse2 is the number of limited use weapons left for player2, such as Ullar's Bolt, WraithAttack drows.
  16. numEngaged: Keeps track of number of engaged figures for use with Engagement Strike and Ice Spikes.
  17. We may need to keep track of more stuff in the future, as more abilities are invented
  18. The states are given an arbitrary indexing. For efficiency, it is likely best to use a hash (associative array) to assign a an index to each state.
There are also initial states and final states. There are 12 possible initial states, depending on which halfTurn and which player starts up. The final states keep track of who won, with how many hit points or units left.

After the list of states is made up, a big transition matrix is built. The rows and columns correspond to the states. So the size is the number of states (which could be well over a thousand). What is a transition matrix?

For each state State1, we calculate all the possible states that we can end up in after one attack (one set of dice rolls, including any Chomp or Gaze). The probability P that we land in state State2 is stored as an entry in the transition matrix in row State1 and Column State2. Call this transition matrix S. The part where we land in a final state is separated out into a matrix T. So S has dimension n x n and T has dimension n x m where m is the number of final states, and n is the number of non-final states.

Here is the math theory calculation...