Skip to content

Instantly share code, notes, and snippets.

@stek29
Last active October 27, 2018 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stek29/a9f6944629c39b076828a4be385722e0 to your computer and use it in GitHub Desktop.
Save stek29/a9f6944629c39b076828a4be385722e0 to your computer and use it in GitHub Desktop.
Universal Paperclips related scrips

See Universal Paperclips

qbot.js

"non-cheat" quantum computing bot (makes decisions based on chip opacity, without accessing game's internal variables)

qtoggle.js

Add "toggle" button to quantum computing

var qChipBot = function(chipcount, negative_default, no_adjust_neg, proc_interval, no_adjust_ival) {
negative_default = negative_default || -180;
var AUTOqDefaultInterval = proc_interval || 100;
var AUTOqCurrentInterval = AUTOqDefaultInterval;
var AUTOqMaxInterval = 2000;
var AUTOqCompBtn = document.querySelector('#btnQcompute');
var AUTOqComp = ()=>AUTOqCompBtn.click();
var AUTOqChipCount = chipcount;
var AUTOqOpsNegativeDefault = negative_default;
var AUTOqOpsNegativeMin = -250;
var AUTOqOpsNegativeMax = -100;
var AUTOqChips = [].concat.apply([], document.querySelectorAll('.qChip')).slice(0, chipcount);
var AUTOqChipOpacities = ()=>AUTOqChips.map(chip=>chip.style.opacity);
var AUTOqOpsExpected = ()=>AUTOqChipOpacities().map(op=>op>0?op*360:AUTOqOpsNegativeDefault).reduce((x,y)=>x+y);
var AUTOqCompDisplay = document.querySelector('#qCompDisplay');
var AUTOqCompLastVal = ()=>parseInt(AUTOqCompDisplay.innerText.split(': ')[1].replace(',', ''));
var AUTOqChipProc = function() {
let expected = AUTOqOpsExpected();
if (expected > 0) {
AUTOqComp();
let actual = AUTOqCompLastVal();
if (!no_adjust_neg) {
let negative_cnt = AUTOqChipOpacities().filter(op=>op<0).length;
new_neg = Math.floor((actual < 0)
? Math.max(
AUTOqOpsNegativeDefault + actual / negative_cnt,
AUTOqOpsNegativeMin
) : Math.min(
AUTOqOpsNegativeDefault + actual / negative_cnt,
AUTOqOpsNegativeMax
)
);
if (new_neg != AUTOqOpsNegativeDefault) {
AUTOqOpsNegativeDefault = new_neg;
console.log(`Anjusted neg default: ${AUTOqOpsNegativeDefault}
expected: ${expected}, got: ${actual}
negative_cnt: ${negative_cnt}
adjustment: ${Math.floor(actual / negative_cnt)}`);
}
}
if (!no_adjust_ival) {
let new_ival = Math.floor((actual > 0)
? Math.max(
AUTOqCurrentInterval*0.75,
AUTOqDefaultInterval
) : Math.min(
AUTOqCurrentInterval/0.75,
AUTOqMaxInterval
));
if (new_ival != AUTOqCurrentInterval) {
AUTOqCurrentInterval = new_ival;
console.log(`Anjusted ival: ${AUTOqCurrentInterval}`);
AUTOqChipSetInterval();
}
}
}
}
var AUTOqChipInterval = -1;
var AUTOqChipSetInterval = function() {
clearInterval(AUTOqChipInterval);
AUTOqChipInterval = setInterval(AUTOqChipProc, AUTOqCurrentInterval);
}
var AUTOqChipStart = function() {
AUTOqCurrentInterval = AUTOqDefaultInterval;
AUTOqChipSetInterval();
}
var AUTOqChipStop = ()=>clearInterval(AUTOqChipInterval);
return {
step: AUTOqChipProc,
start: AUTOqChipStart,
stop: AUTOqChipStop,
};
}
(function(){
const INTERVAL = 0;
let ival = null;
let qCompStart = function() {
ival = setInterval(qComp, INTERVAL);
}
let qCompStop = function() {
clearInterval(ival);
ival = null;
}
let qCompToggle = ()=>(((ival)?qCompStop:qCompStart)());
let qtogglebtn = document.createElement('button');
qtogglebtn.setAttribute('class', 'button2');
qtogglebtn.id = 'btnQToggle';
qtogglebtn.onclick = qCompToggle;
qtogglebtn.innerText = 'Toggle';
let qholder = document.querySelector('#qComputing');
let qCompDisplayEl = qholder.querySelector('#qCompDisplay');
qholder.insertBefore(qtogglebtn, qCompDisplayEl);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment