glitchdetector

Tycoon Weather Simulator

Apr 21st, 2021 (edited)
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. -- Tycoon Weather Simulator by glitchdetector, use https://www.lua.org/cgi-bin/demo to run
  2. iterations = 72 -- Cycles to run
  3. weather = 'EXTRASUNNY' -- Starting weather
  4. WeatherData = {
  5.   --[WEATHER] = {NAME, {MIN_CYCLES, MAX_CYCLES}, NEXT_TYPES},
  6.     ['EXTRASUNNY'] =    {"Extra Sunny",     {1, 1},     {'CLEAR', 'CLEARING'}},
  7.     ['CLEAR'] =         {"Clear",           {1, 1},     {'EXTRASUNNY', 'OVERCAST'}},
  8.     ['SMOG'] =          {"Smoggy",          {1, 1},     {'EXTRASUNNY', 'OVERCAST'}},
  9.     ['FOGGY'] =         {"Foggy",           {1, 1},     {'EXTRASUNNY', 'CLEARING'}},
  10.     ['OVERCAST'] =      {"Overcast",        {1, 1},     {'SMOG', 'EXTRASUNNY'}},
  11.     ['CLOUDS'] =        {"Cloudy",          {1, 1},     {'FOGGY', 'EXTRASUNNY'}},
  12.     ['CLEARING'] =      {"Drizzling",       {1, 1},     {'CLEAR', 'RAIN'}},
  13.     ['RAIN'] =          {"Rainy",           {2, 3},     {'THUNDER', 'CLOUDS'}},
  14.     ['THUNDER'] =       {"Stormy",          {1, 3},     {'CLEAR', 'EXTRASUNNY'}},
  15. }
  16. -- Below is garbagem don't look at it
  17. 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