Turtle escape

The turtle gets 30 moves on the hex grid to escape. Will it make it?

You can change the number on line 8 to get different attempts. I chose one I liked.

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();

turtle.pendown();
const r = Random(846);

// The walk function will be called until it returns false.
function walk(i) {
    if (i % 30 == 0) {
        turtle.jump(0, 0);
    }
    turtle.forward(6);
    if (r() > 0.5) {
        turtle.left(60);
    } else {
        turtle.right(60);
    }

    const [x, y] = turtle.position();
    return (
        -100 < x &&
        x < 100 &&
        -100 < y &&
        y < 100);
}

function Random(seed) {
  this._seed = seed % 2147483647;
  if (this._seed <= 0) this._seed += 2147483646;
  return function nextFloat() {
    return ((_seed = _seed * 16807 % 2147483647) - 1) / 2147483646;
  };
}