logoalt Hacker News

deviationtoday at 6:14 PM0 repliesview on HN

Paste this bad-boy into your console and watch the real expert play:

(function () { "use strict";

  // ── CONFIG ──────────────────────────────────────────────────
  const AUTO_RESTART = true;
  const RESTART_DELAY = 800;   // ms before auto-restart after death
  const MUTE_SOUND = true;     // silence during autoplay
  const SIM_FRAMES = 350;      // max frames to simulate per check
  // ────────────────────────────────────────────────────────────

  let running = true;
  let totalGames = 0;
  let botBest = 0;
  let scores = [];

  if (MUTE_SOUND && typeof snd !== "undefined") snd = false;

  function wouldHitTarget() {
    if (st !== 1 || !bl || !bl.orb) return false;

    var targets = [];
    for (var i = cWI + 1; i < Math.min(wl.length, cWI + 3); i++) {
      if (wl[i] && !wl[i].caught) targets.push(wl[i]);
    }
    if (targets.length === 0) return false;

    var ta = bl.angle + bl.dir * Math.PI / 2;
    var nw = wl[cWI + 1];
    var spd;
    if (nw) {
      var ddx = nw.x - bl.x, ddy = nw.y - bl.y;
      spd = Math.max(4.5, Math.min(7.5, Math.sqrt(ddx * ddx + ddy * ddy) * 0.038));
    } else {
      spd = 5.5;
    }

    var x = bl.x, y = bl.y;
    var vx = Math.cos(ta) * spd;
    var vy = Math.sin(ta) * spd;

    for (var f = 0; f < SIM_FRAMES; f++) {
      vy += 0.06;
      vx *= 0.995;
      vy *= 0.995;
      x += vx;
      y += vy;

      for (var t = 0; t < targets.length; t++) {
        var dx = x - targets[t].x, dy = y - targets[t].y;
        if (Math.sqrt(dx * dx + dy * dy) < targets[t].radius + 20) {
          return true;
        }
      }

      if (y > 2500 || x < -400 || x > W + 400) return false;
    }
    return false;
  }

  function autoRestart() {
    if (st !== 2) return;
    var go = document.getElementById("game-over");
    var rp = document.getElementById("revive-popup");
    if (go) go.classList.add("hidden");
    if (rp) rp.classList.add("hidden");
    document.getElementById("pause-btn").style.display = "flex";
    document.getElementById("sound-btn").style.display = "flex";
    st = 1;
    init();
  }

  function tick() {
    if (!running) return;

    if (st === 0) {
      handleTap();
    } else if (st === 2 && AUTO_RESTART) {
      totalGames++;
      scores.push(sc);
      if (sc > botBest) botBest = sc;
      console.log(
        "Game #" + totalGames +
        " | Score: " + sc +
        " | Jumps: " + jmp +
        " | Combo peak: " + cc +
        " | Bot best: " + botBest
      );
      setTimeout(autoRestart, RESTART_DELAY);
      setTimeout(function () { requestAnimationFrame(tick); }, RESTART_DELAY + 50);
      return;
    } else if (st === 1 && bl && bl.orb) {
      if (wouldHitTarget()) {
        release();
      }
    }

    requestAnimationFrame(tick);
  }

  window.stopBot = function () {
    running = false;
    console.log("Bot paused. Call startBot() to resume.");
  };

  window.startBot = function () {
    if (running) return;
    running = true;
    console.log("Bot resumed.");
    requestAnimationFrame(tick);
  };

  window.botStatus = function () {
    var avg = scores.length
      ? (scores.reduce(function (a, b) { return a + b; }, 0) / scores.length).toFixed(1)
      : 0;
    console.log(
      "Games: " + totalGames +
      " | Best: " + botBest +
      " | Avg: " + avg +
      " | Running: " + running
    );
  };

  console.log("=== STARFLING AUTO-PLAYER ===");
  console.log("Controls: stopBot() | startBot() | botStatus()");
  requestAnimationFrame(tick);
})();