Advertisement
Znailxxor

Untitled

Jun 3rd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.70 KB | None | 0 0
  1. Aspects = {
  2.     aer = {
  3.         name = "Aer",
  4.         tier = 1
  5.     },
  6.     aqua = {
  7.         name = "Aqua",
  8.         tier = 1
  9.     },
  10.     ignis = {
  11.         name = "Ignis",
  12.         tier = 1
  13.     },
  14.     ordo = {
  15.         name = "Ordo",
  16.         tier = 1
  17.     },
  18.    
  19.     perditio = {
  20.         name = "Perditio",
  21.         tier = 1
  22.     },
  23.     terra = {
  24.         name = "Terra",
  25.         tier = 1
  26.     },
  27.     gelum = {
  28.         name = "Gelum",
  29.         tier = 2
  30.     },
  31.     lux = {
  32.         name = "Lux",
  33.         tier = 2
  34.     },
  35.     motus = {
  36.         name = "Motus",
  37.         tier = 2
  38.     },
  39.     permutatio = {
  40.         name = "Permutatio",
  41.         tier = 2
  42.     },
  43.     potentia = {
  44.         name = "Potentia",
  45.         tier = 2
  46.     },
  47.     tempestas = {
  48.         name = "Tempestas",
  49.         tier = 2
  50.     },
  51.     vacuos = {
  52.         name = "Vacuos",
  53.         tier = 2
  54.     },
  55.     venenum = {
  56.         name = "Venenum",
  57.         tier = 2
  58.     },
  59.     victus = {
  60.         name = "Victus",
  61.         tier = 2
  62.     },
  63.     vitreus = {
  64.         name = "Vitreus",
  65.         tier = 2
  66.     },
  67.     herba = {
  68.         name = "Herba",
  69.         tier = 3
  70.     },
  71.     iter = {
  72.         name = "Iter",
  73.         tier = 3
  74.     },
  75.     limus = {
  76.         name = "Limus",
  77.         tier = 3
  78.     },
  79.     metallum = {
  80.         name = "Metallum",
  81.         tier = 3
  82.     },
  83.     mortuus = {
  84.         name = "Mortuus",
  85.         tier = 3
  86.     },
  87.     sano = {
  88.         name = "Sano",
  89.         tier = 3
  90.     },
  91.     tempus = {
  92.         name = "Tempus",
  93.         tier = 3
  94.     },
  95.     vinculum = {
  96.         name = "Vinculum",
  97.         tier = 3
  98.     },
  99.     volatus = {
  100.         name = "Volatus",
  101.         tier = 3
  102.     },
  103.     bestia = {
  104.         name = "Bestia",
  105.         tier = 4
  106.     },
  107.     fames = {
  108.         name = "Fames",
  109.         tier = 4
  110.     },
  111.     praecantatio = {
  112.         name = "Praecantatio",
  113.         tier = 4
  114.     },
  115.     tenebrae = {
  116.         name = "Tenebrae",
  117.         tier = 4
  118.     },
  119.     arbor = {
  120.         name = "Arbor",
  121.         tier = 4
  122.     },
  123.     infernus = {
  124.         name = "Infernus",
  125.         tier = 5
  126.     },
  127.     auram = {
  128.         name = "Auram",
  129.         tier = 5
  130.     },
  131.     examinis = {
  132.         name = "Examinis",
  133.         tier = 5
  134.     },
  135.     spiritus = {
  136.         name = "Spiritus",
  137.         tier = 5
  138.     },
  139.     superbia = {
  140.         name = "Superbia",
  141.         tier = 5
  142.     },
  143.     vitium = {
  144.         name = "Vitium",
  145.         tier = 5
  146.     },
  147.     alienis = {
  148.         name = "Alienis",
  149.         tier = 6
  150.     },
  151.     gula = {
  152.         name = "Gula",
  153.         tier = 6
  154.     },
  155.     cognito = {
  156.         name = "Cognito",
  157.         tier = 6
  158.     },
  159.     sensus = {
  160.         name = "Sensus",
  161.         tier = 6
  162.     },
  163.     corpus = {
  164.         name = "Corpus",
  165.         tier = 7
  166.     },
  167.     desidia = {
  168.         name = "Desidia",
  169.         tier = 8
  170.     },
  171.     humanus = {
  172.         name = "Humanus",
  173.         tier = 10
  174.     },
  175.     invidia = {
  176.         name = "Invidia",
  177.         tier = 10
  178.     },
  179.     luxuria = {
  180.         name = "Luxuria",
  181.         tier = 11
  182.     },
  183.     instrumentum = {
  184.         name = "Instrumentum",
  185.         tier = 11
  186.     },
  187.     perfodio = {
  188.         name = "Perfodio",
  189.         tier = 11
  190.     },
  191.     telum = {
  192.         name = "Telum",
  193.         tier = 12
  194.     },
  195.     tutamen = {
  196.         name = "Tutamen",
  197.         tier = 12
  198.     },
  199.     messis = {
  200.         name = "Messis",
  201.         tier = 13
  202.     },
  203.     ira = {
  204.         name = "Ira",
  205.         tier = 13
  206.     },
  207.     machina = {
  208.         name = "Machina",
  209.         tier = 13
  210.     },
  211.     lucrum = {
  212.         name = "Lucrum",
  213.         tier = 14
  214.     },
  215.     pannus = {
  216.         name = "Pannus",
  217.         tier = 15
  218.     },
  219.     fabrico = {
  220.         name = "Fabrico",
  221.         tier = 21
  222.     },
  223.     meto = {
  224.         name = "Meto",
  225.         tier = 24
  226.     }
  227. }
  228.  
  229. -- Links
  230. Aspects.venenum.links = { Aspects.aqua, Aspects.perditio }
  231. Aspects.pannus.links = { Aspects.instrumentum, Aspects.bestia }
  232. Aspects.perditio.links = { Aspects.vacuos, Aspects.gelum, Aspects.venenum, Aspects.permutatio, Aspects.mortuus, Aspects.vitium, Aspects.vinculum }
  233. Aspects.humanus.links = { Aspects.bestia, Aspects.cognito, Aspects.messis, Aspects.perfodio, Aspects.instrumentum, Aspects.lucrum, Aspects.fabrico }
  234. Aspects.lux.links = { Aspects.aer, Aspects.ignis, Aspects.tenebrae }
  235. Aspects.telum.links = { Aspects.instrumentum, Aspects.ignis, Aspects.ira }
  236. Aspects.corpus.links = { Aspects.mortuus, Aspects.bestia, Aspects.luxuria }
  237. Aspects.potentia.links = { Aspects.ordo, Aspects.ignis, Aspects.praecantatio }
  238. Aspects.vacuos.links = { Aspects.aer, Aspects.perditio, Aspects.tenebrae, Aspects.alienis, Aspects.praecantatio, Aspects.fames, Aspects.superbia, Aspects.gula, Aspects.tempus }
  239. Aspects.praecantatio.links = { Aspects.vacuos, Aspects.potentia, Aspects.auram, Aspects.vitium, Aspects.infernus }
  240. Aspects.spiritus.links = { Aspects.victus, Aspects.mortuus, Aspects.cognito, Aspects.sensus, Aspects.desidia }
  241. Aspects.examinis.links = { Aspects.motus, Aspects.mortuus }
  242. Aspects.tutamen.links = { Aspects.instrumentum, Aspects.terra }
  243. Aspects.vinculum.links = { Aspects.motus, Aspects.perditio, Aspects.desidia }
  244. Aspects.superbia.links = { Aspects.volatus, Aspects.vacuos }
  245. Aspects.fames.links = { Aspects.victus, Aspects.vacuos, Aspects.lucrum, Aspects.luxuria, Aspects.gula, Aspects.invidia }
  246. Aspects.gelum.links = { Aspects.ignis, Aspects.perditio }
  247. Aspects.aer.links = { Aspects.vacuos, Aspects.lux, Aspects.tempestas, Aspects.motus, Aspects.volatus, Aspects.auram, Aspects.arbor, Aspects.sensus }
  248. Aspects.vitreus.links = { Aspects.terra, Aspects.ordo, Aspects.metallum }
  249. Aspects.limus.links = { Aspects.victus, Aspects.aqua }
  250. Aspects.vitium.links = { Aspects.praecantatio, Aspects.perditio }
  251. Aspects.tenebrae.links = { Aspects.vacuos, Aspects.lux, Aspects.alienis }
  252. Aspects.victus.links = { Aspects.aqua, Aspects.terra, Aspects.mortuus, Aspects.spiritus, Aspects.sano, Aspects.limus, Aspects.herba, Aspects.bestia, Aspects.fames }
  253. Aspects.lucrum.links = { Aspects.humanus, Aspects.fames }
  254. Aspects.ignis.links = { Aspects.lux, Aspects.gelum, Aspects.potentia, Aspects.cognito, Aspects.telum, Aspects.infernus, Aspects.ira }
  255. Aspects.tempestas.links = { Aspects.aer, Aspects.aqua }
  256. Aspects.meto.links = { Aspects.messis, Aspects.instrumentum }
  257. Aspects.sano.links = { Aspects.victus, Aspects.ordo }
  258. Aspects.messis.links = { Aspects.herba, Aspects.humanus, Aspects.meto }
  259. Aspects.iter.links = { Aspects.motus, Aspects.terra }
  260. Aspects.permutatio.links = { Aspects.perditio, Aspects.ordo }
  261. Aspects.infernus.links = { Aspects.ignis, Aspects.praecantatio }
  262. Aspects.tempus.links = { Aspects.vacuos, Aspects.ordo }
  263. Aspects.aqua.links = { Aspects.tempestas, Aspects.victus, Aspects.venenum, Aspects.limus }
  264. Aspects.motus.links = { Aspects.aer, Aspects.ordo, Aspects.volatus, Aspects.iter, Aspects.bestia, Aspects.examinis, Aspects.machina, Aspects.vinculum }
  265. Aspects.perfodio.links = { Aspects.humanus, Aspects.terra }
  266. Aspects.alienis.links = { Aspects.vacuos, Aspects.tenebrae }
  267. Aspects.metallum.links = { Aspects.terra, Aspects.vitreus }
  268. Aspects.ordo.links = { Aspects.motus, Aspects.vitreus, Aspects.potentia, Aspects.permutatio, Aspects.sano, Aspects.instrumentum, Aspects.tempus }
  269. Aspects.desidia.links = { Aspects.vinculum, Aspects.spiritus }
  270. Aspects.fabrico.links = { Aspects.humanus, Aspects.instrumentum }
  271. Aspects.cognito.links = { Aspects.ignis, Aspects.spiritus, Aspects.humanus }
  272. Aspects.terra.links = { Aspects.vitreus, Aspects.victus, Aspects.metallum, Aspects.iter, Aspects.herba, Aspects.perfodio, Aspects.tutamen }
  273. Aspects.sensus.links = { Aspects.aer, Aspects.spiritus }
  274. Aspects.ira.links = { Aspects.telum, Aspects.ignis }
  275. Aspects.bestia.links = { Aspects.motus, Aspects.victus, Aspects.corpus, Aspects.humanus, Aspects.pannus }
  276. Aspects.volatus.links = { Aspects.aer, Aspects.motus, Aspects.superbia }
  277. Aspects.instrumentum.links = { Aspects.humanus, Aspects.ordo, Aspects.meto, Aspects.telum, Aspects.tutamen, Aspects.fabrico, Aspects.pannus, Aspects.machina }
  278. Aspects.auram.links = { Aspects.praecantatio, Aspects.aer }
  279. Aspects.herba.links = { Aspects.victus, Aspects.terra, Aspects.arbor, Aspects.messis }
  280. Aspects.luxuria.links = { Aspects.corpus, Aspects.fames }
  281. Aspects.gula.links = { Aspects.fames, Aspects.vacuos }
  282. Aspects.invidia.links = { Aspects.sensus, Aspects.fames }
  283. Aspects.arbor.links = { Aspects.aer, Aspects.herba }
  284. Aspects.mortuus.links = { Aspects.victus, Aspects.perditio, Aspects.spiritus, Aspects.corpus, Aspects.examinis }
  285. Aspects.machina.links = { Aspects.motus, Aspects.instrumentum }
  286.  
  287. -- colors
  288. Aspects.venenum.colors = { text = colors.lime, background = colors.black }
  289. Aspects.pannus.colors = { text = colors.yellow, background = colors.white }
  290. Aspects.perditio.colors = { text = colors.lightGray, background = colors.gray }
  291. Aspects.humanus.colors = { text = colors.pink, background = colors.yellow }
  292. Aspects.lux.colors = { text = colors.orange, background = colors.yellow }
  293. Aspects.telum.colors = { text = colors.red, background = colors.lightGray }
  294. Aspects.corpus.colors = { text = colors.pink, background = colors.red }
  295. Aspects.potentia.colors = { text = colors.cyan, background = colors.white }
  296. Aspects.praecantatio.colors = { text = colors.pink, background = colors.magenta }
  297. Aspects.spiritus.colors = { text = colors.gray, background = colors.black }
  298. Aspects.examinis.colors = { text = colors.green, background = colors.gray }
  299. Aspects.tutamen.colors = { text = colors.cyan, background = colors.lightBlue }
  300. Aspects.vinculum.colors = { text = colors.pink, background = colors.brown }
  301. Aspects.superbia.colors = { text = colors.purple, background = colors.black }
  302. Aspects.fames.colors = { text = colors.red, background = colors.gray }
  303. Aspects.gelum.colors = { text = colors.lightBlue, background = colors.white }
  304. Aspects.aer.colors = { text = colors.white, background = colors.yellow }
  305. Aspects.vitreus.colors = { text = colors.white, background = colors.lightBlue }
  306. Aspects.limus.colors = { text = colors.lime, background = colors.yellow }
  307. Aspects.vitium.colors = { text = colors.magenta, background = colors.purple }
  308. Aspects.tenebrae.colors = { text = colors.black, background = colors.black }
  309. Aspects.victus.colors = { text = colors.magenta, background = colors.red }
  310. Aspects.lucrum.colors = { text = colors.yellow, background = colors.orange }
  311. Aspects.ignis.colors = { text = colors.yellow, background = colors.red }
  312. Aspects.tempestas.colors = { text = colors.gray, background = colors.white }
  313. Aspects.vacuos.colors = { text = colors.gray, background = colors.lightGray }
  314. Aspects.meto.colors = { text = colors.brown, background = colors.orange }
  315. Aspects.sano.colors = { text = colors.red, background = colors.magenta }
  316. Aspects.messis.colors = { text = colors.brown, background = colors.yellow }
  317. Aspects.iter.colors = { text = colors.brown, background = colors.red }
  318. Aspects.permutatio.colors = { text = colors.gray, background = colors.green }
  319. Aspects.infernus.colors = { text = colors.orange, background = colors.red }
  320. Aspects.tempus.colors = { text = colors.gray, background = colors.purple }
  321. Aspects.aqua.colors = { text = colors.lightBlue, background = colors.cyan }
  322. Aspects.motus.colors = { text = colors.white, background = colors.gray }
  323. Aspects.perfodio.colors = { text = colors.brown, background = colors.gray }
  324. Aspects.alienis.colors = { text = colors.brown, background = colors.purple }
  325. Aspects.metallum.colors = { text = colors.brown, background = colors.lightGray }
  326. Aspects.ordo.colors = { text = colors.white, background = colors.lightGray }
  327. Aspects.desidia.colors = { text = colors.black, background = colors.gray }
  328. Aspects.fabrico.colors = { text = colors.green, background = colors.lightGray }
  329. Aspects.cognito.colors = { text = colors.pink, background = colors.lightGray }
  330. Aspects.terra.colors = { text = colors.lime, background = colors.green }
  331. Aspects.sensus.colors = { text = colors.cyan, background = colors.blue }
  332. Aspects.ira.colors = { text = colors.red, background = colors.black }
  333. Aspects.bestia.colors = { text = colors.gray, background = colors.brown }
  334. Aspects.volatus.colors = { text = colors.lightGray, background = colors.white }
  335. Aspects.instrumentum.colors = { text = colors.gray, background = colors.blue }
  336. Aspects.auram.colors = { text = colors.magenta, background = colors.pink }
  337. Aspects.herba.colors = { text = colors.green, background = colors.lime }
  338. Aspects.luxuria.colors = { text = colors.white, background = colors.pink }
  339. Aspects.gula.colors = { text = colors.yellow, background = colors.brown }
  340. Aspects.invidia.colors = { text = colors.lime, background = colors.gray }
  341. Aspects.arbor.colors = { text = colors.green, background = colors.brown }
  342. Aspects.mortuus.colors = { text = colors.pink, background = colors.gray }
  343. Aspects.machina.colors = { text = colors.purple, background = colors.gray }
  344.  
  345. monitor = peripheral.find("monitor")
  346. monitor.clear()
  347. monitor.setTextScale(1)
  348. belowAspects = 1
  349. maxX, maxY = monitor.getSize()
  350. buttons = {}
  351.  
  352. for _, v in pairs(Aspects) do
  353.     table.sort(v.links, function(a, b) return a.tier < b.tier end)
  354. end
  355.  
  356. sortedAspects = {}
  357. for _, v in pairs(Aspects) do
  358.     sortedAspects[#sortedAspects+1] = v
  359. end
  360. table.sort(sortedAspects, function(a, b) return a.tier < b.tier end)
  361.  
  362. local goDeeper
  363. goDeeper = function(carry, goal, depth)
  364.     solutions = {}
  365.     newSolutions = {}
  366.     if depth == 0 then
  367.         if carry.name == goal.name then return true, {{goal}} end
  368.     else
  369.         for _, v in pairs(carry.links) do
  370.             result, newSolutions = goDeeper(v, goal, depth - 1)
  371.             if result == true then
  372.                 for _, solution in newSolutions do
  373.                     solution[#solution+1] = carry
  374.                     solutions[#solutions+1] = solution
  375.                 end
  376.             end
  377.         end
  378.         if #solutions > 0 then
  379.             return true, solutions
  380.         else
  381.             return false
  382.         end
  383.     end
  384. end
  385.  
  386. function findCheapest(a1, a2, iterations)
  387.     solutions = goDeeper(a1, a2, iterations)
  388.     print(textutils.serialize(solutions))
  389. end
  390.  
  391. function tryButton(x, y)
  392.     for _, button in pairs(buttons) do
  393.         if x >= button.x and x <= button.x + button.w and y == button.y then
  394.             return unpack(button.response)
  395.         end
  396.     end
  397.     return "not a button at "..tostring(x)..", "..tostring(y)
  398. end
  399.  
  400. function makeButton(x, y, w, response)
  401.     buttons[#buttons+1]  = {x = x, y = y, w = w, response = response}
  402. end
  403.  
  404. function drawButton(x, y, text, textColor, backColor)
  405.     monitor.setCursorPos(x, y)
  406.     monitor.setTextColor(textColor)
  407.     monitor.setBackgroundColor(backColor)
  408.     monitor.write(" "..text.." ")
  409.     monitor.setTextColor(colors.white)
  410.     monitor.setBackgroundColor(colors.black)
  411. end
  412.  
  413. function makeAspectButton(aspect, x, y)
  414.     drawButton(x, y, aspect.name, aspect.colors.text, aspect.colors.background)
  415.     makeButton(x, y, string.len(aspect.name) + 2, {"aspect", aspect})
  416. end
  417.  
  418. function makeAspectButtons()
  419.     x = 2
  420.     y = 2
  421.     for _, aspect in pairs(sortedAspects) do
  422.         if x + string.len(aspect.name) + 2 > maxX then
  423.             x = 2
  424.             y = y + 2
  425.         end
  426.         makeAspectButton(aspect, x, y)
  427.         x = x + string.len(aspect.name) + 3
  428.     end
  429.     return x, y
  430. end
  431.  
  432. step = "prep1"
  433.  
  434. while 1 do
  435.     if step == "prep1" then
  436.         buttons = {}
  437.         currentAspect = nil
  438.         currentAspect2 = nil
  439.         monitor.clear()
  440.         _, y = makeAspectButtons()
  441.         x = 2
  442.         y = y + 2
  443.         belowAspects = y
  444.         monitor.setCursorPos(x, y)
  445.         monitor.write("Select an aspect to start")
  446.         step = "input1"
  447.     end
  448.    
  449.     if step == "input1" then
  450.         response = nil
  451.         aspect = nil
  452.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  453.         response, aspect = tryButton(xPos, yPos)
  454.         if aspect then
  455.             currentAspect = aspect
  456.             step = "prep2"
  457.         end
  458.     end
  459.    
  460.     if step == "prep2" then
  461.         buttons = {}
  462.         currentAspect2 = nil
  463.         monitor.clear()
  464.         _, y = makeAspectButtons()
  465.         x = 2
  466.         y = y + 2
  467.         monitor.setCursorPos(x, y)
  468.         monitor.write("Select another aspect")
  469.         x = 2
  470.         y = y + 2
  471.         monitor.setCursorPos(x, y)
  472.         monitor.write("Current selection: ")
  473.         x = 22
  474.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  475.         y = y + 2
  476.         drawButton(x, y, "Cancel", colors.red, colors.white)
  477.         makeButton(x, y, 8, {"cancel"})
  478.         step = "input2"
  479.     end
  480.    
  481.     if step == "input2" then
  482.         response = nil
  483.         aspect = nil
  484.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  485.         response, aspect = tryButton(xPos, yPos)
  486.         if aspect then
  487.             currentAspect2 = aspect
  488.             step = "prep3"
  489.         else
  490.             if response == "cancel" then
  491.                 step = "prep1"
  492.             end
  493.         end
  494.     end
  495.    
  496.     if step == "prep3" then
  497.         buttons = {}
  498.         monitor.clear()
  499.         x = 2
  500.         y = belowAspects - 2
  501.         for i = 0, 8, 1 do
  502.             drawButton(x + 4*i, y, tostring(i+1), colors.black, colors.white)
  503.             makeButton(x + 4*i, y, 3, {"number", i+1})
  504.         end
  505.         x = 2
  506.         y = y + 2
  507.         monitor.setCursorPos(x, y)
  508.         monitor.write("Select the number of aspects between the two")
  509.         x = 2
  510.         y = y + 2
  511.         monitor.setCursorPos(x, y)
  512.         monitor.write("Current selection: ")
  513.         x = 22
  514.         drawButton(x, y, currentAspect.name, currentAspect.colors.text, currentAspect.colors.background)
  515.         x = x + string.len(currentAspect.name) + 3
  516.         drawButton(x, y, currentAspect2.name, currentAspect2.colors.text, currentAspect2.colors.background)
  517.         y = y + 2
  518.         drawButton(2, y, "Cancel", colors.red, colors.white)
  519.         makeButton(2, y, 8, {"cancel"})
  520.         drawButton(11, y, "Undo", colors.yellow, colors.gray)
  521.         makeButton(11, y, 6, {"undo"})
  522.         step = "input3"
  523.     end
  524.    
  525.     if step == "input3" then
  526.         response = nil
  527.         number = nil
  528.         event, _, xPos, yPos = os.pullEvent("monitor_touch")
  529.         response, number = tryButton(xPos, yPos)
  530.         print(response)
  531.         if number then
  532.             iterations = number
  533.             step = "calc1"
  534.         elseif response == "cancel" then
  535.             step = "prep1"
  536.         elseif response == "undo" then
  537.             step = "prep2"
  538.         end
  539.     end
  540.    
  541.     if step == "calc1" then
  542.         monitor.clear()
  543.         monitor.setCursorPos(2, belowAspects)
  544.         monitor.write("Calculating...")
  545.         solutions = findCheapest(currentAspect, currentAspect2, iterations + 2)
  546.     end
  547.    
  548. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement