News for hackers. Stuff that matters.
Re:Spaceplan by christiangenco on Saturday August 13, 2016 @05:06AM (#12280836)
I love it! Found myself doing mental calculations for the most effective thing to buy next, and the next thing I knew I'd written a script to automatically buy it:

    var clickBestThing = function(){
       var things = [...document.querySelectorAll("#manufacture__container > div")].map(function(e){
        var res = {e};
        [...e.getElementsByTagName("span")].map(function(s){
          res[s.id] = +s.innerText.replace(/[^0-9]/g, '')
        })
        if(e.id === "item__spudGun" || e.id === "item__potatoLauncher") res.powerGain *= 1000;
        res.score = res.cost / res.powerGain;
        // res.score = res.cost / res.spudGain;
        res.name = e.getElementsByClassName("manufacture__name")[0].innerText;
        return res
      }).sort(function(a,b){return a.score - b.score})

      window.things = things;

      var bestThing = things[0];
      if(!things[things.length-1].score) bestThing = things[things.length-1]
      console.info("clicking " + bestThing.name)
      things[0].e.click();
    }
    var timer = setInterval(clickBestThing, 5000)
Of course it's much easier to `power = 999...`, but this feels more like automation and less like cheating.
Re:Spaceplan by TusanHomichi on Saturday August 13, 2016 @10:08AM (#12281558)
You can actually improve this a little with a better scoring function. Suppose we currently produce p, and A costs cA, for a power gain of pA. Likewise for B. Under the assumption that we will buy at least one more of A and B, we can look at whether A then B or B then A is faster, which is:

cA/p + cB/(p+pA) < cB/p + cA/(p+pA)

Solving this, we get cA * (p+pA)/pA < cB * (p+pB)/pB Since the left side is all in A, if we pick the item minimizing that quantity, it is faster to buy it before any other item. So changing res.score to be res.cost * (cur_power + res.powerGain)/res.powerGain is going to be a bit faster

Re:Spaceplan by christiangenco on Sunday August 14, 2016 @01:53AM (#12284429)
Ahh of course! I had the thought to take this into account but couldn't wrap my head around the math last night.

cA/p is just the time it would take to earn the money to buy A at the current production level - seems much simpler now.

I think the last term should be `cA/(p+pB)`. When I solve from there[1] I get `cB * pB < cA * pA`, which means that the most optimal item A will have the largest product `cA * pA`.

This would translate to:

    res.score = res.cost*res.powerGain
    ...
    }).sort(function(a,b){return b.score - a.score})   
Does that check out? It seems too simple, and now that I'm thinking more about it I think this would be functionally equal to what I already have. Did I do my inequality[1] wrong?

1. http://i.imgur.com/pyMY3zr.jpg

Re:Spaceplan by thexa4 on Saturday August 13, 2016 @11:00AM (#12281725)
Slight modification so it doesn't automatically buys the item but just highlights the best one

https://gist.github.com/thexa4/2da63028a1d8007dedbd0ba9432c8...

Re:Spaceplan by smaddox on Saturday August 13, 2016 @05:54PM (#12283258)
Re:Spaceplan by niix on Saturday August 13, 2016 @08:52AM (#12281269)
Nice! After clicking the button a few times my first inclination was also to open the console and see how I could make my life easier.
Re:Spaceplan by drewamox on Saturday August 13, 2016 @07:13AM (#12281055)
Typical Noob idiot coming through, first of all i've got to praise you for doing that the amount of effort that took must be high, but being the typical noob idiot I am I have to also wonder how I actually use this? reply
Re:Spaceplan by christiangenco on Sunday August 14, 2016 @01:17AM (#12284359)
No need to be self deprecating - this isn't 4chan :)

Copy and paste the code in your browser's javascript console. In Chrome it's under View/Developer/JavaScript Console.

For a good intro on how this works: https://www.khanacademy.org/computing/computer-programming/h...