Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tycoon Weather Simulator by glitchdetector, use https://www.lua.org/cgi-bin/demo to run
- iterations = 72 -- Cycles to run
- weather = 'EXTRASUNNY' -- Starting weather
- WeatherData = {
- --[WEATHER] = {NAME, {MIN_CYCLES, MAX_CYCLES}, NEXT_TYPES},
- ['EXTRASUNNY'] = {"Extra Sunny", {1, 1}, {'CLEAR', 'CLEARING'}},
- ['CLEAR'] = {"Clear", {1, 1}, {'EXTRASUNNY', 'OVERCAST'}},
- ['SMOG'] = {"Smoggy", {1, 1}, {'EXTRASUNNY', 'OVERCAST'}},
- ['FOGGY'] = {"Foggy", {1, 1}, {'EXTRASUNNY', 'CLEARING'}},
- ['OVERCAST'] = {"Overcast", {1, 1}, {'SMOG', 'EXTRASUNNY'}},
- ['CLOUDS'] = {"Cloudy", {1, 1}, {'FOGGY', 'EXTRASUNNY'}},
- ['CLEARING'] = {"Drizzling", {1, 1}, {'CLEAR', 'RAIN'}},
- ['RAIN'] = {"Rainy", {2, 3}, {'THUNDER', 'CLOUDS'}},
- ['THUNDER'] = {"Stormy", {1, 3}, {'CLEAR', 'EXTRASUNNY'}},
- }
- -- Below is garbagem don't look at it
- cw=weather;wd=WeatherData;fm="%-10s";du=math.random(wd[cw][2][1],wd[cw][2][2])function Progress()du=du-1;if du<=0 then local a=wd[cw]if not a then error('invalid resolver for '..cw)end;cw=a[3][math.random(#a[3])]du=math.random(wd[cw][2][1],wd[cw][2][2])end;return cw end;cwsPerType={}print("Running simulation for",iterations,"iterations starting at",cw)for b=0,iterations do cwsPerType[cw]=(cwsPerType[cw]or 0)+1;local c=cw;Progress()end;print("Simulation ended on",cw)print(fm:format("FREQUENCY"),fm:format("WEATHER TYPE"),fm:format("OCCURENCES"))wc={}for d,e in next,cwsPerType do table.insert(wc,{t=d,o=e})end;table.sort(wc,function(f,g)return f.o>g.o end)for h,i in next,wc do print(fm:format(math.floor(10000/iterations*i.o)/100 .."%"),fm:format(wd[i.t][1]),fm:format(i.o))end
Add Comment
Please, Sign In to add comment