Ok! I have calculated the base probabilities. Code is here if you dare:

Next problem is working out how to navigate the tree of possible situations.

A battle situation is a defender attack/defense and a attacker attack/defense. There are 1296 possible situations, which is a pretty manageable number.

Each situation has a probablility of being a *loss* for the defender. The probability is equal to the probability of the loss given each number of possible hits, multiplied by the probability of getting that many hits.

If the number of hits is zero, you havben’t lost. Probability zero (whew!).

If the number of hits is more than your total amount of dice minus two (because you need to retain at least one attack and on defense die), then the loss probability should you get that many hits is 1. You have lost.

If not, then run through each way that you can distribute the hits, and then reverse the attacker/defender situation. Pick the highest loss probability of these sitiations. That’s the move you should make, and your loss probability for that many hits is the 1-p of the reversed situtation.

Now, this sounds staggeringly recursive, but it isn’t because as you calculate these situation probabilities you cache them. So meh. So how do we work out in what order to calculate these situations, such that for every situation we know that the reverse situation has already been done?

Well, one way is to order the situations by total number of dice.

The other way is to write it recursively, use caching as a recursion short-cut, ant let the algorithm do it in whatever sequence it prefers. That’s the easy way and that’s the way I’ll do it.

The remaining problem is: how to exhibit the results? Well, hopefully there will be a general rule eg: “if you have more dice than your opponent, take it off defense, else take it off attack”. Discovering that general rule is the point of the exercise.

Wrong, wrong, wrong.

If the number of hits is zero, then the probability of loss is the 1-p probability of loss for the reverse situation. The problem is that there’s a probability that the reverse situation will also have zero hits, and this creates an infinite recursion if we do it recursively.

Of course, we are crating a Markov Chain. Or network. I’ll have to look into it a trifle more closely.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: