Advertisement
VikeStep

Route Finder

Oct 6th, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. local combos = io.open("combos.txt","r")
  2. currBestTime = 99999
  3. currBestRoute = ""
  4. cost = {15, 100, 500, 3000, 10000, 40000, 200000}
  5. cps = {0.1, 0.5, 4, 10, 40, 100, 400}
  6.  
  7. function split(pString, pPattern)
  8. numchanged = 0
  9. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  10. local fpat = "(.-)" .. pPattern
  11. local last_end = 1
  12. local s, e, cap = pString:find(fpat, 1)
  13. while s do
  14. if s ~= 1 or cap ~= "" then
  15. table.insert(Table,cap)
  16. numchanged = numchanged +1
  17. end
  18. last_end = e+1
  19. s, e, cap = pString:find(fpat, last_end)
  20. end
  21. if last_end <= #pString then
  22. cap = pString:sub(last_end)
  23. table.insert(Table, cap)
  24. numchanged = numchanged +1
  25. end
  26. return Table
  27. end
  28.  
  29. function round(num)
  30. local upper = math.ceil(num)-num
  31. local lower = num-math.floor(num)
  32. if upper > lower then
  33. return(num - lower)
  34. elseif lower > upper then
  35. return(upper + num)
  36. elseif lower == upper then
  37. return(upper + num)
  38. end
  39. end
  40.  
  41. function resetVariables()
  42. bought = {0,0,0,0,0,0,0}
  43. bank = 0
  44. total = 0
  45. currCPS = 7.576
  46. currCost = {15, 100, 500, 3000, 10000, 40000, 200000}
  47. --print(unpack(currCost))
  48. end
  49.  
  50. function determineTime(inputData)
  51. resetVariables()
  52. local it = 0
  53. local completed = false
  54. while it < currBestTime and completed == false do
  55. --while completed == false do
  56. it = it + 1
  57. bank = bank + currCPS
  58. total = total + currCPS
  59. local tower = 1
  60. local stillBuying = false
  61. local count = 1
  62. while not stillBuying and count < 8 do
  63. if tonumber(inputData[count]) > 0 then
  64. tower = count
  65. stillBuying = true
  66. end
  67. count = count + 1
  68. end
  69. if stillBuying and currCost[tower] < bank then
  70. bought[tower] = bought[tower]+1
  71. bank = bank - currCost[tower]
  72. inputData[tower] = tostring(tonumber(inputData[tower]) - 1)
  73. currCost[tower] = round(cost[tower] * (1.15 ^ bought[tower]))
  74. currCPS = currCPS + cps[tower]
  75. end
  76. if total > 999999 then
  77. completed = true
  78. end
  79. end
  80. --wait = io.read()
  81. --print(it)
  82. return({completed, it})
  83. end
  84.  
  85. lineNumber = 0
  86. for line in io.lines("combos.txt") do
  87. route = determineTime(split(line, ", "))
  88. if route[1] then
  89. currBestTime = route[2]
  90. currBestRoute = line
  91. print("Time: "..currBestTime..", Route: "..currBestRoute)
  92. end
  93. lineNumber = lineNumber + 1
  94. --print(lineNumber)
  95. end
  96.  
  97. combos:close()
  98.  
  99. print("Time: "..currBestTime..", Route: "..unpack(currBestRoute))
  100.  
  101. wait = io.read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement