Probability Programming Problem
Help me, please?
Problem:
3 shooters: A, B, C
Each has their own shooting accuracy:
A - 0.33%
B - 0.50%
C - 1.00%
They will engage in a shooting duel until only one is left standing. One shoots at a time. To compensate for the accuracy inequities of A & B...A will shoot first, B will shoot second, then C...and cycle repeats until there is a winner. Also, each shooter will always shoot at the person with the highest shooting accuracy first.
This is basically what I have thus far...of course I left out the non-trivial stuff
Code: Select all
Psuedo Code:
A.ShootsAtTarget(C);
if (C.isAlive()) {
B.ShootsAtTarget(C);
if (C.isAlive()) {
C.ShootsAtTarget(B) // B is now dead since C never misses
// Duel is now between A & C
... // more code
}
// C is DEAD...Duel is now between B & A
else ... // more code
}
// C is DEAD...Duel is now between A & B
else {
B.ShootsAtTarget(A);
... // more code
}
/* this basically sets the target (dueler) as dead if the random number
is less than or equal to the shooter's accuracy
*/
public function ShootsAtTarget(Obj target) {
ran_num = Math.random() // generate number between 0 & 1
if (this.accuracy <= ran_num) target.isAlive(false)
}
Am I going about this the right way?
Any help is appreciated.
Thanks