\chapter{Dice}

\section{Basics of Dice}

\subsection{Distribution of Successes}

\begin{multicols}{2}
    For further analysis it will be useful to have a distribution function for margins of success.

    To obtain such a distribution we start by observing that each roll can be divided into four groups: critical successes, successes, failures and critical failures, as shown in \cref{equ:dice_groups}. Further, this tuple has a multinomial distribution
    \begin{align}
        \left(C_s, S, F, C_f\right) \sim \text{MN}\left(d, 4, p\right)\label{equ:dice_groups} \\
        p = \left[1/12,\frac{12-\stat{dt}-1}{12},\frac{\stat{dt}-1}{12},\frac{1}{12}\right]
    \end{align}

    We can easily map a tuple to a success margin:
    \begin{equation}
        M = 2C_s + S - F - 2C_f
    \end{equation}

    Therefore, our distribution for $M$ is a sum over all tuples that produce the correct $m$
    \begin{equation}
        Pr(M = m) = \sum_{C_s,S,F,C_f; M = m}  \text{MN}\left(d, 4, p\right)
    \end{equation}

    Instead of trying all combinations of variables and summing the correct ones, we can use a system of Diophantine equations to reduce the search space.

    We start with two equations
    \begin{align}
        2c_s + s - f - 2c_f & = m \\
        c_s + s + f + c_f   & = d
    \end{align}
    which resolve into a two-dimensional system
    \begin{align}
        c_s & = m - d + 2f + 3c_f   \\
        s   & = -m + 2d - 3f - 4c_f
    \end{align}

    Next, we use inequalities $c_s\geq0, s\geq0$ to constrain the space for $c_f$, based on $f$. An example plot in \cref{fig:candidates} graphically shows the area defined by these equations and inequalities for one combination of $d$ and $m$.
    \begin{align}
        \frac{m-d+2f}{-3} \leq c_f \leq \frac{-m+2d-3f}{4}
    \end{align}
    Because the lower bound is not necessarily greater than 0, we will also use $c_f\geq0$.

    We can now also constrain $f$ by observing that the lower bound for $c_f$ can cross $c_f=0$ before $f=d$.
    \begin{equation}
        0 \leq f \leq \frac{2d-m}{3}
    \end{equation}

    Putting the sum together, and adding floors and ceilings to limit the sum to integers, we get:
    \begin{align}
        Pr(M=m) & = \sum_{f=0}^{\left\lfloor \frac{2d-m}{3} \right\rfloor}\sum_{c_f=\max(0,\left\lceil\frac{m-d+2f}{-3}\right\rceil)}^{\left\lfloor\frac{-m+2d-3f}{4}\right\rfloor} \\
                & \quad\; \frac{d!}{c_s!s!f!c_f!}
        \frac{n_s^s n_f^f}{12^{d}}                                                                                                                                                  \\
        n_f     & = \stat{dt}-1                                                                                                                                                     \\
        n_s     & = 12-n_s
    \end{align}
    While this equation is not very illuminating, it does allow us to efficiently compute the distribution and thus answer various questions regarding the results of dice rolls.

\end{multicols}

\begin{figure}[htb]
    \centering
    \includegraphics{images/dice_candidates_example.pdf}
    \caption{Example of candidate combinations of $f$ and $c_f$ with upper and lower bounds for $c_f$ shown. In this plot, $d=12$ and $m=8$.\label{fig:candidates}}
\end{figure}

\subsection{Probability of Success}\label{sec:pos}

\begin{multicols}{2}
    The first question to ask is: ``What is the probability of success, given a fixed \stat{DT}?''

    We will use the binomial distribution $\text{B}(20,7/20)$ for the size of the dice pool, to compute the expectation. This is a fairly arbitrary choice that assumes 7 is the average pool size. However, it allows us to analyze the probabilities regardless of what the actual current size of the pool is.

    \Cref{tab:cos} shows the probability of success for a given \stat{DT} as well as number of successes in a number of attempts.
\end{multicols}

