View difference between Paste ID: DHXRNt9B and sXHfPqs4
SHOW: | | - or go back to the newest paste.
1
local coinStates = {
2
	[1] = {
3
		"           ",
4
		"  _______  ",
5
		" /       \\ ",
6
		"|  Heads  |",
7
		"|_________|",
8
		" \\_______/ ",
9
		"           ",
10
		"           ",
11
	},
12
	[2] = {
13
		"   _____   ",
14
		"  /     \\  ",
15
		" /       \\ ",
16
		"|         |",
17
		"|  Heads  |",
18
		"|         |",
19
		" \\       / ",
20
		"  \\_____/  ",
21
	},
22
	[3] = {
23
		"           ",
24
		"  _______  ",
25
		" /_______\\ ",
26-
		"|  Head   |",
26+
27
		"|         |",
28
		" \\_______/ ",
29
		"           ",
30
		"           ",
31
	},
32
	[4] = {
33
		"           ",
34
		"           ",
35
		" _________ ",
36
		"|_________|",
37
		"           ",
38
		"           ",
39
		"           ",
40
	},
41
	[5] = {
42
		"           ",
43
		"  _______  ",
44
		" /       \\ ",
45
		"|  Tails  |",
46
		"|_________|",
47
		" \\_______/ ",
48
		"           ",
49
		"           ",
50
	},
51
	[6] = {
52
		"   _____   ",
53
		"  /     \\  ",
54
		" /       \\ ",
55
		"|         |",
56
		"|  Tails  |",
57
		"|         |",
58
		" \\       / ",
59
		"  \\_____/  ",
60
	},
61
	[7] = {
62
		"           ",
63
		"  _______  ",
64
		" /_______\\ ",
65
		"|  Tails  |",
66
		"|         |",
67
		" \\_______/ ",
68
		"           ",
69
		"           ",
70
	},
71
	[8] = {
72
		"           ",
73
		"           ",
74
		" _________ ",
75
		"|_________|",
76
		"           ",
77
		"           ",
78
		"           ",
79
	},
80
}
81
local currentState = 2
82
local criteria = {...}
83
local score = {0, 0}
84
local xSize, ySize = term.getSize()
85
86
function displayCoin()
87
	term.setCursorPos(1, 1)
88
	print("Heads: "..criteria[1].." ("..score[1]..")")
89
	print("Tails: "..criteria[2].." ("..score[2]..")")
90
	for i = 1 , #coinStates[currentState] do
91
		term.setCursorPos(math.floor(xSize/2)-5, math.floor(ySize/2)-4+i)
92
		print(coinStates[currentState][i])
93
	end
94
end
95
96
function tailsToHeads(delay)
97
	while currentState ~= 2 do
98
		currentState = currentState + 1
99
		if currentState > 8 then
100
			currentState = 1
101
		end
102
		sleep(delay)
103
		displayCoin()
104
	end
105
end
106
107
function headsToTails(delay)
108
	while currentState ~= 6 do
109
		currentState = currentState + 1
110
		if currentState > 8 then
111
			currentState = 1
112
		end
113
		sleep(delay)
114
		displayCoin()
115
	end
116
end
117
118
if criteria[1] == nil or criteria[2] == nil then
119-
	error("Two arguments required.")
119+
	error("Two arguments required. Example: 'coin Yes No'")
120
end
121
122
term.clear()
123
repeat
124
	local decision = math.random()
125
	for i = 1, math.random(4, 8) do
126
		if currentState == 2 then
127
			headsToTails(0.05)
128
		elseif currentState == 6 then
129
			tailsToHeads(0.05)
130
		end
131
	end
132
	for i = 1, math.random(2, 4) do
133
		if currentState == 2 then
134
			headsToTails(0.1)
135
		elseif currentState == 6 then
136
			tailsToHeads(0.1)
137
		end
138
	end
139
	if decision < 0.5 then
140
		if currentState ~= 2 then
141
			tailsToHeads(0.15)
142
		end
143
		score[1] = score[1] + 1
144
	elseif decision >= 0.5 then
145
		if currentState ~= 6 then
146
			headsToTails(0.15)
147
		end
148
		score[2] = score[2] + 1
149
	end
150
	displayCoin()
151
	sleep(1.5)
152
until score[1] == 3 or score[2] == 3