Inspiration

Guards started with the Art Gallery Problem, a question Victor Klee asked in 1973: how many guards do you need so that every part of a gallery is watched? Chvátal proved that a gallery with n walls never needs more than ⌊n/3⌋, but finding the smallest number for one particular floor plan is genuinely hard. Computers have to work for it too.

That combination seemed ideal for a daily game. You can explain the rules in one sentence, it feels natural to play with your thumb, and there's a provably best answer waiting at the end. I also liked the mood of it: a dark museum, a few lamps, and the small satisfaction of the last corner lighting up.

What it does

Every day, everyone on the subreddit gets the same floor plan. You tap the floor to place a camera, drag it to move it, and tap it again to take it away. Cameras see in every direction but not through walls, so the floor fills with amber light as you work and the dark parts stay striped. A counter shows how much of the floor is lit.

Once everything is lit you can lock in. You get three lock-ins a day, and your best (fewest cameras) is what counts:

  • 💎 par
  • 🥇 one over par
  • 🥈 two over par
  • 🥉 solved

If you've been stuck for a minute, the game offers a hint that circles a dark corner. Taking it caps your medal at gold for the day.

After your last lock-in, or whenever you choose to reveal the answer, the optimal solution sweeps across the board in blue light on top of your own cameras. Most people's first reaction is "oh, there". Below that you'll find how everyone else did that day, your streak, and a countdown to the next gallery. You can share a spoiler-free result as a comment in the day's results thread:

Guards #12 💎 📷📷📷 (par 3) Coverage locked in: attempt 2/3 🔥 streak 7

The difficulty follows the week. Mondays are gentle, Fridays and Saturdays are hard, and Sundays get a showcase gallery with angled walls. A new post goes up on its own at midnight UTC, and moderators can also post a puzzle from the subreddit menu. New players get a short tutorial they can skip.

How I built it

The game runs on Devvit Web. The client is React with a hand-written canvas renderer, the server is Hono, and everything the game needs to remember lives in Redis. The inline post in the feed is a small, light page; the full game opens in expanded view.

The core of the project is a geometry module I wrote in plain TypeScript. It works out exactly what each camera can see by sweeping rays around the camera toward every wall corner. Checking whether the floor is "fully lit" uses a fixed set of about 6,000 sample points, plus extra points pushed into every corner and around every inside corner, so a tiny nook can't sneak past. The server runs the same code with the same points on every lock-in, so the result on your screen and the result that gets saved always agree, and nobody can fake a score.

The puzzles themselves come from an offline generator. It builds floor plans from a set of shapes (room suites, spirals, combs, alcove halls, pillared halls and so on) and finds the true minimum number of cameras for each one with an exact set cover solver. Most generated plans turn out to be dull, so a filter scores them on things like how many different camera spots could belong to a perfect answer, and whether the obvious "biggest room first" approach leads you astray. Only the interesting ones make it into the bank, which currently holds 70 days.

I also wired up Devvit's Journeys analytics, wrote 31 tests (including 12,000 random checks of the visibility code against a slower, independent method), and drew the artwork, including the thumbnail, with the same geometry code, so the shadows are real rather than painted.

Challenges I ran into

The hardest part was the geometry edge cases. Cameras lined up exactly with a wall, or rays that skim along a row of corners, broke early versions in ways that were hard to spot. Every bug I found turned into a test.

Deciding what "100% lit" means took some thought. Exact polygon maths is fragile with floating-point numbers, so I settled on the shared set of sample points and made sure the display never rounds 99.9% up to 100%.

Par had to be exact, but also reachable by a person with a finger. The solver searches a fine grid of possible camera spots. Occasionally a player can beat it with a spot that isn't on the grid. Rather than pretending that's impossible, the game congratulates them and logs the placement.

Finally, a lot of generated puzzles were boring: the answer was simply one camera per room. Measuring that and filtering it out made a big difference. So did a rule that stops the same kind of floor plan from showing up twice in a week. My first batch was about 40% spirals.

Accomplishments that I'm proud of

Every puzzle has a par that is mathematically correct, not estimated. I'm also proud of the reveal. Watching the best answer sweep in over your own attempt makes the "how did they do it with one fewer?" moment land without any explanation. And the full daily loop works end to end on Reddit, from the automatic midnight post to streaks, the community histogram and sharing.

What I learned

Geometry code is mostly edge cases, and the most useful test I wrote was simply comparing my fast method with a slow one on thousands of random positions. I learned that "is this puzzle fun?" can be partly measured, which beat tuning difficulty by feel. And for a daily game, the ending matters as much as the puzzle. The reveal, the histogram and the share text are what bring people back the next day.

What's next for Guards

I'd like to grow the bank with new kinds of floor plans and themed weeks, and eventually let players submit their own galleries, checked by the same solver and credited on the day they run. Variant days with limited-angle cameras or patrolling guards would be fun, since both are well-known versions of the original problem. A heatmap of where everyone placed their cameras is high on the list as well.

Built With

Share this project:

Updates

Submission history