[RPG] How to spells per day be determined mathematically

dnd-3.5espells

I want a character sheet I'm designing to automatically show available spells per day at each spell level without the user having to enter that information by hand.

Is there a formula for determining a class's spells per day without consulting the class's table? That is, can spells per day be determined mathematically, or are spells per day arbitrary, making the lookup chart required?

I don't need the math for bonus spells, only for classes.

Best Answer

TL;DR: Use lookup tables, because we're not in Kansas any more.

We're off to see the Wizard...

Just looking at the wizard, there seems to be a fairly regular progression. You get the first spell of spell level \$S\$ when your class level \$C\$ satisfies

\begin{align} \frac{C+1}{2} & \geq S &\Leftrightarrow&& C-2S+1 & \geq 0 \end{align}

The second, third and fourth spell for each level are obtained when

\begin{align} C-2S+1 \geq 1, C-2S+1 \geq 3, C-2S+1 \geq 6 \end{align}

This can be easily written as

$$ C-2S+1 = \sum_{i=1}^{k-1} i = \frac{k(k-1)}{2} $$

We can solve this for \$k\$, which yields

$$ k_S(C) = \frac{1}{2} \pm \frac{1}{2} \sqrt{1+8(C-2S+1)} $$

The correct solution here is the one with the positive sign. We also have to round down to the next integer. Finally, there's a maximum of 4 for wizards:

$$ k_S(C) = \min\left(4,\left\lfloor\frac{1}{2} + \frac{1}{2} \sqrt{1+8(C-2S+1)}\right\rfloor\right) $$

If that seems pretty reasonable so far, it's because it doesn't account for deviations yet. This formula only holds true for \$1\leq S \leq7\$. Spell levels 0, 8 and 9 have slightly different progressions (in order to end with 4 slots on all spell levels at level 20), which I'm not going into in this answer (although spell level 0 can be obtained using \$S=-0.5\$).

The same calculation works for clerics and druids, too, with the exception that the limit is 5, except for 0-level spells, which have a limit of 6. I guess Tier 1 classes are simply better.

The wicked witch of the west sinister sorcerer of the south

If we try to adapt this to the sorcerer, things start getting wonky. The progression is all different, the maximum is increased to 6, there's a minimum of 3 unless it's 0. The shunted progression (new spell levels at odd levels) causes spell level 1 to deviate from the pattern.

For \$2\leq S \leq 8\$, we have

$$ k_S(C) = \begin{cases}\min\left(6,3+C-2S\right)& C\geq 2S\\0 & C < 2S\end{cases} $$

Spell level 1 is offset by 1 class level, so

$$ k_1(C) = \min\left(6,3+C+1-2S\right) $$

Let loose the flying monkeys

Now let's go to where math breaks completely: Bards. Not only is the Bard spell progression majorly weird, with exceptions being as common as rules, you now also have to deal with 0 spells per day being different from "–" spells per day.

I'm not even going to talk about Rangers and Paladins. Or, you know, classes outside of the PHB (like the Duskblade). Or prestige classes (Sublime Chord comes to mind).

Conclusion: Not worth the effort

I hope this illustrates that while WotC seems to have started with a plan, the dozens of variations for special cases within the same class, as well as major differences between characters makes it so that a lookup table, a nested if else or case structure are the only real way to deal with the problem.