Advertisement
guitarplayer616

Sc2 Simulator AI

Apr 30th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. --[[update = {
  2.     gather = function()
  3.        
  4.     energy()
  5.     construction()
  6.    
  7. }]]
  8.  
  9. --goal engine includes
  10.     --drone resource updates
  11.     --drone train time
  12.     --pool spawn time
  13.     --larvae spawn rate
  14.  
  15. minerals = 50
  16. gas = 0
  17. supply = 6
  18. supplycap = 14
  19.  
  20. pool = false
  21. queen = 1
  22. local startTime = os.clock()
  23. t = math.floor(os.clock() - startTime)
  24. local gametick = 1
  25.  
  26.  
  27. --if timeTable
  28. timeTable = {
  29.     ["assign"] = function(t,func)
  30.         if not timeTable[t] then
  31.             timeTable[t] = {}
  32.         end
  33.         table.insert(timeTable[t],func)
  34.     end,
  35.     --doesn't take floating times
  36.     --doesn't take 2 events at same time
  37. }
  38.  
  39. units = {
  40.     ["drone"] = {
  41.         ["update"] = function(self)
  42.             minerals = minerals + (gametick*(self.number * self.rate))
  43.         end,
  44.         ["number"] = 12,
  45.         ["rate"] = 1.2852,
  46.         ["train"] = function()
  47.             minerals = minerals - 75
  48.             supply = supply + 1
  49.             units.larvae.number = units.larvae.number - 1
  50.             --assign to t = number
  51.             if not timeTable[t+22] then
  52.                 timeTable[t+22] = {}   
  53.             end
  54.             table.insert(timeTable[t+22],function()
  55.                 units.drone.number = units.drone.number + 2;
  56.             end)
  57.         end,
  58.     },
  59.     ["larvae"] = {
  60.         ["number"] = 3,
  61.         ["spawning"] = false,
  62.         ["update"] = function(self)
  63.             if not self.spawning and self.number<6 then
  64.                 --should be 12.5
  65.                 self.spawning = true
  66.                 if not timeTable[t+12] then
  67.                     timeTable[t+12] = {}   
  68.                 end
  69.                 table.insert(timeTable[t+12],function()
  70.                     units.larvae.number = units.larvae.number + 1
  71.                     units.larvae.spawning = false
  72.                 end)
  73.             end
  74.         end,
  75.     },
  76.     ["queen"] = {
  77.         ["update"] = function()
  78.         end,
  79.         ["number"] = 0,
  80.         ["rate"] = .69,
  81.         ["energy"] = 0,
  82.         ["cost"] = 150,
  83.     },
  84.     ["ling"] = {
  85.         ["update"] = function()
  86.         end,
  87.         ["number"] = 0,
  88.         ["cost"] = 44,
  89.     },
  90.     ["overlord"] = {
  91.         ["number"] = 0,
  92.         ["train"] = function()
  93.             minerals = minerals - 100
  94.             units.larvae.number = units.larvae.number - 1
  95.             timeTable.assign(t+21,
  96.             function()
  97.                 units.overlord.number = units.overlord.number + 1
  98.                 supplycap = supplycap + 8
  99.             end
  100.             )
  101.         end
  102.        
  103.     },
  104.    
  105.  
  106. }
  107.  
  108.  
  109. structures = {
  110.     ["pool"] = {
  111.         ["number"] = 0,
  112.         ["cost"] = 200,
  113.         ["constructionTime"] = 25
  114.     },
  115. }
  116.  
  117.  
  118. while true do
  119.     shell.run("clear")
  120.     --term.setCursorPos(1,1)
  121.     print("minerals: "..minerals)
  122.     print("gas: "..gas)
  123.     print("supply: "..supply.."/"..supplycap)
  124.     print()
  125.     print("larvae: "..units.larvae.number)
  126.     print("drones: "..units.drone.number)
  127.     print("overlords: "..units.overlord.number)
  128.     print()
  129.     print("time: "..t)
  130.    
  131.     local tick = os.startTimer(gametick)
  132.     local events = {os.pullEvent()}
  133.        
  134.  
  135.    
  136.    
  137.     if events[1] == "timer" and events[2] == tick then
  138.         --ai
  139.         if (supplycap - supply) <= 2 and minerals > 150 and units.larvae.number>0 then
  140.             units.overlord.train()
  141.         elseif minerals > 75 and supply+1<=supplycap and units.larvae.number>0 then
  142.             units.drone.train()
  143.         end
  144.        
  145.         for i,v in pairs(timeTable) do
  146.            
  147.             if tonumber(i) and t == (i*(1/gametick)) then
  148.                 --error("HIT")
  149.                 for _,f in pairs(v) do
  150.                     f()
  151.                 end
  152.             end
  153.         end
  154.         for i,v in pairs(units) do
  155.             if v.update then
  156.                 v:update()
  157.             end
  158.         end
  159.     end
  160.     t = math.floor(os.clock() - startTime)
  161.    
  162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement