Skip to content

Instantly share code, notes, and snippets.

@thexa4
Last active April 9, 2024 16:28
Show Gist options
  • Save thexa4/58c10a43d8daffbae7bfd79bfee0e9bd to your computer and use it in GitHub Desktop.
Save thexa4/58c10a43d8daffbae7bfd79bfee0e9bd to your computer and use it in GitHub Desktop.
Idle managers
// https://kittensgame.com/web/
var astronomyButton = document.getElementById("observeButton");
function buildBuilding(name) {
let buttons = gamePage.bldTab.children;
for (var b of buttons) {
if (b.model.name.startsWith(name)) {
if(b.model.enabled && b.controller.hasResources(b.model)) {
b.model.prices = b.controller.getPrices(b.model);
b.controller.payPrice(b.model);
b.controller.incrementValue(b.model);
return true;
}
}
}
return false;
}
function resourceAvailable(name, tresh) {
let resource = gamePage.resPool.get(name);
let limit = resource.maxValue * tresh;
if (limit <= resource.value + 1)
return Math.floor(resource.value - limit);
return 0;
}
function craftItem(item, num, divisor = 1) {
var amount = Math.floor(num / divisor);
let ratio = gamePage.getResCraftRatio(name);
amount = parseFloat((amount * (1 + ratio)).toFixed(2));
gamePage.craft(item, amount);
//console.log({item: item, amount: amount});
}
function doLoop() {
if (gamePage.perTickUI < 0) { return; }
// Observation
if (astronomyButton.children.length > 0)
astronomyButton.children[0].click();
// Catnip management
let catnip = gamePage.resPool.get('catnip');
let calendar = gamePage.calendar;
if (calendar.season == 0) // spring
{
let field = gamePage.bld.get('field');
let fieldPrice = gamePage.bld.getPrices('field')[0].val;
if (catnip.perTickCached > 0.1 && fieldPrice < catnip.value)
if (field.unlocked)
buildBuilding('Catnip Field');
}
if (catnip.value / catnip.maxValue > 0.95)
craftItem('wood', resourceAvailable('catnip', 0.95), 2350);
// Wood
let woodAvailable = resourceAvailable('wood', 0.95);
if (woodAvailable > 0)
craftItem('beam', woodAvailable, 700);
// Steel
let ironAvailable = resourceAvailable('iron', 0.95);
let coalAvailable = resourceAvailable('coal', 0.95);
if (ironAvailable > 100 && coalAvailable > 100)
craftItem('steel', Math.min(ironAvailable, coalAvailable), 100);
else if(ironAvailable > 125)
craftItem('plate', ironAvailable, 125);
// Slab
let stoneAvailable = resourceAvailable('stone', 0.95);
if (stoneAvailable > 0)
craftItem('slab', stoneAvailable, 1000);
// Culture
var cultureAvailable = resourceAvailable('culture', 0.90);
var fursAvailable = gamePage.resPool.get('furs').value - 100000;
if (fursAvailable > 0)
craftItem('parchment', fursAvailable, 5950);
var parchmentAvailable = gamePage.resPool.get('parchment').value;
if (cultureAvailable > 400 && parchmentAvailable > 25)
craftItem('manuscript', Math.min(cultureAvailable / 400, parchmentAvailable / 25));
// Compendium
var scienceAvailable = resourceAvailable('science', 0.80);
var manuscriptAvailable = gamePage.resPool.get('manuscript').value;
if (manuscriptAvailable > 1000 && scienceAvailable > 10000)
craftItem('compedium', scienceAvailable, 10000);
// Hunting
var catpowerAvailable = resourceAvailable('manpower', 0.95);
if (catpowerAvailable > 0)
gamePage.village.huntAll();
catpowerAvailable = resourceAvailable('manpower', 0.5);
let goldAvailable = resourceAvailable('gold', 0.95);
let slabAvailable = gamePage.resPool.get('slab').value;
// Trading
if (calendar.season == 1) // summer
{
let titaniumAvailable = resourceAvailable('titanium', 0.95);
if (catpowerAvailable > 0 && goldAvailable > 0 && slabAvailable > 50 && titaniumAvailable <= 0)
gamePage.diplomacy.trade(gamePage.diplomacy.races[4]);
}
// Faith
var faithAvailable = resourceAvailable('faith', 0.99);
if (faithAvailable > 1)
gamePage.religion.praise();
}
if (document.loopTimer != undefined) clearInterval(document.loopTimer);
document.loopTimer = setInterval(doLoop, 500);
// https://www.decisionproblem.com/paperclips/index2.html
document.nextPriceChange = Date.now();
document.nextInvestmentChange = Date.now();
document.nextFactory = Date.now();
document.nextProbeRole = Date.now();
document.nextTournament = Date.now();
document.nextSyncSwarm = null;
document.nextEntertainSwarm = null;
//document.nextProbeRoleButton = window.btnRaiseProbeFacElement;
document.maxProduction ||= 0;
document.pricePID ||= {
P: 0.2,
I: 0.01,
D: 0.1,
Last: null,
Sum: 0,
LastSample: Date.now(),
}
var body = document.getElementsByTagName('body')[0];
body.style.color = "#eee8d5";
body.style.background = "#002b36";
document.getElementById("giftShopDiv").style.display = "none";
function doLoop() {
let makeClipButton = window.btnMakePaperclip;
let buyWireButton = window.btnBuyWire;
let wireCost = window.wireCost;
let clipmakerRate = window.clipRate;
document.maxProduction = (9 * document.maxProduction + clipmakerRate) / 10;
if (document.maxProduction > clipmakerRate)
clipmakerRate = document.maxProduction;
let unsoldClips = window.unsoldClips;
let btnLowerPrice = window.btnLowerPrice;
let btnRaisePrice = window.btnRaisePrice;
let btnExpandMarketing = window.btnExpandMarketing;
let btnMakeClipper = window.btnMakeClipper;
let projectButtons = document.getElementsByClassName("projectButton");
let processors = window.processors;
let memory = window.memory;
let optics = window.btnQcomputeElement;
let chips = window.qChipsElements;
let btnMakeMegaClipper = window.btnMakeMegaClipper;
let stratPicker = window.stratPickerElement;
let btnNewTournament = window.btnNewTournament;
let btnRunTournament = window.btnRunTournament;
let btnImproveInvestments = window.btnImproveInvestments;
let investmentLevelLabel = window.investmentLevelElement;
let investmentLevel = investmentLevelLabel ? parseInt(investmentLevelLabel.innerHTML) : 0;
let btnInvest = window.btnInvest;
let btnWithdraw = window.btnWithdraw;
let investmentTotalValueLabel = window.portValue;
let investmentTotalValue = investmentTotalValueLabel ? parseFloat(investmentTotalValueLabel.innerHTML.replaceAll(',','')) : 0;
let investmentCashValueLabel = window.investmentBankroll;
let investmentCashValue = investmentCashValueLabel ? parseFloat(investmentCashValueLabel.innerHTML.replaceAll(',','')) : 0;
let fundsLabel = window.fundsElement;
let funds = fundsLabel ? parseFloat(fundsLabel.innerHTML.replaceAll(',','')) : 0;
let autoClipperCountLabel = window.clipmakerLevel2;
let autoClipperCount = autoClipperCountLabel ? parseInt(autoClipperCountLabel.innerHTML) : 0;
let megaClipperCountLabel = window.megaClipperLevelElement;
let megaClipperCount = megaClipperCountLabel ? parseInt(megaClipperCountLabel.innerHTML) : 0;
let marketingLevelLabel = window.marketingLvlElement;
let marketingLevel = marketingLevelLabel ? parseInt(marketingLevelLabel.innerHTML) : 0;
let investStrat = window.investStratElement;
let btnAddProc = window.btnAddProcElement;
let btnAddMem = window.btnAddMemElement;
let batteryCountLabel = window.batteryLevelElement;
let batteryCount = batteryCountLabel ? parseInt(batteryCountLabel.innerHTML.replaceAll(",","")) : 0;
let powerConsumptionLabel = window.powerConsumptionRateElement;
let powerConsumption = powerConsumptionLabel ? parseInt(powerConsumptionLabel.innerHTML.replaceAll(",", "")) : 0;
let solarCountLabel = window.farmLevelElement;
let solarCount = solarCountLabel ? parseInt(solarCountLabel.innerHTML.replaceAll(",","")) : 0;
let availableMatterDisplay = window.availableMatterDisplayElement;
let availableMatter = availableMatterDisplay ? availableMatterDisplay.innerHTML : "0";
let acquiredMatterDisplay = window.acquiredMatterDisplayElement;
let acquiredMatter = acquiredMatterDisplay ? acquiredMatterDisplay.innerHTML : "0";
let nanoWireDisplay = window.nanoWireElement;
let nanoWire = nanoWireDisplay ? nanoWireDisplay.innerHTML : "0";
let btnMakeFarm = window.btnMakeFarmElement;
let btnFarmx10 = window.btnFarmx10Element;
let btnMakeBattery = window.btnMakeBatteryElement;
let btnBatteryx10 = window.btnBatteryx10Element;
var btnMakeHarvester = window.btnMakeHarvesterElement;
let btnHarvesterx10 = window.btnHarvesterx10Element;
let btnHarvesterx100 = window.btnHarvesterx100Element;
let btnHarvesterx1000 = window.btnHarvesterx1000Element;
var btnMakeWireDrone = window.btnMakeWireDroneElement;
let btnWireDronex10 = window.btnWireDronex10Element;
let btnWireDronex100 = window.btnWireDronex100Element;
let btnWireDronex1000 = window.btnWireDronex1000Element;
let btnMakeFactory = window.btnMakeFactoryElement;
let workSlider = window.sliderElement;
let yomiDisplay = window.yomiDisplayElement;
let yomi = yomiDisplay ? parseInt(yomiDisplay.innerHTML.replaceAll(",","")) : 0;
let btnMakeProbe = window.btnMakeProbeElement;
if (btnMakeHarvester) {
if (btnHarvesterx10 && !btnHarvesterx10.disabled)
btnMakeHarvester = btnHarvesterx10;
if (btnHarvesterx100 && !btnHarvesterx100.disabled)
btnMakeHarvester = btnHarvesterx100;
if (btnHarvesterx1000 && !btnHarvesterx1000.disabled)
btnMakeHarvester = btnHarvesterx1000;
}
if (btnMakeWireDrone) {
if (btnWireDronex10 && !btnWireDronex10.disabled)
btnMakeWireDrone = btnWireDronex10;
if (btnWireDronex100 && !btnWireDronex100.disabled)
btnMakeWireDrone = btnWireDronex100;
if (btnWireDronex1000 && !btnWireDronex1000.disabled)
btnMakeWireDrone = btnWireDronex1000;
}
if (window.humanFlag && buyWireButton && !buyWireButton.disabled) {
let wireLabel = window.wireElement;
let wire = parseInt(wireLabel.innerHTML.replace(",",""));
let wireSeconds = wire / clipmakerRate;
if (wireCost <= 16 && wireSeconds < 600 || wire == 0) {
buyWireButton.click();
return;
}
}
if (window.humanFlag && document.nextPriceChange < Date.now()) {
let inventorySeconds = unsoldClips / document.maxProduction;
let target = 30;
let error = (target - inventorySeconds) / 30;
let deltaT = (Date.now() - document.pricePID.LastSample) / 100;
if (deltaT > 5 || deltaT < 0.01) {
document.pricePID.Last = error;
document.pricePID.LastSample = Date.now();
} else {
document.pricePID.Sum += error / deltaT;
if (document.pricePID.Sum > 100)
document.pricePID.Sum = 100;
if (document.pricePID.Sum < -100)
document.pricePID.Sum = -100;
var outcome = 0;
outcome += error * document.pricePID.P;
outcome += document.pricePID.Sum * document.pricePID.I;
if (document.pricePID.Last != null) {
outcome += (error - document.pricePID.Last) * document.pricePID.D / deltaT;
}
/*console.log({
seconds: inventorySeconds,
P: error * document.pricePID.P,
I: document.pricePID.Sum * document.pricePID.I,
D: (error - document.pricePID.Last) * document.pricePID.D,
"=": outcome
});*/
//console.log({seconds: inventorySeconds, unsold: unsoldClips, rate: clipmakerRate})
document.pricePID.Last = error;
document.pricePID.LastSample = Date.now();
let desiredPriceChange = (outcome - window.margin) * 100;
if (desiredPriceChange < -0.5 && !btnLowerPrice.disabled) {
//document.nextPriceChange = Date.now() + 1 * 1000;
btnLowerPrice.click();
return;
}
if (desiredPriceChange > 0.5 && !btnRaisePrice.disabled) {
//document.nextPriceChange = Date.now() + 1 * 1000;
btnRaisePrice.click();
return;
}
}
}
if (window.humanFlag && marketingLevel < 18 && btnExpandMarketing && !btnExpandMarketing.disabled) {
btnExpandMarketing.click();
return;
}
for (var project of projectButtons) {
if (project.disabled)
continue;
if (project.textContent.includes("The Universe Next Door")) {
if (Math.random() < 0.5)
continue; // Try to reach 1:1 sim, universe ratio
}
if (project.textContent.includes("Algorithmic Trading")) {
if (strategyEngineFlag == 0)
continue;
}
console.log("Bought project: " + project.textContent);
project.click();
return;
}
if (window.humanFlag && (megaClipperCount < marketingLevel * 4 || window.funds > 128e6) && !btnMakeMegaClipper.disabled) {
btnMakeMegaClipper.click();
return;
}
if (window.humanFlag && (autoClipperCount < marketingLevel * 6 || window.funds > 128e6) && !btnMakeClipper.disabled) {
btnMakeClipper.click();
return;
}
if (btnAddProc && btnAddMem && !btnAddProc.disabled) {
if (memory < 70) {
if (processors < 10) {
if (processors < memory) {
btnAddProc.click();
return;
} else {
btnAddMem.click();
return;
}
} else {
btnAddMem.click();
return;
}
} else {
if (memory < 300) {
if (processors * 2 < memory) {
btnAddProc.click();
return;
} else {
btnAddMem.click();
return;
}
} else {
btnAddProc.click();
return;
}
}
}
if (window.autoTourneyFlag && window.autoTourneyStatus) {
let tourneyButton = window.btnToggleAutoTourneyElement;
if (!tourneyButton.disabled) {
tourneyButton.click();
return;
}
}
if (stratPicker && strategyEngineFlag == 1 && !btnNewTournament.disabled && yomi < 128000 && document.nextTournament < Date.now()) {
document.nextTournament = Date.now() + 30 * 1000;
stratPicker.selectedIndex = stratPicker.children.length - 1;
btnNewTournament.click();
return;
}
if (btnRunTournament && strategyEngineFlag == 1 && !btnRunTournament.disabled) {
btnRunTournament.click();
return;
}
if (window.humanFlag && window.investmentEngineFlag == 1 && btnImproveInvestments && !btnImproveInvestments.disabled) {
btnImproveInvestments.click();
return;
}
if (window.humanFlag && window.investmentEngineFlag == 1 && document.nextInvestmentChange < Date.now()) {
document.nextInvestmentChange = Date.now() + 30 * 1000;
if (investStrat)
investStrat.selectedIndex = 1;
if (investmentLevel > 3 && btnInvest) {
if (funds > investmentTotalValue)
{
document.nextInvestmentChange = Date.now() + 30 * 1000;
btnInvest.click();
return;
}
}
if (btnWithdraw) {
if (investmentCashValue > funds && investmentCashValue / investmentTotalValue < 0.5) {
btnWithdraw.click();
return;
}
}
}
if (!window.spaceFlag && !window.humanFlag && window.project127.flag && !btnMakeFarm.disabled) {
desired = Math.floor(powerConsumption / 50 * 1.3 + 1)
if (solarCount < desired) {
//let delta = desired - solarCount;
if (!btnFarmx10.disabled) {
btnFarmx10.click();
} else {
btnMakeFarm.click();
}
return;
}
}
if (!window.spaceFlag && !window.humanFlag && window.project127.flag && !btnMakeBattery.disabled) {
desired = Math.floor(powerConsumption / 500 * 8 + 1)
if (batteryCount < desired) {
let delta = desired - batteryCount;
if (delta > 10)
btnBatteryx10.click();
else
btnMakeBattery.click();
return;
}
}
if (memory < 300) {
if (workSlider && workSlider.value != "140") {
workSlider.value = "140";
return;
}
} else {
if (workSlider && workSlider.value != "80") {
workSlider.value = "80";
return;
}
}
if (!window.spaceFlag && !window.humanFlag && window.factoryFlag && !btnMakeFactory.disabled && document.nextFactory < Date.now()) {
if (nanoWire != "0") {
document.nextFactory = Date.now() + 2 * 1000;
btnMakeFactory.click();
return;
}
}
if (window.spaceFlag) {
if (!window.btnIncreaseProbeTrustElement.disabled) {
window.btnIncreaseProbeTrustElement.click();
return;
}
if (!window.btnEntertainSwarmElement.disabled && window.entertainButtonDivElement.style.display != "none") {
if (document.nextEntertainSwarm == null) {
document.nextEntertainSwarm = Date.now() + 2 * 60 * 1000;
} else {
if (document.nextEntertainSwarm < Date.now()) {
console.log("Entertained swarm")
document.nextEntertainSwarm = null;
window.btnEntertainSwarmElement.click();
return;
}
}
}
if (!window.btnSynchSwarmElement.disabled && window.synchButtonDivElement.style.display != "none") {
if (document.nextSyncSwarm == null) {
document.nextSyncSwarm = Date.now() + 2 * 60 * 1000;
} else {
if (document.nextSyncSwarm < Date.now()) {
console.log("Synchronizing swarm")
document.nextSyncSwarm = null;
window.btnSynchSwarmElement.click();
return;
}
}
}
if (!window.btnIncreaseMaxTrustElement.disabled) {
window.btnIncreaseMaxTrustElement.click();
return;
}
if (window.probeUsedTrust < window.probeTrust - 1) {
//window.probeSpeed
//window.probeNav
//window.probeRep
//window.probeHaz
//window.probeFac
//window.probeHarv
//window.probeWire
if (window.project131.flag == 1 && window.probeCombat < 6 && !window.btnRaiseProbeCombatElement.disabled) {
window.btnRaiseProbeCombatElement.click();
return;
}
if (window.probeHaz < 4 && !window.btnRaiseProbeHazElement.disabled) {
window.btnRaiseProbeHazElement.click();
return;
}
if (window.probeRep < 6 && !window.btnRaiseProbeRepElement.disabled) {
window.btnRaiseProbeRepElement.click();
return;
}
if (window.probeSpeed <= window.probeNav && !window.btnRaiseProbeSpeedElement.disabled) {
if (window.probeSpeed < 4) {
window.btnRaiseProbeSpeedElement.click();
return;
} else {
if (!window.btnRaiseProbeRepElement.disabled) {
window.btnRaiseProbeRepElement.click();
return;
}
}
} else if(!window.btnRaiseProbeNavElement.disabled) {
if (window.probeNav < 4) {
window.btnRaiseProbeNavElement.click();
return;
} else {
if (!window.btnRaiseProbeRepElement.disabled) {
window.btnRaiseProbeRepElement.click();
return;
}
}
}
}
if (window.project131.flag == 1 && window.probeCombat < 6) {
if (window.probeSpeed >= window.probeNav && !window.btnLowerProbeSpeedElement.disabled) {
window.btnLowerProbeSpeedElement.click();
return;
}
if (window.probeNav >= window.probeSpeed && !window.btnLowerProbeNavElement.disabled) {
window.btnLowerProbeNavElement.click();
return;
}
}
if (window.probeFac + window.probeHarv + window.probeWire < 1) {
let mdpsLabel = window.mdpsElement;
let mapsLabel = window.mapsElement;
let mdbsUnit = mdpsLabel.innerHTML.split(' ')[1];
let mapsUnit = mapsLabel.innerHTML.split(' ')[1];
let mdbsValue = parseFloat(mdpsLabel.innerHTML.split(' ')[0]);
let mapsValue = parseFloat(mapsLabel.innerHTML.split(' ')[0]);
if (window.availableMatter > 0 && window.acquiredMatter == 0 && (mdbsUnit != mapsUnit || mdbsValue > 2 * mapsValue)) {
if (!window.btnRaiseProbeHarvElement.disabled) {
window.btnRaiseProbeHarvElement.click();
return;
}
} else if(window.acquiredMatter > 0 && window.wire == 0) {
if (!window.btnRaiseProbeWireElement.disabled) {
window.btnRaiseProbeWireElement.click();
return;
}
} else if(window.wire > 0) {
if (!window.btnRaiseProbeFacElement.disabled) {
window.btnRaiseProbeFacElement.click();
return;
}
}
}
if (document.nextProbeRole < Date.now() && window.probeTrust > 5) {
document.nextProbeRole = Date.now() + 10 * 1000;
if (window.probeFac > 0 && !window.btnLowerProbeFacElement.disabled) {
window.btnLowerProbeFacElement.click();
//document.nextProbeRoleButton = window.btnRaiseProbeHarvElement;
return;
}
if (window.probeHarv > 0 && !window.btnLowerProbeHarvElement.disabled) {
window.btnLowerProbeHarvElement.click();
//document.nextProbeRoleButton = window.btnRaiseProbeWireElement;
return;
}
if (window.probeWire > 0 && !window.btnLowerProbeWireElement.disabled) {
window.btnLowerProbeWireElement.click();
//document.nextProbeRoleButton = window.btnRaiseProbeFacElement;
return;
}
}
if (window.probeCount == 0 && !btnMakeProbe.disabled) {
btnMakeProbe.click();
return;
}
}
if (optics && !optics.disabled) {
var sum = 0;
for (var chip of chips) {
sum += parseFloat(chip.style.opacity);
}
if (sum > 0 && window.operations < 1000 * memory) {
optics.click();
return;
}
}
if (makeClipButton && !makeClipButton.disabled) {
makeClipButton.click();
return;
}
if (!window.spaceFlag && !window.humanFlag && window.harvesterFlag && !btnMakeHarvester.disabled) {
if (acquiredMatter == "0") {
btnMakeHarvester.click();
return;
}
}
if (!window.spaceFlag && !window.humanFlag && window.wireDroneFlag && !btnMakeWireDrone.disabled && acquiredMatter != "0") {
if (nanoWire == "0") {
btnMakeWireDrone.click();
return;
}
}
}
var apm = 120;
if (document.loopTimer != undefined) clearInterval(document.loopTimer);
document.loopTimer = setInterval(doLoop, 60000 / apm);
@thexa4
Copy link
Author

thexa4 commented Nov 27, 2022

It's meant to be pasted in your developer console, can you retry it there instead of in tampermonkey?

@thexa4
Copy link
Author

thexa4 commented Nov 28, 2022

Sorry, I looked at the wrong script. I fixed the syntax error. Thanks for checking in the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment