Monday, August 10, 2020

Why run for President in Battlestar Galactica?

Because it's always better when you're in control.

Let's say that it's in the first half of the game, before the sleeper agent phase. It's a 5-player game and you think that everyone is human. Someone else is President. Why would you want to spend the action and cards necessary to make yourself President instead? Because one of you might become a Cylon.

Let's say all players are going to get one more loyalty card. So there are five cards, two of which are Cylon cards. The probability that one (or more) of you turns Cylon is $1 - P(\text{neither Cylon})$. $P(\text{neither Cylon}) = \frac{3}{5}\cdot\frac{2}{4}$. That is, one of you gets a human card ($3/5$), and then the other also gets one of the remaining human cards ($2/4$). Thus,
\begin{align}
P(\text{one or more of you become Cylon}) &= 1 - \frac{3}{5}\cdot\frac{2}{4} \\
&= 1 - \frac{3}{10} \\
&= 0.7.
\end{align}

Don't forget about the case where both of you end up as Cylons. Then resources are "wasted", and maybe you look suspicious. But maybe that's okay, because it's a good cover for depleted resources and allows you to stay hidden. But let's take this out, just assume that it's not valuable to switch here.

\begin{align}
\begin{split}
P(\text{one of you become Cylon}) &= P(\text{one or more of you become Cylon}) \\
& \phantom{= } - P(\text{both of you become Cylon})
\end{split}\\
\end{align}
\begin{align}
P(\text{one of you become Cylon}) &= 0.7 - \frac{2}{5}\cdot\frac{1}{4} \\
&= 0.7 - 0.1 \\
&= 0.6
\end{align}
Thus, it is more likely than not that you and the current President are going to end up on opposite teams, so you'd be better off having more power. The remaining question is whether or not you think the benefit is worth the cost.
Let's assign this a shorter variable, $p_1$, for use later on.
\begin{align}
p_0 &= P(\text{one of you become Cylon}) \\
&= 0.6.
\end{align}

I'll be honest in that I used to think it was inefficient to squabble about the Presidency unless you knew the President was a Cylon. But after a forum post about the importance of control in the game got me thinking about this case. It's interesting to me how the game is structured in this way that encourages loyal humans to do selfish things even without explicit personal goals (a la Dead of Winter). This is an interesting emergent property of the rules.

We've considered the case when there aren't any Cylons out, now let's look at having one Cylon out before the sleeper agent phase. There are three sub-cases: you're the Cylon, the President is the Cylon, someone else is the Cylon. We've already tacitly assumed above that if you or the President is or becomes a Cylon, it's worth it to take the Presidency. So those cases are taken care of. If someone else is a Cylon, then we're similar to the above analysis, but with a smaller probability that one of you becomes a Cylon in the sleeper agent phase. In this case there is only one Cylon card out of 4 left.
\begin{align}
P(\text{one of you become a Cylon}) &= 1 - P(\text{both of you stay human}) \\
&= 1 - \frac{4}{5}\cdot\frac{3}{4}\\
&= 1 - \frac{3}{4} \\
&= \frac{1}{4} = 0.25
\end{align}
Here the probability of one of you becoming a Cylon is much lower. One interesting case to consider here is if the existing Cylon gets the second Cylon loyalty card. In this case, the Cylon can then give this card to one of the humans. This is another opportunity for you or the current President to become a Cylon, and thus on opposite teams. Assuming this happens, and not knowing anything about the Cylon's strategy in selecting a target, there is a probability of $2/4 = 0.5$ that the Cylon selects you or the President out of the four humans. However, the President is arguably a higher-value target because of the powers of the office. For the rest of the analysis, we'll assume that a Cylon with two loyalty cards does give the second card away, with equal probability to all players. This increases the probability that one of you becomes a Cylon, $\Delta p = \Delta P(\text{one of you becomes a Cylon})$, is as follows.
\begin{align}
\Delta p &= P(\text{Cylon with two cards}) \cdot P(\text{Cylon gives card to one of you}) \\
&= \frac{1}{5} \cdot \frac{2}{4} \\
&= \frac{1}{10} = 0.1
\end{align}
Thus, our corrected probability for one of you becoming a Cylon is,
\begin{align}
P(\text{one of you become a Cylon}) &= 0.25 + 0.1 \\
&= 0.35.
\end{align}
As before, let's assign this a shorter variable, $p_1$, for use later on.
\begin{align}
p_1 &= P(\text{one of you become a Cylon}) \\
&= 0.35.
\end{align}

