Skip to content

Instantly share code, notes, and snippets.

@RSNara
Last active March 31, 2016 22:13
Show Gist options
  • Save RSNara/3f528b118b24669edbfe to your computer and use it in GitHub Desktop.
Save RSNara/3f528b118b24669edbfe to your computer and use it in GitHub Desktop.
(() => {
const cookie = document.getElementById('bigCookie');
(function loop() {
setTimeout(loop);
cookie.dispatchEvent(new MouseEvent('click', { bubbles: true}));
})();
})();
function itemRatio(item) {
return item.cps(item) / item.price;
}
function getItemCps(item) {
return item.cps(item);
}
(function loop() {
const cookies = Game.cookies;
const cps = Game.cookiesPs;
const allItems = Object.keys(Game.ObjectsById).map((key) => {
return Game.ObjectsById[key];
});
const itemsCanBuy = allItems.filter((item) => item.price < cookies);
const bestItemCanBuy = bestItem(itemsCanBuy);
const bestItemToBuy = bestItem(allItems);
if (bestItemCanBuy && bestItemToBuy) {
printItem('Best item to buy', bestItemToBuy);
printItem('Best item can buy', bestItemCanBuy);
const cpsWithBestItemCanBuyBought = cps + getItemCps(bestItemCanBuy);
const cookiesWithBestItemCanBuyBought = cookies - bestItemCanBuy.price;
console.log("ratio with bought best can buy: " + (bestItemToBuy.price - cookiesWithBestItemCanBuyBought) / cpsWithBestItemCanBuyBought );
console.log("ratio with waiting: " + (bestItemToBuy.price - cookies) / cps)
if (almostLessThan(
(bestItemToBuy.price - cookiesWithBestItemCanBuyBought) / cpsWithBestItemCanBuyBought,
(bestItemToBuy.price - cookies) / cps
)) {
bestItemCanBuy.buy();
window.bestItemCanBuyBought = (window.bestItemCanBuyBought || 0) + 1;
} else if (bestItemToBuy.price <= cookies) {
bestItemToBuy.buy();
}
}
setTimeout(loop, 1000);
})();
function almostLessThan(a, b) {
return a < 1.05 * b;
}
function printItem(label, item) {
console.log(label + ' : ' + item.displayName + ' (ratio: ' + itemRatio(item));
}
function bestItem(items) {
return items.reduce((max, current) => {
if (itemRatio(max) < itemRatio(current)) {
return current;
}
return max;
}, items[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment