Remix.run Logo
escanor 2 hours 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 2 hours ago | parent [-]

it 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)