Posted 23 February 2014 - 07:35 AM
Hello Pros! I was recently working on an AI for guess the number, and I ran into this problem.
Sometimes, the program works perfectly, and guesses the number.
But sometimes, it will do a few guesses, then error out:
Sometimes, the program works perfectly, and guesses the number.
But sometimes, it will do a few guesses, then error out:
startup: 26: bad argument #2: interval is empty
Current code:
h = 0
d = 1000
l = 0
more = {}
less = {}
tbg = math.random(1, 200)
repeat
if more[1] == nil then
d = 20
end
for k, v in ipairs(more) do
if v < d then
d = v
end
end
if less[1] == nil then
l = 1
end
for k, v in ipairs(less) do
if v > l then
l = v
end
end
l = l+1
d = d-1
g = math.random(l, d)
if g > tbg then
table.insert(more, g)
elseif g < tbg then
table.insert(less, g)
end
print(g)
h = h+1
until g == tbg
print("The number was: "..tbg)
print("It took "..h.." guesses!")
Does anyone know what is going on?