Skip to content

Puzzle (merge / 2048)

2048-Style Merge Puzzle

Tested with Google AI Studio · produced Merge Cubes

The Prompt

Build a 2048-style merge puzzle game as ONE self-contained HTML file (all CSS/JS inline, no libraries, works offline).

Rules to implement exactly:
- 4x4 grid. Swipe (touch) or arrow keys move all tiles. Optionally WASD.
- Tiles with the same value merge once per move into their sum. Spawns a 2 (90%) or 4 (10%) in a random empty cell after every successful move.
- Game over when no merges are possible; win banner at 2048 with a "keep going" option.
- Score = sum of merged values; best score kept for the session.

Implementation requirements:
- Implement slide-merge as a pure function of (grid, direction) returning the new grid, merges and gained score — so it is testable. NO DOM manipulation inside that function.
- Smooth tile slide animation (CSS transforms are fine) and a small pop animation on merge.
- Tiles must be positioned with transforms so animation is cheap; 60fps target.
- Handle rapid key input gracefully (queue or throttle).
- Responsive: canvas or DOM-based is fine, must scale to phone screens.

Then print: the merge function alone, followed by a list of edge cases you handled (corner pushes, triple tiles, spawn after no-move, etc.).

What This Prompt Produces

Asking for the merge as a pure function is the trick that eliminates the classic 2048 bugs. Merge Cubes was generated from this prompt and only needed art-style tweaks — still our go-to structure for logic-heavy prompts on Gemini 3.

Modification Tips

  • Do not skip the "edge cases" line at the end — it makes the AI self-audit the trickiest logic.
  • If arrow keys scroll the page on mobile browsers, follow up with: "preventDefault on arrow keydown."
  • Want a fresh twist? Add: "Reskin tiles as glowing gems; when two gems merge, emit a brief sparkle."

The Game This Prompt Produced

Want to try it? Open Google AI Studio, paste the prompt, and you'll have a playable game in minutes. When you're happy with the result, submit it to Daily AI Games.