-
-
Save anonymous/07fea26f117ec3d8eb0812a2b50db598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
payoutInterval = 0.25 | |
rollInterval = 0.25 | |
function payout(payoutAmount) | |
--mem.payOut = (mem.payOut or 0) + payoutAmount | |
--mem.minBal = math.min((mem.minBal or 0), mem.payIn - mem.payOut) | |
--print(string.format("Payout %d (%d in, %d out, %d house profit, minimum balance %d)", payoutAmount, mem.payIn, mem.payOut, mem.payIn - mem.payOut, mem.minBal)) | |
mem.lastPayout = payoutAmount | |
mem.payoutCounter = (mem.payoutCounter or 0) + (payoutAmount * 2) | |
interrupt(payoutInterval, "payout") | |
end | |
function roll() | |
digits = {math.random(0,9), math.random(0,9), math.random(0,9)} | |
digiline_send("lcd", string.format("%d%d%d", digits[1], digits[2], digits[3])) | |
if (digits[1] == 6) and (digits[2] == 6) and (digits[3] == 6) then | |
payout(66) | |
return | |
end | |
if (digits[1] == digits[2]) and (digits[2] == digits[3]) then | |
payout(45) | |
return | |
end | |
if (digits[2] == digits[3]) then | |
payout(5) | |
return | |
end | |
end | |
if (event.type == "digiline") and (event.channel == "pipe_in") then | |
coinsIn = tonumber(string.sub(event.msg, 21, -1)) or 1 -- 21 is a fixed index for mineninths. Change this if you're accepting something else. | |
mem.payIn = (mem.payIn or 0) + coinsIn | |
mem.rollCounter = (mem.rollCounter or 0) + coinsIn | |
interrupt(rollInterval, "roll") | |
end | |
if (event.type == "interrupt") and (event.iid == "roll") then | |
if mem.rollCounter > 0 then | |
roll() | |
mem.rollCounter = mem.rollCounter - 1 | |
interrupt(rollInterval, "roll") | |
end | |
end | |
if (event.type == "interrupt") and (event.iid == "payout") then | |
if mem.payoutCounter > 0 then | |
if not port.d then | |
digiline_send("lcd", string.format("Winner!\n%d/%d\n", mem.payoutCounter / 2, mem.lastPayout)) | |
end | |
port.d = not port.d | |
mem.payoutCounter = mem.payoutCounter - 1 | |
interrupt(payoutInterval, "payout") | |
else | |
digiline_send("lcd", string.format("Last Payout %d\n", mem.lastPayout)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment