3 ms·
pure random player: (async function(punch, delay) { async function sleep(ms) { return new Promise((resolve, _) => { setTimeout(resolve, ms)
by escanor 3mo ago
pure random player:
(async function(punch, delay) {
async function sleep(ms) {
return new Promise((resolve, _) => {
setTimeout(resolve, ms)
})
}
for (let i = 0; i < 100; i++) {
punch(['L', 'R'][(Math.random() * 2) | 0])
await sleep(delay)
}
})(punch, 150)
"cheating" player:
(async function(oracle, punch, delay) {
async function sleep(ms) {
return new Promise((resolve, _) => {
setTimeout(resolve, ms)
})
}
for (let i = 0; i < 100; i++) {
punch((i + 1) < oracle.minForPrediction ? ['L', 'R'][(Math.random() * 2) | 0] : oracle.predictNextPunch() === 'L' ? 'R' : 'L')
await sleep(delay)
}
})(oracle, punch, 150)
is it possible to do any better? i haven't fully read frog/oracle code
- escanor 3mo agoit is: (async function(oracle, punch, delay) { async function sleep(ms) { return new Promise((resolve, _) => { setTimeout(resolve, ms) }) } for (let i = 0; i < 100; i++) { const state = oracle._state const block = oracle.predictNextPunch() oracle._state = state punch(block === 'L' ? 'R' : 'L') await sleep(delay) } })(oracle, punch, 150)
- emrtnn 3mo agoLess fancy hack here, intercept the prediction function on every punch and force the frog to take the opposite side. const realPunch = punch; punch = function(myMove) { oracle.predictNextPunch = function() { return myMove === 'L' ? 'R' : 'L'; }; realPunch(myMove); };
- escanor 3mo agobrilliant!