Project 04

Snake

One line of code per subscriber. That was the whole brief.

185 / 160

The playable game gets one line for every subscriber the channel has. This page, the leaderboard and the anti-cheat sit outside that budget — they are the cabinet, not the game. Right now the game is 25 lines over: giving it a real ending, and stopping food from landing on the snake, cost more than the budget had left. The counter stays honest about that until the channel catches up.

Arrow keys to move · swipe on touch · any key to restart

High scores

    How you win

    Snake usually has no ending — you play until you die. This one does: eat every piece of food the board can hold and the game stops on PERFECT. There are 400 squares, the snake starts on four of them, so a finished game is 396 pieces of food and exactly 3960 points. Nothing scores higher, which is why the server refuses anything that does.

    Food is only ever placed on a square the snake is not standing on. That sounds obvious, and it is — but the first version picked a random square without checking, and any piece that landed on the snake's own body was swallowed on the spot for a free ten points. The longer you got, the more often it happened.

    Why the score is checked on the server

    The browser is the last place you should count anything that matters. The page sends a finished score to /api/snake/scores, and the server only accepts it if it is a multiple of ten and no larger than 3960 — the most a 20×20 board can physically produce.

    Scores are tied to your Google account, one row per player, and only your best one is kept. Sending a worse score than you already have does nothing, so there is nothing to gain from spamming the endpoint.