Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local coinStates = {
- [1] = {
- " ",
- " _______ ",
- " / \\ ",
- "| Heads |",
- "|_________|",
- " \\_______/ ",
- " ",
- " ",
- },
- [2] = {
- " _____ ",
- " / \\ ",
- " / \\ ",
- "| |",
- "| Heads |",
- "| |",
- " \\ / ",
- " \\_____/ ",
- },
- [3] = {
- " ",
- " _______ ",
- " /_______\\ ",
- "| Heads |",
- "| |",
- " \\_______/ ",
- " ",
- " ",
- },
- [4] = {
- " ",
- " ",
- " _________ ",
- "|_________|",
- " ",
- " ",
- " ",
- },
- [5] = {
- " ",
- " _______ ",
- " / \\ ",
- "| Tails |",
- "|_________|",
- " \\_______/ ",
- " ",
- " ",
- },
- [6] = {
- " _____ ",
- " / \\ ",
- " / \\ ",
- "| |",
- "| Tails |",
- "| |",
- " \\ / ",
- " \\_____/ ",
- },
- [7] = {
- " ",
- " _______ ",
- " /_______\\ ",
- "| Tails |",
- "| |",
- " \\_______/ ",
- " ",
- " ",
- },
- [8] = {
- " ",
- " ",
- " _________ ",
- "|_________|",
- " ",
- " ",
- " ",
- },
- }
- local currentState = 2
- local criteria = {...}
- local score = {0, 0}
- local xSize, ySize = term.getSize()
- function displayCoin()
- term.setCursorPos(1, 1)
- print("Heads: "..criteria[1].." ("..score[1]..")")
- print("Tails: "..criteria[2].." ("..score[2]..")")
- for i = 1 , #coinStates[currentState] do
- term.setCursorPos(math.floor(xSize/2)-5, math.floor(ySize/2)-4+i)
- print(coinStates[currentState][i])
- end
- end
- function tailsToHeads(delay)
- while currentState ~= 2 do
- currentState = currentState + 1
- if currentState > 8 then
- currentState = 1
- end
- sleep(delay)
- displayCoin()
- end
- end
- function headsToTails(delay)
- while currentState ~= 6 do
- currentState = currentState + 1
- if currentState > 8 then
- currentState = 1
- end
- sleep(delay)
- displayCoin()
- end
- end
- if criteria[1] == nil or criteria[2] == nil then
- error("Two arguments required. Example: 'coin Yes No'")
- end
- term.clear()
- repeat
- local decision = math.random()
- for i = 1, math.random(4, 8) do
- if currentState == 2 then
- headsToTails(0.05)
- elseif currentState == 6 then
- tailsToHeads(0.05)
- end
- end
- for i = 1, math.random(2, 4) do
- if currentState == 2 then
- headsToTails(0.1)
- elseif currentState == 6 then
- tailsToHeads(0.1)
- end
- end
- if decision < 0.5 then
- if currentState ~= 2 then
- tailsToHeads(0.15)
- end
- score[1] = score[1] + 1
- elseif decision >= 0.5 then
- if currentState ~= 6 then
- headsToTails(0.15)
- end
- score[2] = score[2] + 1
- end
- displayCoin()
- sleep(1.5)
- until score[1] == 3 or score[2] == 3
Add Comment
Please, Sign In to add comment