\begin{table}[htb]
    \centering
    \begin{tabular}{r | r r c l}
        \stat{DT} & $p$  & \multicolumn{3}{c}{Succeeds}           \\ \cline{2-5}
        1         & 98\% & 51                           & in & 52 \\
        2         & 95\% & 20                           & in & 21 \\
        3         & 90\% & 8                            & in & 9  \\
        4         & 82\% & 4                            & in & 5  \\
        5         & 70\% & 2                            & in & 3  \\
        6         & 56\% & 1                            & in & 2  \\
        7         & 42\% & 2                            & in & 5  \\
        8         & 28\% & 1                            & in & 4  \\
        9         & 17\% & 1                            & in & 6  \\
        10        & 9\%  & 1                            & in & 12 \\
        11        & 4\%  & 1                            & in & 26 \\
    \end{tabular}
    \caption{Expected chance of success.\label{tab:cos}}
\end{table}

\subsection{Margin of Success}

\begin{multicols}{2}
    We also want to know what the expected margin of success is, given that the player succeeded in the roll, $\text{E}\left[M | M \geq 0\right]$. \Cref{tab:exp_mos} shows the expectations.

    Of note are the expected numbers of successes for \stat{DT} 11. The requirement for critical successes there causes a large variance in results. It is also important to remember that this does not show the full range of results. The highest possible result is $2d$, which for one die is the only possible (successful) result, while other numbers of dice have wider ranges.

    The variance on the upper half of the \stat{DT} range is very low. Even large dice pools can only expect 1 or 2 successes. With a drop in \stat{DT} the dice pool really comes into its own and can be expected to produce more successes.

    This means that building a large dice pool is not enough to ensure a large number of successes. The player must actually reduce the \stat{DT} to get a high likelihood of more successes.
\end{multicols}

\begin{table}[htb]
    \centering
    \begin{tabular}{r | S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1]}
            & \multicolumn{10}{c}{Difficulty Threshold}                                                                                                                                                                                                                                                   \\
        $d$ & \multicolumn{1}{c}{1}                     & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{5} & \multicolumn{1}{c}{6} & \multicolumn{1}{c}{7} & \multicolumn{1}{c}{8} & \multicolumn{1}{c}{9} & \multicolumn{1}{c}{10} & \multicolumn{1}{c}{11} \\ \cline{2-12}
        1   & 1.1                                       & 1.1                   & 1.1                   & 1.1                   & 1.1                   & 1.2                   & 1.2                   & 1.2                   & 1.3                   & 1.5                    & 2.0                    \\
        2   & 2.1                                       & 1.8                   & 1.5                   & 1.3                   & 1.1                   & 1.0                   & 0.8                   & 0.7                   & 0.7                   & 0.7                    & 1.0                    \\
        3   & 2.6                                       & 2.3                   & 2.1                   & 1.9                   & 1.8                   & 1.6                   & 1.5                   & 1.3                   & 1.1                   & 0.7                    & 0.3                    \\
        4   & 3.5                                       & 3.1                   & 2.7                   & 2.3                   & 1.9                   & 1.6                   & 1.4                   & 1.2                   & 1.1                   & 1.2                    & 2.0                    \\
        5   & 4.4                                       & 3.7                   & 3.1                   & 2.7                   & 2.3                   & 2.0                   & 1.7                   & 1.4                   & 1.1                   & 0.9                    & 1.1                    \\
        6   & 5.1                                       & 4.3                   & 3.6                   & 3.0                   & 2.5                   & 2.1                   & 1.7                   & 1.5                   & 1.3                   & 1.1                    & 0.5                    \\
        7   & 6.0                                       & 5.0                   & 4.1                   & 3.4                   & 2.8                   & 2.3                   & 2.0                   & 1.6                   & 1.3                   & 1.2                    & 1.9                    \\
        8   & 6.8                                       & 5.6                   & 4.6                   & 3.7                   & 3.0                   & 2.5                   & 2.0                   & 1.7                   & 1.4                   & 1.1                    & 1.0                    \\
        9   & 7.5                                       & 6.2                   & 5.1                   & 4.1                   & 3.3                   & 2.7                   & 2.2                   & 1.8                   & 1.4                   & 1.2                    & 0.6                    \\
        10  & 8.4                                       & 6.9                   & 5.5                   & 4.4                   & 3.5                   & 2.8                   & 2.2                   & 1.8                   & 1.5                   & 1.2                    & 1.8                    \\
        11  & 9.2                                       & 7.5                   & 6.0                   & 4.8                   & 3.7                   & 3.0                   & 2.4                   & 1.9                   & 1.5                   & 1.2                    & 1.0                    \\
        12  & 10.0                                      & 8.2                   & 6.5                   & 5.1                   & 4.0                   & 3.1                   & 2.4                   & 1.9                   & 1.6                   & 1.3                    & 0.7
    \end{tabular}
    \caption{Expected number of successes.\label{tab:exp_mos}}
\end{table}

\begin{multicols}{2}
    Further, we may want to know more about the distribution of successes. Once again employing the distribution of dice pools from \cref{sec:pos} we can compute the quantiles (for $[0.1,0.25,0.5,0.75,0.9]$) in \cref{tab:quants}. Note that this is still conditioned on the whole roll being successful, i.e., we are considering only non-negative margins of success.

    Like with expectations, there is an anomaly in \stat{DT} 11, because only critical successes pass that \stat{DT}. Another thing worth noting is that for \stat{DT} 8--11, the median number of successes is 1. This means that even if the roll is successful, the margin is likely as not at most 1.
\end{multicols}

\begin{table}[ht]
    \centering
    \begin{tabular}{r | S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1] S[table-format=2.1]}
        \stat{DT} & $q_{10}$ & $q_{25}$ & $q_{50}$ & $q_{75}$ & $q_{90}$ \\ \cline{2-6}
        1         & 3.1      & 4.3      & 6.6      & 7.9      & 8.1      \\
        2         & 1.7      & 3.3      & 5.1      & 6.8      & 8.0      \\
        3         & 0.8      & 2.4      & 4.2      & 5.8      & 7.4      \\
        4         & 0.4      & 1.6      & 3.3      & 5.0      & 6.6      \\
        5         & 0.0      & 0.9      & 2.6      & 4.2      & 5.7      \\
        6         & 0.0      & 0.7      & 1.9      & 3.6      & 5.0      \\
        7         & 0.0      & 0.4      & 1.6      & 2.9      & 4.5      \\
        8         & 0.0      & 0.0      & 1.0      & 2.4      & 3.9      \\
        9         & 0.0      & 0.0      & 1.0      & 2.0      & 3.4      \\
        10        & 0.0      & 0.0      & 0.8      & 1.8      & 2.9      \\
        11        & 0.3      & 0.5      & 1.0      & 1.0      & 2.4      \\
    \end{tabular}

    \caption{Quantiles of the number of successes for a given \stat{DT}.\label{tab:quants}}
\end{table}

\subsection{Threshold--Margin Combinations}

\begin{multicols}{2}
    It is useful to know how to give players a challenge with a certain chance of success. There is no simple formula for this, but in \cref{tab:dtm} we show, for 10\% increments, what combinations of \stat{DT} and margin give a given chance of passing the test. We are using the same distribution for dice pool sizes as in \cref{sec:pos}.

    We separated \cref{tab:dtm} into what we might call ``difficulty classes'', denoted by an intuitive chance of success. A quick glance at the numbers reveals that moving from once class to the next requires adding 1 to the \stat{DT} or adding 1--2 to the required margin.
\end{multicols}


