Created
December 7, 2016 03:43
-
-
Save boertel/9457f9203cbdf56e121a2de788aa510f to your computer and use it in GitHub Desktop.
automate startup-simulator decision
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function choose(choice) { | |
var method = 'pick' + choice.toUpperCase(); | |
var win = api[method](); | |
nextTurn(win); | |
} | |
var threshold = { | |
valuation: 80, | |
happiness: 20, | |
time: 3 | |
}; | |
function conditions(values) { | |
return (values.valuation * 1.5 + values.happiness * 0.9 + values.time * 1.1); | |
} | |
function careful(a, b) { | |
var output; | |
['happiness', 'time', 'valuation'].forEach(function(key) { | |
if (state[key] < threshold[key]) { | |
console.log('CAREFUL', key, state[key], a[key], b[key]); | |
output = a[key] > b[key] ? 'a' : 'b'; | |
} | |
}); | |
return output; | |
} | |
function pickChoice() { | |
var n = undefined; | |
var letter = undefined; | |
var choices = state.card.choices; | |
for (var key in choices) { | |
if (choices.hasOwnProperty(key)) { | |
var choice = choices[key]; | |
var current = conditions(choice.values); | |
if (n === undefined || current > n) { | |
n = current; | |
letter = '' + key; | |
} | |
} | |
letter = careful(choices.a.values, choices.b.values) || letter; | |
} | |
console.log(letter); | |
console.table({ | |
valuation: { | |
'state': state.valuation, | |
'a': choices.a.values.valuation, | |
'b': choices.b.values.valuation | |
}, | |
happiness: { | |
'state': state.happiness, | |
'a': choices.a.values.happiness, | |
'b': choices.b.values.happiness | |
}, | |
time: { | |
'state': state.time, | |
'a': choices.a.values.time, | |
'b': choices.b.values.time | |
}, | |
}); | |
return letter; | |
} | |
startTutorial(); | |
startGame(); | |
var interval = window.setInterval(function() { | |
var letter = pickChoice(); | |
choose(letter); | |
if (state.defeatReason !== null || state.win !== null) { | |
if (state.defeatReason) { | |
console.log('LOST', state.defeatReason, state[state.defeatReason]); | |
} | |
nextTurn(api.pickA()); | |
window.clearInterval(interval); | |
} | |
}, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment