To compute EV profit for all sub-problems, the recurrence relation is:
EV(i, j) = profit of state i attackers and j defenders.
profit(ii, jj, i, j) = the incremental profit for moving from state (i, j) to (ii, jj).
p(ii,jj) = probability of reaching state ii,jj from i, j
EV(i, j) = sum( all next states ii, jj) {
p(ii,jj) * profit(ii,jj, i, j) + EV(ii,jj)
}
This doesn’t consider that you might retreat in the future… to handle that:
EV(i, j) = sum( all next states ii, jj) {
p(ii,jj) * profit(ii,jj, i, j) + EV(ii,jj) > retreatThreshold ? EV(ii,jj) : 0
}
Initial state:
EV(i, j) = 0 for all terminal states. // e.g. 0 attackers or 0 defenders, or any retreat conditions met.
To compute Pwin for all sub-problems, the recurrence relation is:
Pwin(i, j) = probability of winning
Pwin(i, j) = sum (all next states ii, jj) {
isRetreat = Pwin(ii, jj) < threshold;
isRetreat ? 0 : p(ii,jj) * Pwin(ii,jj)
}
Initial state:
Pwin(i, j) = 1 or 0 depending on win conditions. E.g. if takes then at least one land unit attacker.