\begin{table}[ht]
    \centering

    \begin{tabular}[t]{r|cc}
        Succeeds & \stat{DT} & $m$  \\ \hline
        19 in 20 & 1         & 0--1 \\
                 & 2         & 0    \\
        9 in 10  & 1         & 2--3 \\
                 & 2         & 1--2 \\
                 & 3         & 0--1 \\
        4 in 5   & 1         & 4--5 \\
                 & 2         & 3--4 \\
                 & 3         & 2    \\
                 & 4         & 0--1 \\
                 & 5         & 0    \\
        1 in 2   & 1         & 6--7 \\
                 & 2         & 5    \\
                 & 3         & 3--4 \\
                 & 4         & 2--3 \\
                 & 5         & 1--2 \\
                 & 6         & 0--1 \\
                 & 7         & 0
    \end{tabular}
    \hfill
    \begin{tabular}[t]{r|cc}
        Succeeds & \stat{DT} & $m$   \\ \hline
        1 in 3   & 1         & 8     \\
                 & 2         & 6--7  \\
                 & 3         & 5--6  \\
                 & 4         & 4--5  \\
                 & 5         & 3--4  \\
                 & 6         & 2--3  \\
                 & 7         & 1--2  \\
                 & 8         & 0     \\
        1 in 10  & 1         & 9--10 \\
                 & 2         & 8--9  \\
                 & 3         & 7--8  \\
                 & 4         & 6--7  \\
                 & 5         & 5--6  \\
                 & 6         & 4--5  \\
                 & 7         & 3     \\
                 & 8         & 1--2  \\
                 & 9         & 0--1  \\
                 & 10        & 0
    \end{tabular}
    \hfill
    \begin{tabular}[t]{r|cc}
        Succeeds & \stat{DT} & $m$    \\ \hline
        1 in 20  & 1         & 11--12 \\
                 & 2         & 10--11 \\
                 & 3         & 9 --10 \\
                 & 4         & 8--9   \\
                 & 5         & 7--8   \\
                 & 6         & 6--7   \\
                 & 7         & 4--5   \\
                 & 8         & 3--4   \\
                 & 9         & 2--3   \\
                 & 10        & 1--2   \\
                 & 11        & 0      \\
        1 in 100 & 1         & 13     \\
                 & 2         & 12     \\
                 & 3         & 11     \\
                 & 4         & 10     \\
                 & 5         & 9      \\
                 & 6         & 8      \\
                 & 7         & 6      \\
                 & 8         & 5      \\
                 & 9         & 4      \\
                 & 10        & 3      \\
                 & 11        & 1      \\
    \end{tabular}
    \caption{Combinations of \stat{DT} and margin that give a certain chance of success.\label{tab:dtm}}
\end{table}

\section{Combat Pool Steady State}

\begin{multicols}{2}
    The combat pool starts with the proficiency stat, i.e., \stat{STR} or \stat{DEX}. However, after rolling, the change in pool size is determined by \stat{CON}. After a number of turns, the expected size of the pool should converge on a number $\text E[d]$.

    We start by assuming that $\text E[d]$ is a number such that
    \begin{equation}
        \text E[d_{n+1}] = \text E[d_{n}] \label{equ:dice_ss_a1}
    \end{equation}
    where $n$ is the turn after which the steady state is achieved.

    To compute $\text E[d_n]$ for any $n$ we can use
    \begin{equation}
        \text E[d_n] = \text E[d_{n-1}] - p_f \cdot \text E[d_{n-1}] + \stat{con} \label{equ:dice_ss_a2}
    \end{equation}
    where $p_f = \stat{dt}/12$ is the probability of failure.

    Using assumptions in \cref{equ:dice_ss_a1,equ:dice_ss_a2} we write the following equations:
    \begin{align}
        \text E[d]           & = \text E[d] - p_f \cdot \text E[d] + \stat{con} \\
        p_f \cdot \text E[d] & = \stat{con}                                     \\
        \text E[d]           & = \frac{\stat{con}}{p_f}
    \end{align}

    As $p_f$ approaches 1, the steady state becomes just \stat{CON}, meaning the dice pool is entirely discarded and refreshed by \stat{con} on every turn. On the other hand, as $p_f$ approaches 0, the expected dice pool size increases. Specifically at 0, it shoots off toward infinity, as  the dice pool loses no dice and \stat{con} dice get added to it on every turn.
\end{multicols}