Now, let's consider the case when two Cylons are out, which I'd argue doesn't depend on when in the game it occurs. (I choose my words carefully here. I would argue this if pressed, but I'm not going to because I'm lazy.) There are four sub-cases: you are a Cylon, the President is a Cylon, both of you are Cylons, neither of you are Cylons. In the first two cases, it makes sense to get the Presidency, as you and the President are on opposite teams. If neither of you are Cylons, it doesn't make sense (unless the President isn't using the office well). If both of you are Cylons, I'd say in general it doesn't make sense, unless the President is already suspected and you can keep the office on your team by taking it.

What is the confidence (i.e. assessed probability) you must have that a third party is a Cylon to make it not worth while to go for the presidency? As a break-even point we could assign a probability of 0.5. A better approach would be to have values assigned for the benefit of taking the presidency from the opposing team as well as the cost of moving the presidency. Determining those values is beyond the scope of this analysis, so we'll stick with a probability threshold of 0.5, meaning we're looking for the point at which it's more likely than not that you have incentive to take the presidency. This critical point occurs according the following equation.
\begin{align}
0.5 &= p_0 \cdot P(\text{no Cylons}) + p_1 \cdot P(\text{one Cylon}) + 0 \cdot P(\text{two Cylons})\\
&= 0.6 \cdot P(\text{no Cylons}) + 0.35 \cdot P(\text{one Cylon})
\end{align}
I included the two Cylon case to point out that the no and one Cylon cases are not the only possibilities. There's no $1-p$ type tricks here in general. Now, if we do assume that there is at most one other Cylon, then we condition becomes easier to conceptualize. Then it simplifies as follows.
\begin{align}
0.5 &= 0.6 \cdot (1 - P(\text{one Cylon})) + 0.35 \cdot P(\text{one Cylon}) \\
&= 0.6 + (-0.6 + 0.35) \cdot P(\text{one Cylon}) \\
&= 0.6 + -0.25 \cdot P(\text{one Cylon}) \\
P(\text{one Cylon}) &= \frac{0.6-0.5}{0.25} \\
&= 0.4
\end{align}
Here, as long as we believe the probability of one Cylon is 0.4 or less (and the probability of two is zero), then we're more likely than not to end up and opposite teams as the President, even though we are both presently human, and thus have reason to take it.

As a reference it may be useful to know the probability of each of those cases (and the previous cases we've considered). If you have a human card, and you're sure that the President is also human, you know there are two Cylon cards and six human cards left. Three of those cards have been dealt, while five remain for later.
\begin{align}
P(\text{all humans}) &= \frac{6}{8} \cdot \frac{5}{7} \cdot \frac{4}{6} \approx 0.357 \\
P(\text{one cylon}) &= \frac{6}{8} \cdot \frac{5}{7} \cdot \frac{2}{6} \cdot\underbrace{3}_{{\text{3 ways to assign Cylon}}} \approx 0.536 \\
P(\text{two cylons}) &= \frac{6}{8} \cdot \frac{2}{7} \cdot \frac{1}{6} \cdot (\text{3 choose 2 ways to assign cylons) }\\
& = \frac{6}{8} \cdot \frac{2}{7} \cdot \frac{1}{6} \cdot \underbrace{3}_{= \frac{3!}{2! \cdot 1!}} \approx 0.107
\end{align}
Check, does that add up to one? Yes. We can combine this to find the probability that you and the President will end up on opposite teams, given that you start off as human (without any assumptions about the other players.
\begin{align}
p &= p_0 \cdot P(\text{no Cylons}) + p_1 \cdot P(\text{one Cylon}) + 0 \cdot P(\text{two Cylons})\\
&\approx 0.6 \cdot 0.357 + 0.35 \cdot 0.536 + 0 \cdot 0.107 \\
p&\approx0.402
\end{align}
Thus, without any information pertaining to the loyalty of the other players, you're more likely than not to stay on the same team as the President. However, perhaps counter-intuitively, if you feel you can trust everyone, you're more incentivized to go for the presidency yourself.

And what if you're not certain that the President is human? What if all you know is that you're human. Given that, there's a probability of $P(HH|H) = 7/9$ that the President is human with a probability of $P(CH|H) = 7/9$ that is a Cylon with probability $2/9$. Here $P(HH|H)$ refers to the probability that both the President and you are human given that you are human. Similarly, $P(CH|H)$ is the probability that the President is Cylon (now) and you are human (now) given that you are human (now). We can express the probability that you and the President end up on opposite teams given that you are human, $P(O|H)$ as follows. Here $O$ refers to the event that you and the President end up on opposite teams. We're still focusing on opposite teams, and ignoring possible benefits to the Cylons if resources are expended moving the presidency.
\begin{align}
P(O | H) = P(O | HH) \cdot P(HH | H) + P(O | CH) \cdot P(CH | H)
\end{align}
We previously computed $P(O|HH)$, which is the $p$ immediately above.

Now let's find $P(O|CH)$, the probability that you and the President end up on opposite teams given that the President is a Cylon before the sleeper agent phase while you are human. There are similar cases to before. There are two ways that the two of you can remain on opposite teams. First, another player can receive the remaining Cylon card. Since there are five players and five loyalty card, only one of which is Cylon, everyone has the same probability of receiving the Cylon card. Thus, another player receives the Cylon card with probability $3/5$. Second, the President can receive the Cylon card (probability $1/5$) and give it to another player aside from you. Assuming the President gives it out randomly, the probability that this happens and you remain human is $\frac{1}{5}\cdot\frac{3}{4}$.
\begin{align}
P(O|CH) &= \frac{3}{5} + \frac{1}{5}\cdot\frac{3}{4} \\
&=\frac{12+3}{20}\\
&=0.75
\end{align}
Pulling everything together, we get the following.
\begin{align}
P(O | H) &\approx 0.402 \cdot \frac{7}{9} + 0.75 \cdot \frac{2}{9}\\
&\approx 0.479
\end{align}

This is much closer to 0.5, but still less. So given that you're human before the sleeper agent phase, you're just slightly more likely than not to end up on the same side as the president, given all of the assumptions that we've made. However, once you get some information about how the other people are playing, you can throw out most of the probabilities regarding the current state of the game, and only pay attention to those that affect the future of the game. Individual behavior can be much more revealing than statistics.

Monday, August 3, 2020

Is it possible an event is never drawn?

A deck of cards with values in a 2d3 distribution (so a single card with a value of 2, two value 3 cards, etc) and a 10th reshuffle card. On a reshuffle card, draw a replacement card, until you get a value (ie not the reshuffle) card. I was going to add another card that has a specific in-game event, and was trying to work out how likely it was that card would appear before the game ends (about 50 draws, not tied to the cards): I think it is possible, albeit unlikely, that it may not appear to all (although the longer the game goes on, the less likely that is, from my understanding of probabilities).

—paraphrased from here on BGG

This can be solved with a Markov chain, which is a way to model sequences of probabilistic events, where the probabilities involved can be expressed in terms of the state after the previous step in the sequence. In this case, the state represents what's still in the deck. We'll have a different state for each possible number of cards remaining in the deck 11 (only possible before first turn), 10, 9, ..., and 1. The last we'll use as a special state, primarily not to denote when one card is left, but the fact that an event has been drawn. For simplicity, I'll not keep track of how many events have occurred (although we could expand to include that).


So we need a vector representing the probabilities of the initial state, which is known to be 11 cards, so the state vector, $\mathbf{s}$.

\begin{align} \mathbf{s} = \begin{bmatrix} 1\\ 0\\ 0\\ 0\\ 0\\ 0\\ 0\\ 0\\ 0\\ 0\\ 0 \end{bmatrix} \end{align}

Here each subsequent entry in the vector represents a different state, and the values are the probabilities of being in each state.


We also need the transition matrix. That is, given a state, what are the probabilities of moving to another state. Consider when there are $c$ cards left. There are three or four relevant possibilities, depending on how you count.

  1. You could draw a number card, leaving $c-1$ cards, which occurs with probability $(c-2)/c$.
  2. You could draw a shuffle card (probability $1/c$, and then draw a number card (probability $9/10$, as we can ignore drawing the shuffle card again), leaving 10 cards with probability $1/c \cdot 9/10$.
  3. You could draw an event card, with probability $1/c$, and end up in the special event state (by our reckoning).
  4. You could draw a shuffle card (probability $1/c$) and then draw the event card (probability $1/10$), and end up in the special event state with probability $1/c \cdot 1/10$.

We can combine 3 & 4 to find the total probability of getting an event, which is $1/c + 1/c\cdot1/10 = 1/c \cdot 11/10$.


For the first round the probabilities are a little bit special, as we have 11 cards. Thus, the shuffle card doesn't do anything but delay the game. The two possible outcomes are draw a number card (probability $9/10$) and draw an event card (probability 1/10).


Putting this together, we have the transition matrix, $\mathbf{P}$. Each column represents the initial state, and each row represents the next state, in both cases starting with 11 remaining cards, descending to 2, and ending with the special event state.

\begin{align} \mathbf{P}& = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \frac{9}{10} & \frac{9}{10}\cdot\frac{1}{10} & \frac{9}{10}\cdot\frac{1}{9} & \frac{9}{10}\cdot\frac{1}{8} & \frac{9}{10}\cdot\frac{1}{7} & \frac{9}{10}\cdot\frac{1}{6} & \frac{9}{10}\cdot\frac{1}{5} & \frac{9}{10}\cdot\frac{1}{4} & \frac{9}{10}\cdot\frac{1}{3} & \frac{9}{10}\cdot\frac{1}{2} & 0 \\ 0 & \frac{8}{10} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & \frac{7}{9} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & \frac{6}{8} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & \frac{5}{7} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & \frac{4}{6} & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \frac{3}{5} & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{4} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{3} & 0 & 0 \\ \frac{1}{10} & \frac{11}{10}\cdot\frac{1}{10} & \frac{11}{10}\cdot\frac{1}{9} & \frac{11}{10}\cdot\frac{1}{8} & \frac{11}{10}\cdot\frac{1}{7} & \frac{11}{10}\cdot\frac{1}{6} & \frac{11}{10}\cdot\frac{1}{5} & \frac{11}{10}\cdot\frac{1}{4} & \frac{11}{10}\cdot\frac{1}{3} & \frac{11}{10}\cdot\frac{1}{2} & 1 \\ \end{bmatrix} \end{align}

Note a check that we can do is that each column must sum to 1. That is, the probability of transitioning from one state to one of the states is 1. This is because all possible states are incorporated in the matrix.


To find the probability of each state in round $r$, we just compute $P^r \cdot s$. I've done this for 1–100 rounds below. It's quite rare for a game of 50 rounds to have no events. Also note that after about 10 rounds we seem to have reached a stable condition, where the probabilities of being in each of the states isn't changing much (relative to total probability of not having had an event yet).


Figure 1: Probabilities of having some and no events


Figure 2: Probabilities of having no events, log scale


We can expand this solution to not only look at the probability of whether or not an event has occurred, but instead to look at the probability of an event in any given round. The most straightforward application of the previous method would be to (nearly) multiply the number of states by the number of events possible (i.e. the number of rounds). This keeps track of however many events that we may be interested in, just as we've kept track of the binary state of whether any events have occurred. However, this is very inefficient and quickly leads to very large matrices. Instead, we can take note of the fact that if we look at the current round, the only thing that affects whether we draw an event is whether it is still in the deck, not how many times we've drawn an event previously. Thus, we can merely (roughly) double the number of states, with about half corresponding to the cases where the event card is in still in the deck, and the rest corresponding to the cases where the event card has already been drawn. The first state is again one with 11 cards left, which is equivalent to the case when there is 1 card left. If one card is left, it must be the reshuffle card, which, when drawn at the beginning of the next round, then leaves 11 cards just as at the start of the game. The next 9 states are when 10–2 cards remain in the deck, including the event card. The final 9 states are when 10–2 cards are left in the deck, but the event card is not in the deck.



The probabilities are much as before, except that we now broken up cases 3 & 4 from above, and we consider the transitions between the various number of possible cards left in the deck without the event card. The probability of decreasing by one card in the deck, both without the event card, is the probability of not drawing the reshuffle card, $(c-1)/c$. Also note that when there are two cards left there's a probability of $0.5$ that the reshuffle card remains. This is equivalent to the the initial state of having 11 cards, as previously mentioned, as is why the probability of moving from the two 2-card states to the 11-card state is $1/2$.


From any of these states, we can compute the probability of drawing a card. This actually is equal to the sum of elements of the matrix we just constructed. We need to sum the elements which correspond to moving from a state with the event card in the deck to one without it. This includes the cases when the reshuffle card is drawn. To this we must add the cases when the event card is initially out of the deck, the reshuffle card is drawn, and finally the event card is drawn. That is, the 11th row all counts. We must also consider the $1/2$ probability that we go from 2 cards with event to 11 cards left, as this really represents drawing the event card and leaving only the reshuffle card in the deck. Using this we can construct a matrix, $\mathbf{G}$, with all of these probabilities are the elements, such that when we multiply it by any probabilistic state vector, we get the probability of drawing an event card from that state.


Using these three we can find the probability of drawing an event in any round.

\begin{align} P(\text{event in round } r) = G P^r s \end{align}

The result of this equation is plotted in Fig. 3. We see a perhaps somewhat unexpectedly consistent result that appears to be exactly equal to 0.1. But is it? Does this continue forever? We can certainly easily compute the probability for any practical number of rounds, and any deviation from exactly 0.1 in our computations appears to be due to computer rounding error.


Figure 3: Probabilities of drawing an event in current round


So let's prove it. First, we'll quickly dispense with the simple case when there are 11 (or 1) cards left in the deck. Here we must end by drawing a non-reshuffle card, of which there are ten with only one being an event. Thus the probability of drawing an event given that there are 11 cards left is $1/10$.

\begin{align} P(\text{event} | C = 11) = 0.1 \end{align}

Note a slight change in notation here. After writing the above equation, it became obvious that the number of cards left is really a random variable, and hence the switch to a capital $C$. The rest of the cases rely on some observations about the relationship between having an event card in the deck and not when there are given number of cards, $c$, left in the deck. That is, given $C$, what is the probability that the event card is still in the deck?

\begin{align} P(\text{event in deck} | C = c) = ? \end{align}

Let's consider how we get to having $c$ cards left at the beginning of a round. For this to happen, in the rounds immediately preceding the $11-c$ cards not in the deck must have been drawn. What is the probability of doing that while leaving the event card in the deck? Keep in mind that this is conditioned on not drawing the re-shuffle card in any of these rounds.

\begin{align} P(\text{draw value} | \text{don't shuffle}, C=c) = \frac{c-2}{c-1} \end{align}

We need to multiply this term depending on the number of cards left.

\begin{align} P(\text{event in deck} | C = c) &= \prod_{i=11}^{c-1} \frac{i-2}{i-1} \\ \require{cancel}&= \frac{\cancel{9}}{10} \cdot \frac{\cancel{8}}{\cancel{9}} \cdot \frac{\cancel{7}}{\cancel{8}}\cdots \frac{\cancel{c}}{\cancel{c+1}} \frac{c-1}{\cancel{c}} \\ &= \frac{c-1}{10} \end{align}

The probability of drawing an event depends on whether or not the event card is still in the deck. These probabilities largely follow from our initial analysis.

\begin{align} P(\text{event} | \text{event in deck}, C = c) &= \underbrace{\frac{1}{c}}_{{\text{draw event directly}}} + \underbrace{\frac{1}{c}\cdot\frac{1}{10}}_{{\text{draw reshuffle then event}}} \\ P(\text{event} | \text{event not in deck}, C = c) &= \underbrace{\frac{1}{c}\cdot\frac{1}{10}}_{{\text{draw reshuffle then event}}} \end{align}

When the event is not in the deck, the only way to draw it again is to first draw the reshuffle. Putting these together we can find the following.

\begin{multline} P(\text{event in deck} ) = P(\text{event} | \text{event in deck}) \cdot P(\text{event in deck}) \\+ P(\text{event} | \text{event not in deck}) \cdot \left ( 1 - P(\text{event in deck} ) \right ) \end{multline}

In our case (conditioning on $C=c$), we can find what we're looking for.

\begin{align} P(\text{event in deck} | C = c) &= \left (\frac{1}{c} + \frac{1}{c}\cdot\frac{1}{10} \right ) \cdot \frac{c-1}{10} + \frac{1}{c}\cdot\frac{1}{10} \cdot \left ( 1 - \frac{c-1}{10} \right ) \\ &= \frac{1}{c} \cdot \frac{11}{10} \cdot \frac{c-1}{10} + \frac{1}{c} \cdot \frac{1}{10} \cdot \frac{11-c}{10} \\ \require{cancel}&= \frac{11\cancel{c}}{100\cancel{c}} - \cancel{\frac{11}{100c}} + \cancel{\frac{11}{100c}} - \frac{\cancel{c}}{100\cancel{c}} \\ &=\frac{11}{100} - \frac{1}{100} \\ &= \frac{10}{100} \\ &= \frac{1}{10} \end{align}

Here we see that, indeed, regardless of how many cards there are in the deck, the probability of drawing an event always works out to be exactly 0.1. Here two effects exactly cancel each other out. On the one hand, when there are fewer cards, it's more likely to draw an event card that is still in the deck. On the other hand, with fewer cards it's less likely that there the event card still is in the deck.


There is yet a simpler way to see that the probability of drawing an event every round is 0.1. Consider the symmetry of the situation. Every round ends with a non-reshuffle card being drawn. There is no difference in the 10 non-reshuffle cards that impacts the probability of them being drawn. Therefore, the probability that each is drawn in any round must be 0.1. You may ask whether drawing the event card affects the probability of it being drawn in a subsequent round. It does; that effect shows up in certain conditional probabilities.

Monday, July 27, 2020

What is the best weapon in D&D?

There's something interesting about the damage progression for the Monk class in D&D 3.5. For a Medium sized Monk, the damage progression is as shown in Table 1 (source: SRD http://www.d20srd.org/srd/classes/monk.htm).

\begin{align*}
\begin{array}{c|c}
\text{Level} & \text{Damage Dice} \\ \hline
\text{1--3} & 1d6 \\
\text{4--7} & 1d8 \\
\text{8--11} & 1d10 \\
\text{12--15} & 2d6 \\
\text{16--19} & 2d8 \\
\text{20} & 2d10
\end{array}
\end{align*}
Table 1: Monk Damage Progression in D&D 3.5

For levels 1–11 things are pretty clear. Each time the damage dice increase it's strictly better. However, that's not true when moving from 1d10 to 2d6. Certainly, the minimum and maximum are both higher for 2d6 (2 and 12, respectively, as opposed to 1 and 10 for 1d10). The average is also better: 7 versus 5.5. But often we don't care about such metrics. For example, say our Monk is fighting some opponents that each have 5 hit points each. In such as case, we'd like to take them out in one hit as often as possible. Thus, the probability of rolling 5 or higher is of particular interest.

To consider the general case, let's look at the probabilities of rolling a given number or higher for each of the two damage rolls, as shown in Table 2.
\begin{align*}
\begin{array}{ccc}
x & P(1d10 \geq x) & P(2d6 \geq x) \\ \hline
1 & 1 & 1 \\
2 & 0.9 & 1 \\
3 & 0.8 & 0.972 \\
4 & 0.7 & 0.917 \\
5 & 0.6 & 0.833 \\
6 & 0.5 & 0.722 \\
7 & 0.4 & 0.583 \\
8 & 0.3 & 0.417 \\
9 & 0.2 & 0.278 \\
10 & 0.1 & 0.167 \\
11 & 0 & 0.0833 \\
12 & 0 & 0.0278
\end{array}
\end{align*}
Table 2: Monk Damage Probabilities at Levels 11 & 12

This is actually strictly better. But it makes you wonder whether there are cases where it looks like something is better, but it's actually worse. If we had looked at the pmf for 1d10 vs 2d6 we might have been misled, because at 10, 2d6 looks worse (lower probability of getting a 10), even though it is strictly better when considering the probability of rolling 10 or higher.

So let's change the question to be about the best weapon. There are many different weapons in Dungeons and Dragons. Even just looking at the 5th edition Player Basic Rules download, there is almost a full page table on page 47. Weapons differ in cost, dice rolled for damage, type of damage dealt, weight, and properties such as whether it is thrown, requires two-hands to use, etc..

To contain the discussion, let's first just focus on which does the most damage. A lot of the other characteristics of the weapon matter in very context-specific ways. Glancing through the table it's pretty easy to narrow down the list into two potential groups. Those weapons which do 1d12 damage (e.g. a greataxe), and those which do 2d6 damage (i.e. a maul). Both can do up to 12 damage. The maul always does at least 2 damage, so that's better. What about average damage? The average roll for a dN is $(N+1)/2$. This means the average greataxe damage is 6.5, while the average maul damage is 7.

Let's compare the distributions. We've already computed 2d6 for something else. 1d12 is pretty simple, $1/12$ for every possibility. Fig. 1 shows the probability mass functions (PMFs), while Fig. 2 shows the cumulative distribution functions (CDFs). We see some cases in which 2d6 is better, while in some cases 1d12 is better. Look at rolling at least a specific number, that's what matters, which is close to the complementary cumulative distribution function (CCDF), which is plotted in Fig. 3. Here we see that the probability of rolling towards the higher end of the damage distribution with a greataxe is greater than with a maul. Consider just the probability of rolling 12 or higher. With a greataxe the probability is $1/12$, with a maul it's $1/36$.

Figure 1: Damage PMF of Greataxe and Maul 

Figure 2: Damage CDF of Greataxe and Maul

Figure 3: Damage CCDF of Greataxe and Maul
Now let's consider enemies with different number of hit points. We'll look at three possibilities: a goblin with 7 HP, a hobgoblin with 11 HP, and a bugbear with 27 HP. We can find the probability of eliminating each of these enemies in a single round by evaluating the CCDF at one less than the number of HP. This is impossible for the bugbear, as there's no way to roll 27 damage in a single attack with these weapons (Note: throughout this analysis I'm ignoring any bonuses that may increase the damage. I'm also ignoring whether or not you actually hit first). For the goblin, looking at the CCDF at 6, we see that the maul has a higher probability of being eliminated in a single round. For the hobgoblin we get the opposite result. The CCDF at 10 is higher for the greataxe.

Looking at just the probability of elimination in the first round is a small part of the analysis. Next, we'll look at the distribution of the the round in which the target is eliminated, $R$. To determine this, we need a straightforward way to check whether or not we've eliminated a target in a given round. In this case, I found it easier to look at the CDF of elimination, that is, the probability that the target is eliminated by a certain round of combat. In round $r$, we've rolled damage for each weapon $r$ times. If the damage if at least equal to the target's HP, then it must have been eliminated by round $r$. We previously learned how to use convolution to compute the PMF of rolling multiple dice. We can apply this iteratively to get the PMF of rolling $r$d12 for a greataxe or $2r$d6 for a maul in total by round $r$. Performing the running sum to get the CDF from the PMF is straightforward. Then the CDF of the round of elimination, $F_R(r)$, is given by,
\begin{align}
F_R(r) = 1 - F_{D(r)}(h-1) ,
\end{align}
where $D(r)$ is the total damage by the relevant weapon by round $r$ and $h$ is the number of hit-points of the target. Running through the computations for our selected targets we get the plots in Figures 4, 5, and 6. We can see that the maul is almost universally better. The two exception points are the aforementioned eliminating a hobgoblin in 1 round, as well as the probability of eliminating a bugbear in 3 rounds.

Figure 4: Probabilities of eliminating a goblin by a given round 
Figure 5: Probabilities of eliminating a hobgoblin by a given round
Figure 6: Probabilities of eliminating a bugbearby a given round
While we risk the danger of the reductionism we saw earlier in looking at the average damage per roll for each of the two weapons, and noting that perhaps the result is obvious given the above distributions, there remains some allure in combining the above information into a single metric with which we can compare the two weapons and declare which is the best definitively, if not correctly. To accordance with this, we'll compute the expected value of the number of rounds to eliminate a target, $\mathbb{E}R$. We'll do this not just for the selected targets, but for a wide range of hit points, from 1 to 1000 (I did not compute every point in between, and started log spacing after 20 hit points to save time). To do this, two steps are required. First, we must find the CDF for each hit-point valued target. Second, we recall and use the following relationship to calculate the expected value.
\begin{align}
\mathbb{E} R &= \sum_{r=0}^\infty P(R > r) \\
&= \sum_{r=0}^\infty 1 - F_R(r)
\end{align}
We can combine this with our earlier equation for $F_R(r)$ to come up with a simpler expressoin based on the CDF of the total damage up through round $r$.
\begin{align}
\mathbb{E} R &= \sum_{r=0}^\infty 1 - (1 - F_{D(r)}(h-1) ) \\
& = \sum_{r=0}^\infty F_{D(r)}(h-1) \\
\end{align}
While the above sum is shown over an infinite range, we know that it is limited. In the case of the greataxe, since we do at least 1 damage per round, we need only consider up to $h$ rounds. Similarly, for the maul, which does at least 2 damage per round, we need only consider up to $\lfloor \frac{h}{2} \rfloor$ rounds. The results are plotted in Fig. 7. While it's hard to see for low values of the target's HP, it clearly shows that the maul requires fewer rounds, on average, for any number of hit points.

Figure 7: Expected number of rounds to eliminate a target vs. hit points

One might propose the following argument to approximate the number of rounds expected for elimination. Since we know the average damage per roll, all we must do is to take the target's HP and divide by this average damage to find the expected number of rounds to elimination. To aid in discussion of this thought, consider the plot in Fig. 8, which shows the expected number of rounds to elimination per target HP. Also plotted are asymptotes, which are equal to one divided by the average damage per round. That is, if this argument were true, the plot would coincide with these dotted lines. It is not true, and thus they do not coincide. However, they do seem to predict values which the curves are approaching asymptotically, as emphasized in Fig. 9. For a small number of hit points, the non-linear impacts of needing to roll a whole number of attacks means that the inverse of the average is a poor estimate. For example, to eliminate a target with only 1 HP, at 1 round is always needed. An attempt to incorporate this is shown in Fig. 10, which shows estimates of the $R$ per HP, by estimating $R$ as HP divided by the average damage per round, rounding up to the nearest integer number of rounds, and then dividing by HP. We can see that this shows a similar shape, but has discontinuities at various points, corresponding to when the number of rounds is rounded up to the next integer value. If we consider a target like the hobgoblin with 11 HP, there are a number of possible rounds of elimination. To determine $\mathbb{E}R$, first the distribution of $R$ is considered and then averaging is done. The plot in Fig. 10 averages first, and then tries to come up with the number of rounds. Since there is essentially non-linearity involved, we cannot change the order of the averaging without introducing error. The nonlinearity I'm talking about is this: in the round of elimination there may be some excess damage done. Going into that around you may only need to do 3 more points of damage, but it's likely that more damage will be done. Thus, this damage, while it contributes to the average damage per round, does not affect the number of rounds until elimination. As the number of hit points that a target has increases, this excess damage becomes less and less of an impact, which is why the plots approach the asymptotes. Across these plots we see that the maul is universally better than the greataxe.

Figure 8: Expected number of rounds per hit-point to eliminate a target vs. hit points 

Figure 9: Expected number of rounds per hit-point to eliminate a target vs. hit points (zoomed in)
Figure 10: Expected number of rounds per hit-point to eliminate a target vs. hit points compared to a crude estimate\label

That was a little disappointing. I was really expecting to find some scenarios where the greataxe is better. Sure, if we really need to eliminate a hobgoblin in 1 round it's better, but that's too specific to satisfy me. The consistency provided by rolling 2d6 just seems to overpower the slightly better chance of a high roll on 1d12. So what if we compare against something that we might expect to be worse. What if we compare 1d12 to 2d4? When we look at the same comparison, shown in Fig. 11, we see that for target HP less than 5, rolling 2d4 results in a faster expected elimination. Here, the higher minimum appears to prevail over the lower average damage, the latter of which wins for large target HP.

Figure 11: $\mathbb{E}R$ for 1d12 and 2d4

Monday, July 6, 2020

Modeling value in Century: Spice Road

When playing Century: Spice Road (or the Golem Edition, I imagine), it's easy to notice some patterns in the values of the cards.

The Merchant cards are less clear, so let me push them aside first. Not all Merchant cards are equal. Some comparisons are hard to make and depend a lot on the situation. For example, is it better to have a card that transforms 2 saffron (red) into 2 cardamom (green), or 3 saffron into 3 cardamom? If you only have two saffron, the first may be better. With three it's likely the latter. With four saffron we're back to likely preferring the first, as we can perform the trade twice. That is, unless we only need three cardamom and need to hold onto a saffron. You could perhaps come up with some metric that attempts to incorporate all of these types of considerations. However, there's a clear counter example. There's one Merchant card that gives you three turmeric (yellow) and another that gives you four. The latter is strictly better than the first. Even if you can't always make use of the fourth turmeric, it is all that the first card is and more. This one example is all we need to show that Merchant cards are not all balanced.

Now let's look at the Point cards.

Figure 1: Points cards

The pattern I noticed when looking at a bunch of these is that it appears that the number of points, $p$, follows a simple formula based on the number of turmeric (yellow), $y$, saffron (red), $r$, cardamom (green), $g$, and cinnamon (brown), $b$.
\begin{align}
p = y + 2r + 3g + 4b
\end{align}
That is, the number of points is equal to one point for each turmeric, while each higher level of spice is worth one more point each. This tracks for a large number of the Point cards (24 out of 36). Then you run into a card like the following.

Figure 2: Another Point card

Here we'd predict the card to be worth 12 points.
\begin{align}
12 = 1 \cdot 3 + 2 \cdot 1 + 4 \cdot 3 + 4 \cdot 1
\end{align}
However, it's worth two additional points. Why? If you look at this spreadsheet, posted by "GameSnake", it becomes quite clear what the pattern is. There's a column specifying the "Spice cost", matching our analysis up to this point, as well as a "Delta" column. This clearly shows that a Point card is worth an extra point if it requires three different types of spices to claim, and two extra points if it requires four different types of spices. This makes some sense, as it may be more difficult to produce a variety of different spices than just having a good combination to produce exclusively one or two. There's no difference between cards that require only one type of spice and cards that require two types of spice. So our revised equation becomes,
\begin{align}
p = y + 2r + 3g + 4b + \max(n-2, 0) ,
\end{align}

where $n$ is the number of distinct spices needed to claim the Point card. Note that $n$ is dependent on $y$, $r$, $g$, and $b$. We could write an equation without this intermediate variable, but it'd be quite a bit more cumbersome. This equation exactly predicts the value of every Point card in the game, which you can check against in Table 1.


Spices
Victory points Spice cost Delta
YYRR 6 6 0
YYYRR 7 7 0
RRRR 8 8 0
YYGG 8 8 0
YYRRR 8 8 0
YYYGG 9 9 0
RRGG 10 10 0
RRRRR 10 10 0
YYBB 10 10 0
YYGGG 11 11 0
YYYBB 11 11 0
GGGG 12 12 0
RRBB 12 12 0
RRRGG 12 12 0
RRGGG 13 13 0
GGBB 14 14 0
RRRBB 14 14 0
YYBBB 14 14 0
GGGGG 15 15 0
BBBB 16 16 0
RRBBB 16 16 0
GGGBB 17 17 0
GGBBB 18 18 0
BBBBB 20 20 0
YYRB 9 8 1
RRGB 12 11 1
YGGB 12 11 1
YYRRGG 13 12 1
YYRRBB 15 14 1
YYGGBB 17 16 1
RRGGBB 19 18 1
YRGB 12 10 2
YYYRGB 14 12 2
YRRRGB 16 14 2
YRGGGB 18 16 2
YRGBBB 20 18 2

Table 1: Century: Spice Road Points cards. (data from this spreadsheet)

Note: while I leveraged the table above, I did not read any existing analyses of the game.  I imagine that others have come to similar conclusions.

Monday, June 29, 2020

Which die is highest?

You roll a d6, d8, d12, and d20 all at the same time. What is the probability the d6 results in the highest number? d8? d12? d20?
First, let's clarify by what we mean by "highest number''. Does that mean that the d6 is greater the other dice, or just that no other dice are greater? In other words, how do we count ties? Let's not count ties for now, and deal with them last. With four dice, they will be the most tricky. (This is due to the number of cases involved. There could be 2, 3, or 4 dice tied. Or two sets of 2 for that matter!)

The faces of each of these dice are numbered 1 through the number of sides that it has. Each side has equal probability of occurring. If we label the results of the four dice as random variables $X_6$, $X_8$, $X_{12}$, and $X_{20}$, where the subscript refers to the number of sides of the die, then we can write the statement of equal probability in the following equation.
\begin{align}
P(X_N = x) = \begin{cases}
\frac{1}{N} &\qquad x \in \mathbb{W}, 1 \leq x \leq N \\
0 &\qquad \text{else}
\end{cases}
\end{align}
Here $\mathbb{W}$ is the set of all whole numbers (i.e. 0, 1, 2, 3, etc.). Recall that the probability of rolling less than a number on such a die is proportional to said number,
\begin{align}
P(X_N < x) = \frac{x-1}{N} &\qquad x \in \mathbb{W}, 1 \leq x \leq N .
\end{align}
But perhaps I'm putting the cart before the horse. How do we approach this problem? We can write the question as,
\begin{align}
P(X_6 > \max(X_8, X_{12}, X_{20})) = ?
\end{align}
This is not a great way to write it though. It tends to make us think that we should compute the distribution of the maximum term $\max(X_8, X_{12}, X_{20})$. We can write them separately also,
\begin{multline}
P(X_6 > \max(X_8, X_{12}, X_{20})) \\= P((X_6 > X_8) \cap (X_6 > X_{12}) \cap (X_6 > X_{20}))
\end{multline}
This means we are looking for the probability that $X_6 > X_8$ and $X_6 > X_{12}$ and $X_6 > X_{20}$. Unfortunately, these events are not independent, so we can not break up the intersection easily. How do we know that they are not independent? The requirement for independence is that knowing one event does not affect the probability of the other. It holds that $P(A | B) = P(A)$ if $A$ and $B$ are independent. Consider the case when $X_6 > X_{20}$. If true, that makes it more likely that $X_6 > X_8$ as then $X_6$ is more likely to be high.

Instead of using independence, let's consider that we roll the d6 first. All the rolls are independent, so this doesn't affect the probabilities. We can then consider the conditional probability,
\begin{multline}
P(( (X_6 > X_8) \cap (X_6 > X_{12}) \cap (X_6 > X_{20}) ) | X_6 = x) \\= P((x > X_8) \cap (x > X_{12}) \cap (x > X_{20})).
\end{multline}
Here, the three events are independent, since they depend on independent random variables, thus,
\begin{multline}
P((x > X_8) \cap (x > X_{12}) \cap (x > X_{20})) \\= \underbrace{P(x > X_8)}_{\frac{x-1}{8}} \cdot \underbrace{P(x > X_{12})}_{\frac{x-1}{12}} \cdot \underbrace{P(x > X_{20})}_{\frac{x-1}{20}}.
\end{multline}
We can then fill in the individual terms using a previous equation as shown above.
\begin{align}
P((x > X_8) \cap (x > X_{12}) \cap (x > X_{20})) = \frac{(x-1)^3}{8 \cdot 12 \cdot 20}.
\end{align}
We can then use the conditional probability to compute the total probability, using the following form,
\begin{align}
P(A) = \sum_{x \in \Omega} P(A | X=x) \cdot P(X=x),
\end{align}
where $A = (X_6 > X_8) \cap (X_6 > X_{12}) \cap (X_6 > X_{20})$ is an event and $X = X_6$ is a random variable. Note that this is an extension of the basic statement of conditional probability, namely that,
\begin{align}
P(A \cap B) = P(A|B) \cdot P(B),
\end{align}
where $A$ and $B$ are events. Consider a set of mutually exclusive events $B_i$, the union of which encompasses the entire sample space. That is,
\begin{align}
&B_i \cap B_j = \varnothing, \quad i \neq j \\
&\bigcup_i B_i = \Omega .
\end{align}
Suppose we take the intersection of our event $A$ with the whole sample space. The resulting event is equivalent to the event $A$,
\begin{align}
A = A \cap \Omega ,
\end{align}
and thus the probabilities are the same,
\begin{align}
P(A \cap \Omega) = P(A | \Omega) \cdot P(\Omega) = P(A) .
\end{align}
Now, but substituting $\Omega$ for the union of our events $B_i$, we find a new way to write the probability of $A$.
\begin{align}
P(A) & = P(A \cap \Omega) \\
&= P\left (A \cap \left (\bigcup_i B_i \right ) \right ) \\
&=P\left( \bigcup_i \left( A \cap B_i \right) \right)
\end{align}
The last line above distributes the intersection across all the terms in the union. This is analogous to the distributive property of multiplication. That is, treat intersection like multiplication and union like addition when rearranging. A simple statement of the idea is that
\begin{align}
A \cap (B \cup C) = (A \cap B) \cup (A \cap C).
\end{align}
We know that all that sets $A \cap B_i$ are disjoint since $B_i$ are disjoint by construction. The probability of disjoint events add when considering their union, thus,
\begin{align}
P(A) &=P\left( \bigcup_i \left( A \cap B_i \right) \right) \\
&=\sum_i P(A\cap B_i).
\end{align}
Now, we can use our earlier statement of conditional probability to rewrite this as,
\begin{align}
P(A) &=\sum_i P(A\cap B_i) \\
&=\sum_i P(A | B_i) \cdot P(B_i).
\end{align}
By defining the event $B_i$ as when $X = x$, where $x \in \mathbb{Z}$, for some mapping of $i$ onto $x$ (or should it be vice-versa?), we get the equation we are looking to prove. QED.

Now we can move on with the problem at hand, and compute the probability we are interested in.
\begin{align}
P((X_6 > X_8) \cap (X_6 > X_{12}) \cap (X_6 > X_{20})) &= \sum_{x=1}^6 \frac{(x-1)^3}{8 \cdot 12 \cdot 20}\cdot \frac{1}{6} \\
&\approx 0.0195
\end{align}
We can similarly compute the other probabilities, but there is a slight wrinkle here. We tacitly benefited from the fact that the d6 has the lowest maximum. If we instead look at the probability that the d20 is highest, we have to consider that the d20 can roll a number not possible on the other dice. This shows up when we use the earlier equation for $P(X_N < x)$ outside the range we stated. We can extend it as follows.
\begin{align}
P(X_N < x) = \begin{cases}
\hfill 0 \hfill & \, x < 0 \\
\hfill \cfrac{x-1}{N} \hfill &\, x \in \mathbb{N}, x \leq N \\
\hfill 1 \hfill & \, x > N
\end{cases}
\end{align}
Focusing on the probability that the d8 is highest, there are thus two cases two consider: when the d8 rolls up to 6, and when it rolls above 6.
\begin{align}
P((x > X_6) \cap (x > X_{12}) \cap (x > X_{20})) = \begin{cases}
\cfrac{(x-1)^3}{6 \cdot 12 \cdot 20}&\, x \leq 6 \\ & \\
\cfrac{(x-1)^2}{12 \cdot 20} &\, x > 6
\end{cases}
\end{align}
From this we can compute the probability that the d8 is higher than all other dice using two summations.
\begin{multline}
P((X_8 > X_6) \cap (X_8 > X_{12}) \cap (X_8 > X_{20})) \\= \left (
\sum_{x=1}^6 \frac{(x-1)^3}{6 \cdot 12 \cdot 20}
+ \sum_{x=7}^8 \frac{(x-1)^2}{12 \cdot 20}
\right ) \cdot \frac{1}{8}
\end{multline}
\begin{align}
P((X_8 > X_6) \cap (X_8 > X_{12}) \cap (X_8 > X_{20}))&\approx 0.0638
\end{align}
Computing the probability for the d12 and d20 are similar, except that there are even more ranges.
\begin{multline}
P((X_{12} > X_6) \cap (X_{12} > X_{8}) \cap (X_{12} > X_{20})) \\= \left (
\sum_{x=1}^6 \frac{(x-1)^3}{6 \cdot 8 \cdot 20}
+ \sum_{x=7}^8 \frac{(x-1)^2}{8 \cdot 20}
+ \sum_{x=9}^{12} \frac{(x-1)}{20}
\right ) \cdot \frac{1}{12}
\end{multline}
\begin{align}
P((X_{12} > X_6) \cap (X_{12} > X_{8}) \cap (X_{12} > X_{20}))&\approx 0.222
\end{align}
\begin{multline}
P((X_{20} > X_6) \cap (X_{20} > X_{8}) \cap (X_{20} > X_{12})) \\= \left (
\sum_{x=1}^6 \frac{(x-1)^3}{6 \cdot 8 \cdot 12}
+ \sum_{x=7}^8 \frac{(x-1)^2}{8 \cdot 12}
+ \sum_{x=9}^{12} \frac{(x-1)}{12}
+ \sum_{x=13}^{20} 1
\right ) \cdot \frac{1}{20}
\end{multline}
\begin{align}
P((X_{20} > X_6) \cap (X_{20} > X_{8}) \cap (X_{20} > X_{12}))&\approx 0.622
\end{align}
Now, let's consider the probability of a tie. If we just lump them all together, then we compute the probability relatively easily, by looking at it in terms of there not being a tie.
\begin{align}
P(\text{tie}) = 1 - P(\text{no tie})
\end{align}
We can construct the case when there is no tie. Consider rolling the d6 first. Any face is allowed. Now consider rolling the d8. All but one of the faces are allowed; if we roll the same as on the d6 we have a tie. Similarly for the d12, all but 2 are allowed. For the d20, all but 3 are allowed.
\begin{align}
P(\text{no tie}) &= \frac{6}{6} \cdot \frac{7}{8} \cdot \frac{10}{12} \cdot \frac{17}{20}\\
&\approx 0.620\\
P(\text{tie}) &\approx 1 - 0.620 \\
&\approx 0.380
\end{align}
Note that when we compare this to what's left when none of the four dice are higher than all the others, the values are not equal.
\begin{align}
P(\text{tie for highest}) &= 1 - P(\text{d6 strictly higher}) \\
&\qquad -P(\text{d8 strictly higher}) \\
&\qquad -P(\text{d12 strictly higher}) \\
&\qquad- P(\text{d20 strictly higher}) \\
&\approx 1 - 0.0195 - 0.0638 - 0.222 - 0.622 \\
&\approx 0.0727
\end{align}
This is because many, most actually, of the ties are between dice which are not amongst the highest. For example, the dice may roll 6, 6, 10, 15.

(I originally found this question here on BGG.)

Tuesday, June 23, 2020

Errata: How replayable is Onitama using the 16 move cards in the base game?


In our earlier discussion of Onitama, there was an error in the calculation of the number of sets of five cards which have an asymmetric card without its mirror, which we labeled $n_3$, helpfully pointed out by a reader in the comments.  On reflection, the error is somewhat obvious, as we computed that there are more of these cases than the total number of ways of select five cards, $n_1$.
\begin{align}
n_1 &= 4368 \\
n_3 &= 8008 \\
n_3 &> n_1
\end{align}
We avoided spotting the error because we subtracted half of $n_3$ from $n_1$, and since $n_1 > n_3/2$, we still got a positive number.  However, a simple check of the scale of these two numbers would have indicated the error.

But what is the error?  It's that we double counted many cases (I really should be saying I here, as I made the error, and you're following along at home probably spotting my error!).  Recall the construction of $n_3$.  We selected one of the asymmetric cards, and then allowed the remaining cards to be any of the cards except the mirror of the first card.  However, that includes cases where there is an additional unmatched asymmetric card.  Those cases get counted again when we get to picking the unmatched card as the first card.

Correcting this gets messy.  I'd still like the largely follow the flow that I used originally, so let's just recompute $n_3$ correctly.  Unfortunately, the best way that I've been able to come up with involves summing over every possible number of unmatched asymmetric cards as well as looking at every possible number of matched asymmetric cards.  The crux is this: if we include an asymmetric card we must know whether or not its pair is included.  Given the number of unmatched asymmetric cards, $u$, and the number of matched pairs, $m$, we can find the number of ways to come up with a valid selection.  First, there are $\binom{8}{u}$ ways to select $u$ unmatched asymmetric cards out of the total of 8, with $u$ from 1 to 4.  The maximum is 4, because there are only 4 pairs of matches cards, so we can't get 5 unmatches ones.  A fifth card would have to match.  That leaves us with $16-u$ cards, but only $4- u$ pairs of matched asymmetric cards ($8-2 \cdot u$ cards in total).  This means there are $\binom{4-u}{m}$ ways to select the matched pairs.  If $u \geq 4$, then there's no space for matched pairs.  In general, we have to keep the total number of matched and unmatched cards to 5 or less, so
\begin{align}
u + 2\cdot m \leq 5 .
\end{align}
This limits $m$ to satisfy,
\begin{align}
m \leq \frac{5-u}{2}
\end{align}
From the binomial coefficient along, we can see that $m \leq 4-u$, but the above requirement is more restrictive here, since $m$ must be an integer.
\begin{align}
\begin{array}{c|c|c}
u &4-u&\frac{5-u}{2}\\\hline
1&3&2\\
2&2&1.5\\
3&1&1\\
4&0&0.5\\
\end{array}
\end{align}
This leaves a remaining $5-u-2 \cdot m$ cards to be chosen from the remaining 8 symmetric cards, which there are $\binom{8}{5-u-2 \cdot m}$ to select.  Putting this together we get the following when we sum over the ranges computed above.
\begin{align}
n_3 &= \sum_{u=1}^4 \sum_{m=0}^{\lfloor \frac{5-u}{2} \rfloor} \binom{8}{u} \cdot \binom{4-u}{m} \cdot \binom{8}{5-u-2 \cdot m} \\
n_3 &= 5456
\end{align}
Unfortunately, I've made another mistake, since the new $n_3$ calculation is still larger than $n_1$.

Perhaps you noticed that I did a poor job of selecting the number of ways to choose $u$ unmatched asymmetric cards.  It holds up to $u=1$, but not above.  We can't choose any of the 8 cards, as we can choose at most one of each pair.  Thus, when selecting each card, we need to choose which pair to select from, of which there are $\binom{4}{u}$ ways to do, and then select which card inside each set.  For each unmatched asymmetric card there are 2 ways of doing that (since there are two cards), so in total there are $2^u$ ways of selecting the $u$ cards once selecting the pairs.  This provides us with a new equation for $n_3$.
\begin{align}
n_3 &= \sum_{u=1}^4 \sum_{m=0}^{\lfloor \frac{5-u}{2} \rfloor} \binom{4}{u} \cdot 2^u \cdot \binom{4-u}{m} \cdot \binom{8}{5-u-2 \cdot m} \\
n_3 &= 4040
\end{align}
Finally, we've gotten a number that's less than $n_1$.  It seems surprisingly large, in that almost all of the ways to select 5 cards out of 16 results in at least one unmatched asymmetric card.  Let's come up with a check that our methodology is correct.  If we add in the case that we get no unmatched pairs, that is $u=0$,
then we should get $n_1$.  Let's try that.
\begin{align}
n_3 +  \sum_{m=0}^{\lfloor \frac{5}{2} \rfloor} \binom{4}{m} \cdot \binom{8}{5-2 m} &= \sum_{u=0}^4 \sum_{m=0}^{\lfloor \frac{5-u}{2} \rfloor} \binom{4}{u} \cdot 2^u \cdot \binom{4-u}{m} \cdot \binom{8}{5-u-2m} \\
 &= 4368 \\
&= \binom{16}{5} \\
&= n_1
\end{align}
This does a pretty good job of confirming that our methodology is correct, as our somewhat convoluted summation gives us the same value for $n_1$.  Now we can bring this all together and calculate the total number of initial positions considering  isomorphs.  Recall that we had the number of ways to select 5 cards excluding isomorphs is as follows.
\begin{align}
n_4 &= n_1 - \frac{n_3}{2} \\
&= \binom{16}{5} - \frac{1}{2} \cdot  \sum_{u=1}^4 \sum_{m=0}^{\lfloor \frac{5-u}{2} \rfloor} \binom{4}{u} \cdot 2^u \cdot \binom{4-u}{m} \cdot \binom{8}{5-u-2m}\\
&= 4365 - \frac{4040}{2} \\
&= 2345
\end{align}
To get the number of initial positions with isomorphs, we need to multiply by $\frac{5!}{2 \cdot 2}$ as before.
\begin{align}
n_5 &= n_4 \cdot \frac{5!}{2 \cdot 2} \\
&= 2345  \cdot \frac{5!}{2 \cdot 2} \\
&= 2345 \cdot 30 \\
&= 70350
\end{align}

Monday, June 22, 2020

Onitama errata forthcoming

I'm working on fixing the Onitama calculation error I made previously, but I've made some subsequent computation errors that I'm tracking down.  Expect an update soon.