AUTOSNAKE

Program a snake. Out-think the other one.

P1
CONSOLE
    P1WINS 0
    LEN 3
    ROUND 1
    TICK 0
    DRAWS 0
    P2WINS 0
    LEN 3

    Space pause · → step · R restart · ? API · Ctrl+Space autocomplete

    P2
    CONSOLE

      SNAKESCRIPT

      SnakeScript is JavaScript with a snake-sized vocabulary. Your code is the body of a function that runs once per tick: look at the world, then return 'up', 'down', 'left' or 'right'. Changes go live as you type; if the code does not parse, the last working version keeps playing.

      // A complete brain: chase the food, otherwise find room to breathe.
      return toward(food) ?? safest();

      Rules