I'm trying to simplify a win/loss simulation. The situation is as follows:
Let's say there are two players A and B where:
- When A goes into a battle, it's probability of a win is 0.1 (10%)
- When B goes into a battle, it's probability of a win is 0.2 (20%)
Note 1 : The win probability is invariant to the opponent.
Note 2 : There are no draws, though there could be in a future enhancement, for now trying to keep things simple.
Note 3 : There are other players in the game each with their own probabilities.
If A and B were to battle each other I need to determine who will win.
Currently what I'm doing is sampling 2 different Bernoulli distributions, one for A (with $P_a = 0.1$) and one for B (with $P_b = 0.2$)
I sample each of the distributions until only one of them returns success. That player is the winner of the battle, the other player will have lost. The following is pseudo code of the process:
while (true)
{
bool win_a = bernoulli(pr_a);
bool win_b = bernoulli(pr_b);
if (win_a == win_b) // either both won or both lost
continue;
if (win_a)
return "A won";
else
return "B won";
}
The problem with the above approach is that even though it will eventually determine a winner, it may end-up looping for a long time before it does.
I was wondering if there's a mathematically valid way of combining the above probabilities into a singular Bernoulli trial such that $Pr(A_{winning})= k$ and $Pr(B_{winning}) = 1 - k$ for some particular k.
My current thinking is that $k = \frac{P_a}{(P_a + P_b)}$ but I'm not sure if it is correct or how to reason about it correctness.