215 lines
7.5 KiB
Plaintext
215 lines
7.5 KiB
Plaintext
// Sensitivity cube and breakpoint statistics for generated weapons.
|
|
// Every value is derived from the exact binomial model in weapon_metrics.typ.
|
|
#import "weapon_metrics.typ": *
|
|
#import "report_config.typ": inclusive-range, sensitivity-settings
|
|
|
|
#let analyzed-base-precisions = inclusive-range(sensitivity-settings.base_precision)
|
|
#let analyzed-dice-pools = inclusive-range(sensitivity-settings.dice)
|
|
#let comparison-dice-pools = sensitivity-settings.comparison_dice
|
|
|
|
#let mean(values) = values.sum() / values.len()
|
|
|
|
#let numeric-median(values) = {
|
|
let ordered = values.sorted()
|
|
let middle = calc.floor(ordered.len() / 2)
|
|
if calc.rem(ordered.len(), 2) == 0 {
|
|
(ordered.at(middle - 1) + ordered.at(middle)) / 2
|
|
} else {
|
|
ordered.at(middle)
|
|
}
|
|
}
|
|
|
|
#let analyzed-probability(base-precision, weapon-precision) = (
|
|
calc.max(0, calc.min(10, base-precision + weapon-precision)) / 10
|
|
)
|
|
|
|
#let swept-damage(item, base-precision, dice) = commitment-analysis(
|
|
item.base-damage,
|
|
item.p-damage,
|
|
item.rmax,
|
|
item.actions,
|
|
dice,
|
|
analyzed-probability(base-precision, item.precision),
|
|
).best
|
|
|
|
#let perturbed-damage(
|
|
item,
|
|
dice,
|
|
precision-delta: 0,
|
|
p-damage-delta: 0,
|
|
base-precision: natural-precision,
|
|
) = commitment-analysis(
|
|
item.base-damage,
|
|
item.p-damage + p-damage-delta,
|
|
item.rmax,
|
|
item.actions,
|
|
dice,
|
|
analyzed-probability(base-precision, item.precision + precision-delta),
|
|
).best
|
|
|
|
#let relative-change(item, dice, precision-delta: 0, p-damage-delta: 0) = {
|
|
let baseline = perturbed-damage(item, dice)
|
|
let changed = perturbed-damage(
|
|
item,
|
|
dice,
|
|
precision-delta: precision-delta,
|
|
p-damage-delta: p-damage-delta,
|
|
)
|
|
if baseline == 0 { 0 } else { (changed / baseline - 1) * 100 }
|
|
}
|
|
|
|
#let weapon-threshold-grid(dice) = all-weapon-metrics.map(item => (
|
|
analyzed-base-precisions.map(precision => swept-damage(item, precision, dice))
|
|
))
|
|
|
|
#let weapon-sensitivity-grid(precision-delta: 0, p-damage-delta: 0) = (
|
|
all-weapon-metrics.map(item => comparison-dice-pools.map(dice => relative-change(
|
|
item,
|
|
dice,
|
|
precision-delta: precision-delta,
|
|
p-damage-delta: p-damage-delta,
|
|
)))
|
|
)
|
|
|
|
#let precision-loss-grid = weapon-sensitivity-grid(precision-delta: -1)
|
|
#let precision-gain-grid = weapon-sensitivity-grid(precision-delta: 1)
|
|
#let p-damage-loss-grid = weapon-sensitivity-grid(p-damage-delta: -1)
|
|
#let p-damage-gain-grid = weapon-sensitivity-grid(p-damage-delta: 1)
|
|
#let precision-swing-grid = precision-loss-grid.zip(precision-gain-grid).map(pair => (
|
|
range(0, comparison-dice-pools.len()).fold((), (values, index) => (
|
|
values + (pair.at(0).at(index), pair.at(1).at(index))
|
|
))
|
|
))
|
|
#let p-damage-swing-grid = p-damage-loss-grid.zip(p-damage-gain-grid).map(pair => (
|
|
range(0, comparison-dice-pools.len()).fold((), (values, index) => (
|
|
values + (pair.at(0).at(index), pair.at(1).at(index))
|
|
))
|
|
))
|
|
#let point-sensitivity-summary = comparison-dice-pools.enumerate().map(pair => {
|
|
let index = pair.at(0)
|
|
let dice = pair.at(1)
|
|
(
|
|
dice: dice,
|
|
precision-loss: mean(precision-loss-grid.map(row => row.at(index))),
|
|
precision-gain: mean(precision-gain-grid.map(row => row.at(index))),
|
|
p-damage-loss: mean(p-damage-loss-grid.map(row => row.at(index))),
|
|
p-damage-gain: mean(p-damage-gain-grid.map(row => row.at(index))),
|
|
)
|
|
})
|
|
|
|
#let weapon-sensitivity-cube = analyzed-base-precisions.fold((), (rows, precision) => (
|
|
rows + analyzed-dice-pools.fold((), (pool-rows, dice) => (
|
|
pool-rows + all-weapon-metrics.map(item => (
|
|
weapon: item.name,
|
|
shape: item.shape,
|
|
nature: item.nature,
|
|
base-precision: precision,
|
|
effective-precision: calc.max(0, calc.min(10, precision + item.precision)),
|
|
dice: dice,
|
|
base-damage: item.base-damage,
|
|
p-damage: item.p-damage,
|
|
rmax: item.rmax,
|
|
actions: item.actions,
|
|
armor-break: item.armor-break,
|
|
expected-damage: swept-damage(item, precision, dice),
|
|
))
|
|
))
|
|
))
|
|
|
|
#let average-swept-damage(base-precision, dice) = mean(
|
|
all-weapon-metrics.map(item => swept-damage(item, base-precision, dice)),
|
|
)
|
|
|
|
#let average-damage-grid = analyzed-base-precisions.map(precision => (
|
|
analyzed-dice-pools.map(dice => average-swept-damage(precision, dice))
|
|
))
|
|
|
|
#let marginal-dice-pools = analyzed-dice-pools.slice(1)
|
|
#let average-marginal-grid = analyzed-base-precisions.map(precision => (
|
|
marginal-dice-pools.map(dice => (
|
|
average-swept-damage(precision, dice)
|
|
- average-swept-damage(precision, dice - 1)
|
|
))
|
|
))
|
|
|
|
#let marginal-observations = analyzed-base-precisions.fold((), (rows, precision) => (
|
|
rows + marginal-dice-pools.map(dice => (
|
|
base-precision: precision,
|
|
dice: dice,
|
|
gain: average-swept-damage(precision, dice)
|
|
- average-swept-damage(precision, dice - 1),
|
|
))
|
|
))
|
|
#let strongest-marginal = marginal-observations.sorted(key: point => -point.gain).first()
|
|
#let weakest-marginal = marginal-observations.sorted(key: point => point.gain).first()
|
|
|
|
#let pearson(records, x-key, y-key) = {
|
|
let xs = records.map(row => row.at(x-key))
|
|
let ys = records.map(row => row.at(y-key))
|
|
let x-mean = mean(xs)
|
|
let y-mean = mean(ys)
|
|
let numerator = xs.zip(ys).map(pair => (
|
|
(pair.at(0) - x-mean) * (pair.at(1) - y-mean)
|
|
)).sum()
|
|
let x-square = xs.map(value => calc.pow(value - x-mean, 2)).sum()
|
|
let y-square = ys.map(value => calc.pow(value - y-mean, 2)).sum()
|
|
if x-square == 0 or y-square == 0 { 0 } else {
|
|
numerator / calc.sqrt(x-square * y-square)
|
|
}
|
|
}
|
|
|
|
#let correlation-fields = (
|
|
(key: "base-precision", label: "Seuil"),
|
|
(key: "dice", label: "Dés"),
|
|
(key: "base-damage", label: "Dég."),
|
|
(key: "p-damage", label: "+/réuss."),
|
|
(key: "rmax", label: "R.Max"),
|
|
(key: "actions", label: "Actions"),
|
|
(key: "armor-break", label: "Brise"),
|
|
(key: "expected-damage", label: "E[dég.]"),
|
|
)
|
|
|
|
#let weapon-correlation-values = correlation-fields.map(left => (
|
|
correlation-fields.map(right => pearson(
|
|
weapon-sensitivity-cube, left.key, right.key,
|
|
))
|
|
))
|
|
|
|
#let damage-correlations = correlation-fields.filter(field => (
|
|
field.key != "expected-damage"
|
|
)).map(field => (
|
|
label: field.label,
|
|
value: pearson(weapon-sensitivity-cube, field.key, "expected-damage"),
|
|
)).sorted(key: result => -calc.abs(result.value))
|
|
|
|
// Discrete knee: greatest normalized height above the line joining the first
|
|
// and last points. This detects where a concave damage curve bends most.
|
|
#let weapon-knee(item, base-precision) = {
|
|
let damages = analyzed-dice-pools.map(dice => swept-damage(item, base-precision, dice))
|
|
let first-damage = damages.first()
|
|
let damage-span = damages.last() - first-damage
|
|
let dice-span = analyzed-dice-pools.last() - analyzed-dice-pools.first()
|
|
let candidates = analyzed-dice-pools.enumerate().map(pair => {
|
|
let index = pair.at(0)
|
|
let dice = pair.at(1)
|
|
let x = (dice - analyzed-dice-pools.first()) / dice-span
|
|
let y = if damage-span == 0 { 0 } else {
|
|
(damages.at(index) - first-damage) / damage-span
|
|
}
|
|
(dice: dice, damage: damages.at(index), curvature: y - x)
|
|
})
|
|
candidates.sorted(key: point => -point.curvature).first()
|
|
}
|
|
|
|
#let knee-summary = analyzed-base-precisions.map(precision => {
|
|
let knees = all-weapon-metrics.map(item => weapon-knee(item, precision))
|
|
let end-damages = all-weapon-metrics.map(item => swept-damage(item, precision, 14))
|
|
(
|
|
precision: precision,
|
|
median-dice: numeric-median(knees.map(knee => knee.dice)),
|
|
average-damage: mean(knees.map(knee => knee.damage)),
|
|
average-end-damage: mean(end-damages),
|
|
retained: mean(knees.map(knee => knee.damage)) / mean(end-damages),
|
|
)
|
|
})
|