Difference between revisions of "Module:Failure rate table"
(Module to calculate failure rates for evocations and invocations) |
(Show only certain rows) |
||
(One intermediate revision by the same user not shown) | |||
Line 36: | Line 36: | ||
function p.table(frame) | function p.table(frame) | ||
− | return table._table(frame.args[1], | + | local inputs = {0, 1, 3, 5, 7, 10, 15, 20, 25, 27} |
+ | return table._table(frame.args[1], 10, {inputs = inputs, format = format}, "Failure rate(%)", success_func(frame.args[2], frame.args[3])) | ||
end | end | ||
return p | return p |
Latest revision as of 04:09, 1 July 2015
Documentation for this module may be created at Module:Failure rate table/doc
local table = require("Module:Calculated table") local p = {} -- translated from spl-cast.cc local function tetrahedral_number(n) return math.floor(n * (n+1) * (n+2) / 6) end -- translated from spl-cast.cc local function true_fail_rate(raw_fail) local outcomes = 101 * 101 * 100 local target = raw_fail * 3 if target <= 100 then return tetrahedral_number(target) / outcomes elseif target <= 200 then return (tetrahedral_number(target) - 2 * tetrahedral_number(target - 101) - tetrahedral_number(target - 100)) / outcomes end return (outcomes - tetrahedral_number(300 - target)) / outcomes end local function success_func(base_fail, scale) return function(env) local skill = env.x local fail = base_fail - scale*skill if fail <= 0 then return 0 end return true_fail_rate(base_fail - scale*skill) end end local function format(n) return ("%.2f%%"):format(100*n) end function p.table(frame) local inputs = {0, 1, 3, 5, 7, 10, 15, 20, 25, 27} return table._table(frame.args[1], 10, {inputs = inputs, format = format}, "Failure rate(%)", success_func(frame.args[2], frame.args[3])) end return p