-- Fibonacci (one step up on a loss, two steps back on a win)
-- Bet basebet times a Fibonacci number: 1, 1, 2, 3, 5, 8, 13, 21 ...
-- After a loss move one step up the sequence, after a win move two steps back, never
-- below the first step. The bet grows much slower than a doubling martingale, but after
-- 3 or more losses a single win no longer pays back the run; it only moves two steps down.

chance  = 49.5
bethigh = false

basebet = params.basebet or balance / 10000
nextbet = basebet

local fib  = { 1, 1 }   -- the sequence, extended as needed
local step = 1          -- current position in the sequence (1-based)

local function fibAt(k)
  while #fib < k do
    fib[#fib + 1] = fib[#fib] + fib[#fib - 1]
  end
  return fib[k]
end

function dobet()
  if win then
    step = math.max(1, step - 2)
  else
    step = step + 1
  end
  nextbet = basebet * fibAt(step)
end
