Skip to content

Instantly share code, notes, and snippets.

@Ghostnipple
Last active January 12, 2022 08:59
Show Gist options
  • Save Ghostnipple/182ee221194f7c3a9038d2390cf5956e to your computer and use it in GitHub Desktop.
Save Ghostnipple/182ee221194f7c3a9038d2390cf5956e to your computer and use it in GitHub Desktop.
This script will generate past game results for Bustabit. Copy the script below and paste it in to a new script window on bustabit. Please note this version only generates the past results, not future results. The save to file option has never worked for me. Script produced by Dsetzer (original can be found at https://gist.github.com/dsetzer.)
//Script was produced by Dsetzer original can be found at https://gist.github.com/dsetzer
//In the script panel in Bustabit create a new script. Copy the script below and paste it in to the script window on bustabit.
//Please note this version will only give you past results and not future results.
//The script has a save to file option, but this has never worked for me.
var config = {
span: { label: 'Previous Games', type: 'number', value: '100' },
outh: { label: 'Include Hashes', type: 'checkbox', value: false },
ocsv: { label: 'Download CSV', type: 'checkbox', value: true}
};
Object.entries(config).forEach((c) => window[c[0]] = c[1].value);
let hashes = new Map(), lastGame = engine.history.first();
let currentId = lastGame.id, currentHash = lastGame.hash;
let games = new Array();
function downloadString(text, fileName) {
var blob = new Blob([ text ], { type: 'text/csv' });
var a = document.createElement('a');
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.dataset.downloadurl = [ 'text/csv', a.download, a.href ].join(':');
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(function () { URL.revokeObjectURL(a.href); }, 1500);
}
for(let i = currentId, result, len = currentId - span; i >= len; i--){
hashes.set(i, String(currentHash));
currentHash = SHA256((currentHash));
}
hashes.forEach((hash, id) =>{
let gameResult = gameResultFromHash(hash);
log(`Game: ${id}, Bust: ${gameResult}${outh?', Hash: '+hash:''}`);
if(ocsv) games.push(`${id}, ${gameResult}${outh?', '+hash:''}\n`);
});
if(ocsv){
games.unshift(`id, result${outh?', hash':''}`);
downloadString(games.join('\r\n'), 'game_results.csv');
}
stop('Finished');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment