DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
29a3ed5
Branches
Tags
master
memoire
review.lua
Fix issues with d439570
John Smith
commited
29a3ed5
at 2022-1 21:28:11
review.lua
Blame
History
Raw
--[[ stuff to help with the review mechanics ]] --[[ manipulates `Prompt` `prompt` in-place as it should be when reviewed at timestamp `revtime` with review success `revsucc` ]] local function update(prompt, revtime, revsucc) if revsucc and revsucc > 0 then local ad = revtime - prompt.time prompt.delay = 2.5 ^ revsucc * ad + math.max(40000 - 0.5 * ad, 0) prompt.succ = prompt.succ + 1 else prompt.delay = 30 prompt.fail = prompt.fail + 1 end prompt.time = revtime end --[[ checks (returns boolean) if `Prompt` `prompt` should be reviewed now ]] local function should(prompt) return os.time() - prompt.time >= prompt.delay end --[[ returns a shuffled version of the table, destroying the table in-place adapted from https://stackoverflow.com/q/55192727 ]] local function shuffle(t) local ret = {} local ci = 1 while #t > 0 do local ri = math.random(1, #t) ret[ci] = t[ri] table.remove(t, ri) ci = ci + 1 end return ret end --[[ returns a table of pairs of integers to index the deck to get prompts to be reviewed now; prompts are shuffled in order ]] local function toreviewlist(deck) local ctrt = {} for i, cg in ipairs(deck) do for j, pr in ipairs(cg) do if should(pr) then table.insert(ctrt, { i, j }) end end end ctrt = shuffle(ctrt) return ctrt end return { update = update, should = should, list = toreviewlist }