# User:PSGarak/Sandbox/Warplan

This calculator will guide you through a Campaign of Parabolan Warfare by deciding the correct options to play at each Stage and values of Advance! and Campaign Morale, based on your character's stats and your own valuation of the different items that might be consumed.

By using this calculator, you are making the decision that you would rather let a spreadsheet play the game for you. You should only use this tool if you already find grinds to be joyless, or a higher EPA is better motivation than gameplay.

### Using this Calculator

The first set of inputs is straightforward. The choice of campaign only affects the number of actions spent on narrative after each stage.

The second set of inputs is the relative Action costs for the various items that can be spent (or gained) via the various actions on the campaign trial. This calculator works by converting all resources into an "action cost" equivalent, so items are valued based on the number of actions to replenish those spent. Ravages of Parabolan Warfare are valued based on the actions to clear them after the campaign. The default values assume all resources can be obtained at 2.5 EPA, and that Ravages take 1 action to clear.

The results of the calculator will show tables of the expected actions to complete the Parabolan Campaign from any given point, as well as the optimal choice at that particular point. If Airs-dependent actions are worth playing, then the tables will list the best non-Airs choice, as well as all Airs-dependent choices that should be played if available.

Note that in some cases, more than one choice might be optimal. The calculator will select only one as optimal, with the choice depending on implementation details.

## Get My Personalized Battle-Plan

 template = User:PSGarak/Sandbox/Parabolan War
form = parameters
result = warplan
param = Watchful|Watchful|300|int|0-400
param = Dangerous|Dangerous|300|int|0-400
param = Persuasive|Persuasive|300|int|0-400
param = Campaign|Campaign|Yourself|select|The Cats,The Fingerkings,The Chessboard,Yourself
param = General|Chosen General|None|select|None,Cat,Snake,Chess
param = null|Item Costs, in Actions to Acquire:||fixed
param = Cost_Ravage|Curing Ravages of Parabolan Warfare|1|number|0-10
param = Cost_Psalm|Apostate's Pslam|1|number|0-10
param = Cost_Sign|London Street Sign|1|number|0-10
param = Cost_Self|Memory of a Much Lesser Self|1|number|0-10
param = Cost_Glass|Glass Gazette|1|number|0-10
param = Cost_Wing|Wing of a Young Terror Bird|1|number|0-10
param = Cost_Plaque|Correspondence Plaque|0.2|number|0-10
param = Cost_Light|Memory of Light|0.2|number|0-10
param = Cost_Solacefruit|Solacefruit|0.2|number|0-10
param = Cost_Viric|Trace of Viric|0.2|number|0-10
param = Cost_Feather|Royal-Blue Feather|0.2|number|0-10
param = Cost_Claw|Silvered Cat's Claw|0.04|number|0-10


## How it Works

This calculator is based on a classical optimization technique called Dynamic Programming. (Despite the similar name, this bears no relation to "dynamic programming languages" like JavaScript or Lua.) The core concept is that results are computed starting from the end of the campaign working backwards rather than from the beginning, calculating actions-to-goal rather than actions-spent. When considering the options available at any particular state, the outcomes of those options will have already been computed, so the arithmetic to choose which is best because very simple.

As an example, consider the table below, showing results for the Writhing River, calculated with default values. Results in the table are computed from the bottom up, and from left to right. When calculating the results for the cell highlighted in purple ( 0 x Advance! & 5 x Campaign Morale), the other highlighted cells indicate the outcome of all the possible actions that might be taken in the Writhing River. The total Actions-to-Complete from those points in the Campaign have already been calculated. We can then compute the expected Actions-to-Complete for each of the available options, taking into account its outcomes, success probability, and resource cost. The option with the lowest expected Actions-to-Complete is recommended as the best option, and its Actions-to-Complete is stored as the value for the current cell.

### Calculations

Some actions (like most Safe Progress options) always produce the same amount of Advance! on success or failure, but have different resource costs. For a given Advance! a and Morale m, the Actions-to-Goal value A(a, m) can be computed as

${\displaystyle A(a,m)=1+A(a+1,m)+pc_{s}+(1-p)c_{f}}$

where p is the probability of success, and cs and cf are the resource costs of success and failure. The constant 1 is the action spent on playing the option. The value a + 1 assumes the Safe Progress increases Advance! by 1, and would be replaced by other values as necessary.

Spending Morale is a slightly different situation, where success & failure both always spend Morale but one only gives Advance!. For this situation, the formula is modified slightly. Note that no Morale options cost resources, so the c terms are ignored.

${\displaystyle A(a,m)=1+pA(a+5,m-5)+(1-p)A(a,m-5)}$

Most other options work slightly differently, where costs are accrued on failure but neither Advance! nor Morale is modified. In these cases, the formula can be derived by observing that with a success probability p, one success will require 1/p attempts and incur (1-1/p) failures.

${\displaystyle A(a,m)={\frac {1}{p}}+A(a+3,m)+c_{s}+({\frac {1}{p}}-1)c_{f}}$

As before, the a + 3 term is an example for early-stage Fast Progress options, but other options modify Advance! and Morale in different ways.

### Airs

The impact of Airs-dependent options are tricky to account for. They cannot always be attempted, which is straightforward to accommodate. The more difficult issue is that on failure, sometimes the option can be re-attempted and sometimes it cannot.

The Actions-to-complete value for an Airs option Aa(a, m) depends in part on the value for the best deterministic option available, Ad(a, m). With a success probability p, and assuming Airs options are available exactly 1/3 of the time, the value Aa(a, m) can be calculated as:

{\displaystyle {\begin{aligned}A_{a}(a,m)={\frac {2}{3}}&\left(A_{d}(a,m)\right)\\+{\frac {1}{3}}&\left[p(1+A(a+4,m))+(1-p)\left(1+c_{f}+A_{a}(a,m)\right)\right]\end{aligned}}}

This equation definesAa in terms of itself, which represents re-attempting on failure. The fact that the option is not always available to play then also encapsulates the fact that it is not always avaialble to re-attempt. Solving this recurrence relationship for a closed-form value of Aa yields the following:

${\displaystyle A_{a}(a,m)={\frac {2A_{d}(a,m)+pA(a+4,m)+c_{f}(1-p)+1}{2+p}}}$

To decide whether the Airs value should be taken or not, we find when ${\displaystyle A_{a}, i.e. when ${\displaystyle A_{d}-A_{a}>0}$. Airs values should be played when the following is true:

${\displaystyle A(a+4,m)

In other words, the fraction on the right describes how much better the success result of the Airs option needs to be compared to the best deterministic option in order to be worth playing.