<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cliff</title>
    <description>The latest articles on DEV Community by Cliff (@cliffwang).</description>
    <link>https://dev.to/cliffwang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4127542%2F31a4bb73-e611-48c7-a9d3-e00a5f161c9e.png</url>
      <title>DEV Community: Cliff</title>
      <link>https://dev.to/cliffwang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cliffwang"/>
    <language>en</language>
    <item>
      <title>From Mobile Apps to Browser Games: The Evolution of Block Blast-Style Puzzles</title>
      <dc:creator>Cliff</dc:creator>
      <pubDate>Sun, 22 Nov 2026 04:32:20 +0000</pubDate>
      <link>https://dev.to/cliffwang/from-mobile-apps-to-browser-games-the-evolution-of-block-blast-style-puzzles-o8m</link>
      <guid>https://dev.to/cliffwang/from-mobile-apps-to-browser-games-the-evolution-of-block-blast-style-puzzles-o8m</guid>
      <description>&lt;p&gt;How a simple block-placement mechanic became a global mobile gaming phenomenon — and why browser games are giving it a new direction.&lt;/p&gt;

&lt;p&gt;Some games don't need complicated controls, elaborate stories, or impressive graphics to become popular.&lt;/p&gt;

&lt;p&gt;A grid, a few geometric shapes, and the simple objective of clearing rows and columns can be enough to keep players engaged for hours.&lt;/p&gt;

&lt;p&gt;Block puzzle games are a good example of this.&lt;/p&gt;

&lt;p&gt;Over the years, this familiar puzzle format has evolved from classic block-fitting games into a major category of mobile casual gaming. Titles such as 1010!, Woodoku, Blockudoku, and Block Blast! have introduced different variations while retaining the same fundamental appeal: simple rules, spatial reasoning, and the satisfaction of clearing the board.&lt;/p&gt;

&lt;p&gt;But there is another interesting development happening.&lt;/p&gt;

&lt;p&gt;What started primarily as a mobile app experience is increasingly finding its way into web browsers.&lt;/p&gt;

&lt;p&gt;Let's look at how this genre evolved, why it became so successful on mobile, and what the transition to browser-based games means for its future.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Origins: A Simple Idea That Keeps Working
&lt;/h2&gt;

&lt;p&gt;The basic idea behind block puzzle games is not new.&lt;/p&gt;

&lt;p&gt;Games like Tetris introduced millions of players to the pleasure of arranging geometric shapes to complete lines. However, falling-block gameplay and modern block-placement puzzles are not exactly the same.&lt;/p&gt;

&lt;p&gt;In traditional falling-block games, pieces descend automatically, and players must react before the board fills up.&lt;/p&gt;

&lt;p&gt;Block-placement puzzles take a different approach.&lt;/p&gt;

&lt;p&gt;Players receive a selection of shapes and decide where to place them on a fixed grid. Completing a full row or column removes those blocks and creates more space.&lt;/p&gt;

&lt;p&gt;There is usually no falling-piece timer. Players can stop, examine the board, and plan their next move.&lt;/p&gt;

&lt;p&gt;This small change makes a significant difference.&lt;/p&gt;

&lt;p&gt;The challenge shifts from reaction speed to spatial reasoning, planning, and resource management.&lt;/p&gt;

&lt;p&gt;Several mobile games helped establish this style of gameplay:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1010!&lt;/strong&gt; popularized a clean, grid-based block-placement experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Woodoku&lt;/strong&gt; combined block placement with elements of Sudoku-style grid clearing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blockudoku&lt;/strong&gt; introduced another variation of the block puzzle and Sudoku combination.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block Blast!&lt;/strong&gt; brought its own polished presentation, 8×8 board, combo system, and accessible mobile experience to a much larger audience.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These games demonstrate an important characteristic of casual puzzle design: a familiar mechanic can remain interesting through carefully designed variations.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The Mobile Era: Why Block Puzzles Became So Popular
&lt;/h2&gt;

&lt;p&gt;The smartphone was a natural home for this type of puzzle.&lt;/p&gt;

&lt;p&gt;There are several reasons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Easy to Learn
&lt;/h3&gt;

&lt;p&gt;Players can understand the basic rules within seconds.&lt;/p&gt;

&lt;p&gt;Select a shape, place it on the board, complete a line, and continue.&lt;/p&gt;

&lt;p&gt;There is very little learning friction, making the genre accessible to both experienced gamers and people who rarely play games.&lt;/p&gt;

&lt;h3&gt;
  
  
  Perfect for Short Sessions
&lt;/h3&gt;

&lt;p&gt;Block puzzles fit naturally into everyday routines.&lt;/p&gt;

&lt;p&gt;A player might complete a few moves while waiting for transportation, take a short break between tasks, or spend twenty minutes trying to beat a previous high score.&lt;/p&gt;

&lt;p&gt;There is no need to remember a complicated storyline or complete a long mission.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Mechanics, Meaningful Decisions
&lt;/h3&gt;

&lt;p&gt;Although the controls are straightforward, the decisions can become increasingly difficult.&lt;/p&gt;

&lt;p&gt;Every placement changes the available space.&lt;/p&gt;

&lt;p&gt;A move that creates an immediate line clear might leave the board in a difficult position for the next pieces. A less obvious placement might preserve valuable space and create better opportunities later.&lt;/p&gt;

&lt;p&gt;This creates a satisfying balance between accessibility and strategic depth.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Strong Foundation for Long-Term Engagement
&lt;/h3&gt;

&lt;p&gt;Modern block puzzle games have also introduced features that extend beyond the original core mechanic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Combo multipliers.&lt;/li&gt;
&lt;li&gt;Daily challenges.&lt;/li&gt;
&lt;li&gt;High-score competitions.&lt;/li&gt;
&lt;li&gt;Adventure and progression modes.&lt;/li&gt;
&lt;li&gt;Different visual themes.&lt;/li&gt;
&lt;li&gt;Events and limited-time challenges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Block Blast! by Hungry Studio is an especially interesting example of this evolution.&lt;/p&gt;

&lt;p&gt;According to Hungry Studio's January 2026 announcement, the game had reached 70 million daily active users and 300 million monthly active users globally as of December 2025. The company also reported conducting more than 10,000 A/B tests during 2025.&lt;/p&gt;

&lt;p&gt;Source: [Hungry Studio – Block Blast! Reaches 70M DAU]&lt;/p&gt;

&lt;p&gt;This illustrates how a relatively simple puzzle mechanic can support a sophisticated, continuously evolving mobile product.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. From Mobile Apps to Browser Games
&lt;/h2&gt;

&lt;p&gt;For a long time, installing an app was the standard way to enjoy mobile puzzle games.&lt;/p&gt;

&lt;p&gt;Players discovered a game through an app store, downloaded it, installed it, and returned whenever they wanted to play.&lt;/p&gt;

&lt;p&gt;That model still works extremely well.&lt;/p&gt;

&lt;p&gt;However, the way people access games has gradually expanded.&lt;/p&gt;

&lt;p&gt;Browser games have become more capable, mobile browsers have improved, and HTML5 technologies have made it possible to deliver interactive gaming experiences without requiring a traditional app installation.&lt;/p&gt;

&lt;p&gt;This changes the entry point for players.&lt;/p&gt;

&lt;p&gt;Instead of searching an app store and downloading a game, someone can simply open a website and start playing.&lt;/p&gt;

&lt;p&gt;Consider the differences:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mobile App&lt;/th&gt;
&lt;th&gt;Browser Game&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requires installation&lt;/td&gt;
&lt;td&gt;Opens through a URL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App store discovery&lt;/td&gt;
&lt;td&gt;Search engines and direct links&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;App updates&lt;/td&gt;
&lt;td&gt;Website updates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primarily designed around app environments&lt;/td&gt;
&lt;td&gt;Can support desktop, tablet, and mobile&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Requires storage space&lt;/td&gt;
&lt;td&gt;No traditional installation required&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Neither approach is universally better.&lt;/p&gt;

&lt;p&gt;Mobile apps have advantages in areas such as offline access, operating-system integration, notifications, and native platform capabilities.&lt;/p&gt;

&lt;p&gt;Browser games have a different strength: accessibility.&lt;/p&gt;

&lt;p&gt;A link can be shared instantly. A player can open it on a computer, Chromebook, tablet, or smartphone without first installing an application.&lt;/p&gt;

&lt;p&gt;For a casual puzzle game, reducing the steps between discovering a game and actually playing it can make a meaningful difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Browser Gaming Is No Longer Just a Desktop Experience
&lt;/h2&gt;

&lt;p&gt;One of the biggest misconceptions about browser games is that they are mainly designed for desktop computers.&lt;/p&gt;

&lt;p&gt;Modern HTML5 games can run on smartphones as well.&lt;/p&gt;

&lt;p&gt;Research published by Newzoo and Google in 2026 highlights how widespread this behavior has become.&lt;/p&gt;

&lt;p&gt;Their H5 gaming research found that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;46% of surveyed online consumers aged 13–55 play browser games monthly.&lt;/li&gt;
&lt;li&gt;83% of H5 gamers play browser games on smartphones.&lt;/li&gt;
&lt;li&gt;75% also play app-based mobile games.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source: &lt;a href="https://newzoo.com/reports/a-playbook-for-winning-with-h5-gamers" rel="noopener noreferrer"&gt;Newzoo – A Playbook for Winning with H5 Gamers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This suggests something important.&lt;/p&gt;

&lt;p&gt;Browser gaming and mobile app gaming are not necessarily competing for completely different audiences.&lt;/p&gt;

&lt;p&gt;Many players use both.&lt;/p&gt;

&lt;p&gt;Someone might prefer a mobile app for regular play but choose a browser version when using a desktop computer, sharing a game with a friend, or simply wanting to try something without installing another application.&lt;/p&gt;

&lt;p&gt;This creates an opportunity for familiar puzzle genres to exist across multiple platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What Makes a Good Browser-Based Block Puzzle?
&lt;/h2&gt;

&lt;p&gt;Moving a puzzle game from an app environment to a browser is not simply a matter of putting the same game inside a webpage.&lt;/p&gt;

&lt;p&gt;The experience needs to be designed around the browser.&lt;/p&gt;

&lt;p&gt;Several details matter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fast Loading and Immediate Play
&lt;/h3&gt;

&lt;p&gt;A browser puzzle should start quickly.&lt;/p&gt;

&lt;p&gt;Players should not have to navigate through multiple pages, create an account, or wait through unnecessary loading screens before making their first move.&lt;/p&gt;

&lt;h3&gt;
  
  
  Responsive Controls
&lt;/h3&gt;

&lt;p&gt;A block puzzle needs to feel natural on different devices.&lt;/p&gt;

&lt;p&gt;On desktop, mouse interaction should be comfortable.&lt;/p&gt;

&lt;p&gt;On mobile, players should be able to drag pieces or use touch-based placement without fighting the interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Persistent Progress
&lt;/h3&gt;

&lt;p&gt;A browser game should not necessarily mean losing progress whenever the player closes a tab.&lt;/p&gt;

&lt;p&gt;Local persistence can help save scores, game states, and personal records between sessions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consistent Gameplay
&lt;/h3&gt;

&lt;p&gt;The core rules should remain understandable and predictable.&lt;/p&gt;

&lt;p&gt;Players need to know how pieces are selected, how lines are cleared, how combos work, and what causes a game to end.&lt;/p&gt;

&lt;h3&gt;
  
  
  More Than Just a Basic Clone
&lt;/h3&gt;

&lt;p&gt;A browser game can also introduce features that make it worth returning to.&lt;/p&gt;

&lt;p&gt;Daily challenges, personal bests, different modes, and strategy guides can turn a simple playable page into a more complete puzzle experience.&lt;/p&gt;

&lt;p&gt;The goal should not be to reproduce an app screen inside a website.&lt;/p&gt;

&lt;p&gt;It should be to build a browser experience that makes sense on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Trying Block Blast Online: A Browser-Based Experience
&lt;/h2&gt;

&lt;p&gt;We have been exploring this idea through our own browser-based block puzzle game at &lt;strong&gt;&lt;a href="https://block-blast.app/" rel="noopener noreferrer"&gt;Block Blast Online&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The goal is straightforward: make the familiar block-placement puzzle available directly in a web browser, without requiring players to download an app or create an account.&lt;/p&gt;

&lt;p&gt;The game runs directly on our website rather than embedding a third-party game.&lt;/p&gt;

&lt;p&gt;Here are some of its main features:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An 8×8 Puzzle Board&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Place different block shapes on the grid and complete horizontal or vertical lines to clear space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Three Pieces at a Time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each round provides three shapes. Players need to think carefully about where to place them because pieces cannot be rotated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Drag and Tap Controls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can drag pieces onto the board or select a piece and tap the target cell. The experience supports both desktop and mobile devices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Combo Scoring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clearing lines on consecutive moves increases the combo multiplier, rewarding players who plan several moves ahead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Endless Mode&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keep playing and try to beat your previous high score. The game uses an adaptive difficulty system to adjust upcoming piece selections based on the board and recent gameplay.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Daily Challenge&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every day, players receive the same fixed puzzle seed and piece sequence. Everyone faces the same challenge, making it possible to compare results on equal terms.&lt;/p&gt;

&lt;p&gt;You can try it here:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://block-blast.app/" rel="noopener noreferrer"&gt;Play Block Blast Online – Free Browser Game&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No download. No sign-up. Just open the page and start playing.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Where Is the Genre Heading?
&lt;/h2&gt;

&lt;p&gt;The future of block puzzle games probably won't be defined by one platform alone.&lt;/p&gt;

&lt;p&gt;Mobile apps will continue to offer advantages for players who want dedicated gaming experiences, offline play, and deeper platform integration.&lt;/p&gt;

&lt;p&gt;At the same time, browser games are opening another distribution channel.&lt;/p&gt;

&lt;p&gt;A few trends are particularly interesting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Device Accessibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Players increasingly expect games to work wherever they happen to be. A puzzle that works well on both a phone and a desktop has more opportunities to fit into everyday routines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Personalized Challenges&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Daily seeds, adaptive difficulty, leaderboards, and personalized goals can give players reasons to return without fundamentally changing the core mechanic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search-Driven Game Discovery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unlike traditional app store discovery, browser games can be discovered through search engines, articles, guides, and shared links.&lt;/p&gt;

&lt;p&gt;This creates a direct relationship between useful content and playable experiences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Independent Browser Game Development&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Smaller developers can build and distribute browser games without going through the same installation and app-store distribution process required by native applications.&lt;/p&gt;

&lt;p&gt;For developers, this creates another way to experiment with familiar mechanics and reach new audiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: The Same Puzzle, A Different Way to Play
&lt;/h2&gt;

&lt;p&gt;Block puzzle games have succeeded because their core idea is remarkably simple.&lt;/p&gt;

&lt;p&gt;They offer a clear objective, meaningful decisions, and a satisfying sense of progress.&lt;/p&gt;

&lt;p&gt;Mobile apps helped bring this experience to a global audience. Now, modern browser technology is making it possible to enjoy similar puzzle experiences through a completely different access model.&lt;/p&gt;

&lt;p&gt;The interesting question is no longer whether a puzzle game should be an app or a website.&lt;/p&gt;

&lt;p&gt;It is how developers can make the experience enjoyable across both.&lt;/p&gt;

&lt;p&gt;If you enjoy block-placement puzzles, give our browser version a try:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://block-blast.app/" rel="noopener noreferrer"&gt;Play Block Blast Online&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes all you need is an empty grid, three blocks, and one more chance to beat your high score.&lt;/p&gt;

</description>
      <category>webgame</category>
      <category>webdev</category>
      <category>gamedev</category>
      <category>blockblast</category>
    </item>
    <item>
      <title>How to Generate Arrow Puzzles: 7 Algorithms Behind Procedural Level Generation</title>
      <dc:creator>Cliff</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:12:09 +0000</pubDate>
      <link>https://dev.to/cliffwang/how-to-generate-arrow-puzzles-7-algorithms-behind-procedural-level-generation-1p6h</link>
      <guid>https://dev.to/cliffwang/how-to-generate-arrow-puzzles-7-algorithms-behind-procedural-level-generation-1p6h</guid>
      <description>&lt;p&gt;From reverse construction and graph theory to constraint solving and evolutionary algorithms.&lt;/p&gt;

&lt;p&gt;Arrow puzzles look deceptively simple. A board contains a collection of arrows, each pointing in a particular direction. The objective is to remove every arrow by allowing it to escape through the edge of the board.&lt;/p&gt;

&lt;p&gt;But how do you generate hundreds or thousands of interesting levels automatically?&lt;/p&gt;

&lt;p&gt;Randomly placing arrows on a grid is easy. Generating a board that is solvable, visually interesting, and appropriately challenging is a much harder problem.&lt;/p&gt;

&lt;p&gt;This is where procedural puzzle generation comes in.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore seven algorithmic approaches that can be used to generate Arrow Escape-style puzzles, how they work, their advantages and limitations, and how they can be combined into a practical level-generation pipeline.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Understanding the Puzzle as a Computational Problem&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before choosing an algorithm, we need to define the puzzle mechanics.&lt;/p&gt;

&lt;p&gt;Consider a grid containing several arrows. Each arrow consists of connected cells and has a head pointing in one of four directions:&lt;/p&gt;

&lt;p&gt;Up&lt;/p&gt;

&lt;p&gt;Down&lt;/p&gt;

&lt;p&gt;Left&lt;/p&gt;

&lt;p&gt;Right&lt;/p&gt;

&lt;p&gt;When a player selects an arrow, the game checks the straight line from its head to the corresponding edge of the board.&lt;/p&gt;

&lt;p&gt;If that line is clear, the arrow can escape. If another arrow occupies any cell along that line, the move is blocked.&lt;/p&gt;

&lt;p&gt;The objective is to remove all arrows.&lt;/p&gt;

&lt;p&gt;This creates an interesting dependency between arrows.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Arrow A blocks the exit path of Arrow B.&lt;/p&gt;

&lt;p&gt;Arrow B must leave before Arrow A can escape.&lt;/p&gt;

&lt;p&gt;Arrow C may block both A and B.&lt;/p&gt;

&lt;p&gt;Removing C can unlock multiple other arrows.&lt;/p&gt;

&lt;p&gt;The difficulty is therefore not simply determined by the number of arrows. It also depends on how those arrows depend on one another.&lt;/p&gt;

&lt;p&gt;A useful way to think about the problem is as a dependency graph.&lt;/p&gt;

&lt;p&gt;Each arrow is a node, and a directed edge represents a blocking relationship.&lt;/p&gt;

&lt;p&gt;Once we understand this structure, we can start designing algorithms to generate it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm One: Reverse Construction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Build the puzzle backward from a known solution.&lt;/p&gt;

&lt;p&gt;Reverse construction is one of the most practical approaches to generating guaranteed-solvable puzzles.&lt;/p&gt;

&lt;p&gt;Instead of randomly placing arrows and hoping the result works, we start with an empty board and construct it in reverse order.&lt;/p&gt;

&lt;p&gt;Imagine that the intended removal sequence is:&lt;/p&gt;

&lt;p&gt;A → B → C → D&lt;/p&gt;

&lt;p&gt;This means A leaves first, followed by B, C, and D.&lt;/p&gt;

&lt;p&gt;To generate the board, we work backward:&lt;/p&gt;

&lt;p&gt;Place D.&lt;/p&gt;

&lt;p&gt;Place C, ensuring that its exit path is not blocked by D.&lt;/p&gt;

&lt;p&gt;Place B, ensuring that its exit path is not blocked by C or D.&lt;/p&gt;

&lt;p&gt;Place A under the same condition.&lt;/p&gt;

&lt;p&gt;The resulting board has a known solution: remove A, then B, then C, then D.&lt;/p&gt;

&lt;p&gt;In simplified pseudocode:&lt;/p&gt;

&lt;p&gt;def generate_reverse(width, height, count):&lt;br&gt;
    board = empty_grid(width, height)&lt;br&gt;
    solution = []&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(count):
    candidates = find_valid_arrow_placements(board)

    if not candidates:
        break

    arrow = choose_random(candidates)
    place_arrow(board, arrow)
    solution.append(arrow)

return board, list(reversed(solution))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The important part is find_valid_arrow_placements().&lt;/p&gt;

&lt;p&gt;It must check more than whether the arrow fits inside the board. It must also ensure that previously placed arrows do not block the new arrow's exit path.&lt;/p&gt;

&lt;p&gt;A production implementation also needs to handle arrow-body geometry, cell overlap, connectivity, and the chosen construction order.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;Solvability can be guaranteed by construction.&lt;/p&gt;

&lt;p&gt;No expensive search is needed for every candidate.&lt;/p&gt;

&lt;p&gt;Easy to introduce randomness.&lt;/p&gt;

&lt;p&gt;Suitable for generating large numbers of levels.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;The resulting levels can have predictable structures.&lt;/p&gt;

&lt;p&gt;Random placement does not automatically produce good difficulty.&lt;/p&gt;

&lt;p&gt;Complex board shapes can make valid placement increasingly difficult.&lt;/p&gt;

&lt;p&gt;For many Arrow Escape games, this is an excellent starting point.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Two: Randomized Backtracking&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Explore possible placements and backtrack when a construction becomes impossible.&lt;/p&gt;

&lt;p&gt;Randomized backtracking is useful when the board has more restrictive geometric requirements.&lt;/p&gt;

&lt;p&gt;Suppose the generator needs to create a board with:&lt;/p&gt;

&lt;p&gt;A specific number of arrows.&lt;/p&gt;

&lt;p&gt;A target board size.&lt;/p&gt;

&lt;p&gt;Different arrow lengths.&lt;/p&gt;

&lt;p&gt;A mixture of horizontal and vertical paths.&lt;/p&gt;

&lt;p&gt;No overlapping cells.&lt;/p&gt;

&lt;p&gt;Valid exit paths.&lt;/p&gt;

&lt;p&gt;A simple random generator may frequently reach a situation where no additional arrow can be placed.&lt;/p&gt;

&lt;p&gt;Backtracking solves this by exploring alternative choices.&lt;/p&gt;

&lt;p&gt;The algorithm works as follows:&lt;/p&gt;

&lt;p&gt;Select a possible arrow placement.&lt;/p&gt;

&lt;p&gt;Check whether it satisfies the current constraints.&lt;/p&gt;

&lt;p&gt;If valid, add it to the board.&lt;/p&gt;

&lt;p&gt;Continue generating.&lt;/p&gt;

&lt;p&gt;If no valid placement remains, undo the previous choice and try another one.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;def backtrack(board, remaining):&lt;br&gt;
    if remaining == 0:&lt;br&gt;
        return True&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;candidates = generate_candidates(board)
shuffle(candidates)

for arrow in candidates:
    if not is_valid(board, arrow):
        continue

    place_arrow(board, arrow)

    if backtrack(board, remaining - 1):
        return True

    remove_arrow(board, arrow)

return False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In practice, the generator can improve efficiency by using:&lt;/p&gt;

&lt;p&gt;Early constraint checking.&lt;/p&gt;

&lt;p&gt;Candidate ordering.&lt;/p&gt;

&lt;p&gt;Maximum search depth.&lt;/p&gt;

&lt;p&gt;Randomized candidate selection.&lt;/p&gt;

&lt;p&gt;Memoization of repeated states.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;More control over board structure.&lt;/p&gt;

&lt;p&gt;Can satisfy multiple geometric constraints.&lt;/p&gt;

&lt;p&gt;Avoids many dead ends during generation.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Search time can increase rapidly.&lt;/p&gt;

&lt;p&gt;Large boards may have enormous candidate spaces.&lt;/p&gt;

&lt;p&gt;Poor candidate ordering can result in excessive backtracking.&lt;/p&gt;

&lt;p&gt;Backtracking is particularly useful when reverse construction alone cannot satisfy the desired board geometry.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Three: Constraint Satisfaction Problems (CSP)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Define what a valid puzzle looks like, then let a solver find an arrangement.&lt;/p&gt;

&lt;p&gt;Constraint Satisfaction Problems are a more formal approach to puzzle generation.&lt;/p&gt;

&lt;p&gt;Instead of describing every construction step, we define variables, domains, and constraints.&lt;/p&gt;

&lt;p&gt;For an Arrow Puzzle, variables might include:&lt;/p&gt;

&lt;p&gt;Arrow position.&lt;/p&gt;

&lt;p&gt;Arrow direction.&lt;/p&gt;

&lt;p&gt;Arrow length.&lt;/p&gt;

&lt;p&gt;Arrow path.&lt;/p&gt;

&lt;p&gt;Occupied grid cells.&lt;/p&gt;

&lt;p&gt;Blocking relationships.&lt;/p&gt;

&lt;p&gt;Then we define constraints.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Geometric constraints&lt;/p&gt;

&lt;p&gt;Every arrow must remain inside the board.&lt;/p&gt;

&lt;p&gt;No two arrows may occupy the same cell.&lt;/p&gt;

&lt;p&gt;Every arrow must have a valid connected path.&lt;/p&gt;

&lt;p&gt;Every arrow must have a valid head and direction.&lt;/p&gt;

&lt;p&gt;Gameplay constraints&lt;/p&gt;

&lt;p&gt;Every arrow must eventually have an available exit.&lt;/p&gt;

&lt;p&gt;The puzzle must contain at least one removable arrow.&lt;/p&gt;

&lt;p&gt;The dependency relationships must permit complete removal.&lt;/p&gt;

&lt;p&gt;Difficulty constraints&lt;/p&gt;

&lt;p&gt;The number of initially removable arrows must be within a target range.&lt;/p&gt;

&lt;p&gt;Some arrows should depend on several other arrows.&lt;/p&gt;

&lt;p&gt;The solution should contain multiple stages.&lt;/p&gt;

&lt;p&gt;A CSP solver attempts to find an assignment satisfying these conditions.&lt;/p&gt;

&lt;p&gt;Tools such as Google OR-Tools CP-SAT or SAT/SMT solvers can be useful for more complex generation problems.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;Very expressive constraints.&lt;/p&gt;

&lt;p&gt;Good control over board composition.&lt;/p&gt;

&lt;p&gt;Useful for generating levels with specific properties.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Modeling the geometry can be complicated.&lt;/p&gt;

&lt;p&gt;Solving large constraint systems can be expensive.&lt;/p&gt;

&lt;p&gt;A mathematically valid solution is not necessarily an enjoyable level.&lt;/p&gt;

&lt;p&gt;CSP is especially interesting when a game needs precise control over the properties of generated levels.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Four: Dependency Graph Generation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Design the logical relationships first, then build the board around them.&lt;/p&gt;

&lt;p&gt;This is one of the most interesting approaches for Arrow Escape-style puzzles.&lt;/p&gt;

&lt;p&gt;Rather than generating arrows directly, we first generate a directed graph.&lt;/p&gt;

&lt;p&gt;Consider this example:&lt;/p&gt;

&lt;p&gt;A → B → D&lt;br&gt;
     ↓&lt;br&gt;
     C → E&lt;/p&gt;

&lt;p&gt;The graph represents the intended blocking relationships. An arrow cannot escape until the arrows blocking its exit path have been removed.&lt;/p&gt;

&lt;p&gt;Depending on the chosen edge convention, the graph can be represented as:&lt;/p&gt;

&lt;p&gt;dependencies = {&lt;br&gt;
    "A": [],&lt;br&gt;
    "B": ["A"],&lt;br&gt;
    "C": ["B"],&lt;br&gt;
    "D": ["B"],&lt;br&gt;
    "E": ["C"]&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Here, an arrow's dependency list identifies the arrows that must leave before it can escape.&lt;/p&gt;

&lt;p&gt;The generator can then:&lt;/p&gt;

&lt;p&gt;Create a directed acyclic graph (DAG).&lt;/p&gt;

&lt;p&gt;Control its depth and branching factor.&lt;/p&gt;

&lt;p&gt;Assign arrows to graph nodes.&lt;/p&gt;

&lt;p&gt;Find geometric placements that realize the desired blocking relationships.&lt;/p&gt;

&lt;p&gt;Validate the resulting board.&lt;/p&gt;

&lt;p&gt;Why use a DAG?&lt;/p&gt;

&lt;p&gt;Because a valid removal sequence must exist. A directed cycle in which every arrow depends on another arrow in the same cycle would create a deadlock.&lt;/p&gt;

&lt;p&gt;A topological ordering of the dependency graph provides a valid removal order.&lt;/p&gt;

&lt;p&gt;This approach separates two problems:&lt;/p&gt;

&lt;p&gt;Logical puzzle design.&lt;/p&gt;

&lt;p&gt;Geometric board construction.&lt;/p&gt;

&lt;p&gt;That separation can make the generator easier to control and debug.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;Direct control over logical complexity.&lt;/p&gt;

&lt;p&gt;Easy to measure dependency depth.&lt;/p&gt;

&lt;p&gt;Useful for creating bottlenecks and branching structures.&lt;/p&gt;

&lt;p&gt;Can produce more intentional difficulty progression.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Not every abstract graph can be represented by valid arrow geometry.&lt;/p&gt;

&lt;p&gt;Geometric placement may introduce unintended dependencies.&lt;/p&gt;

&lt;p&gt;The final board still needs simulation and validation.&lt;/p&gt;

&lt;p&gt;This is a particularly promising approach when the goal is to generate levels with deliberately designed logical structures.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Five: Generate-and-Test with an Automatic Solver&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Generate candidates, solve them, and reject unsuitable levels.&lt;/p&gt;

&lt;p&gt;Sometimes the simplest solution is to generate many possible boards and let an automatic solver evaluate them.&lt;/p&gt;

&lt;p&gt;A typical pipeline looks like this:&lt;/p&gt;

&lt;p&gt;Generate a candidate board&lt;br&gt;
          |&lt;br&gt;
          v&lt;br&gt;
Check geometric validity&lt;br&gt;
          |&lt;br&gt;
          v&lt;br&gt;
Run automatic solver&lt;br&gt;
          |&lt;br&gt;
          v&lt;br&gt;
Is the board solvable?&lt;br&gt;
       /       \&lt;br&gt;
     No         Yes&lt;br&gt;
     |           |&lt;br&gt;
   Reject    Evaluate difficulty&lt;br&gt;
                 |&lt;br&gt;
                 v&lt;br&gt;
          Accept or reject&lt;/p&gt;

&lt;p&gt;For a basic Arrow Escape mechanic, the solver can be surprisingly simple.&lt;/p&gt;

&lt;p&gt;At each step:&lt;/p&gt;

&lt;p&gt;Find all arrows with a clear path to the edge.&lt;/p&gt;

&lt;p&gt;Remove one available arrow.&lt;/p&gt;

&lt;p&gt;Update the board.&lt;/p&gt;

&lt;p&gt;Repeat until all arrows are removed or no removable arrow remains.&lt;/p&gt;

&lt;p&gt;An example:&lt;/p&gt;

&lt;p&gt;def solve(board):&lt;br&gt;
    remaining = set(board.arrows)&lt;br&gt;
    solution = []&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while remaining:
    available = [
        arrow for arrow in remaining
        if is_exit_path_clear(board, arrow, remaining)
    ]

    if not available:
        return None

    arrow = available[0]

    remaining.remove(arrow)
    solution.append(arrow)

return solution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For the removal-only mechanic described here, there is an important mathematical property:&lt;/p&gt;

&lt;p&gt;Removing an arrow only makes the board emptier. It cannot block another arrow that was previously free.&lt;/p&gt;

&lt;p&gt;Therefore, if at least one removable arrow exists, removing it cannot destroy the possibility of completing the puzzle. Repeatedly removing available arrows will eventually clear any solvable board.&lt;/p&gt;

&lt;p&gt;This means a greedy solver is sufficient for checking basic solvability.&lt;/p&gt;

&lt;p&gt;However, this does not mean all generated levels are equally interesting.&lt;/p&gt;

&lt;p&gt;The solver can also collect information about:&lt;/p&gt;

&lt;p&gt;How many arrows are initially available.&lt;/p&gt;

&lt;p&gt;How many rounds of removal are required.&lt;/p&gt;

&lt;p&gt;How many arrows become available after each removal.&lt;/p&gt;

&lt;p&gt;Which arrows unlock the largest number of others.&lt;/p&gt;

&lt;p&gt;How long the longest dependency chain is.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;Easy to implement and understand.&lt;/p&gt;

&lt;p&gt;Excellent for filtering invalid candidates.&lt;/p&gt;

&lt;p&gt;Can be combined with almost any generation method.&lt;/p&gt;

&lt;p&gt;Provides useful data for difficulty estimation.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Solvability alone says very little about puzzle quality.&lt;/p&gt;

&lt;p&gt;Generating and testing too many candidates can be expensive.&lt;/p&gt;

&lt;p&gt;A simple solver may not accurately predict human difficulty.&lt;/p&gt;

&lt;p&gt;For this puzzle mechanic, generate-and-test is particularly effective as a validation layer.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Six: Template-Based Procedural Generation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Combine handcrafted structures with randomized variations.&lt;/p&gt;

&lt;p&gt;Pure randomness is not always the best way to generate enjoyable puzzles.&lt;/p&gt;

&lt;p&gt;A useful alternative is to create a collection of puzzle templates.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Linear dependency patterns.&lt;/p&gt;

&lt;p&gt;Branching structures.&lt;/p&gt;

&lt;p&gt;Multiple independent starting arrows.&lt;/p&gt;

&lt;p&gt;Narrow bottlenecks.&lt;/p&gt;

&lt;p&gt;Dense central clusters.&lt;/p&gt;

&lt;p&gt;Multiple paths that eventually converge.&lt;/p&gt;

&lt;p&gt;The generator selects a template and fills it with randomized arrow geometry.&lt;/p&gt;

&lt;p&gt;A possible workflow:&lt;/p&gt;

&lt;p&gt;template = choose_template(difficulty)&lt;/p&gt;

&lt;p&gt;board = create_board_from_template(template)&lt;/p&gt;

&lt;p&gt;board = randomize_arrow_paths(board)&lt;/p&gt;

&lt;p&gt;if validate(board):&lt;br&gt;
    return board&lt;/p&gt;

&lt;p&gt;Templates can control the overall logical structure, while procedural generation provides variation in:&lt;/p&gt;

&lt;p&gt;Arrow lengths.&lt;/p&gt;

&lt;p&gt;Arrow directions.&lt;/p&gt;

&lt;p&gt;Path shapes.&lt;/p&gt;

&lt;p&gt;Board dimensions.&lt;/p&gt;

&lt;p&gt;Arrow density.&lt;/p&gt;

&lt;p&gt;This is a form of hybrid generation.&lt;/p&gt;

&lt;p&gt;It combines the reliability of handcrafted design with the scalability of procedural generation.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;More predictable level quality.&lt;/p&gt;

&lt;p&gt;Easier difficulty tuning.&lt;/p&gt;

&lt;p&gt;Good for building recognizable level families.&lt;/p&gt;

&lt;p&gt;Less likely to produce visually repetitive random noise.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Requires an initial template library.&lt;/p&gt;

&lt;p&gt;Repeated structures may become recognizable.&lt;/p&gt;

&lt;p&gt;Templates can limit long-term variety.&lt;/p&gt;

&lt;p&gt;For a game with a carefully designed progression, this can be a very practical approach.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithm Seven: Evolutionary Algorithms and Genetic Optimization&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The basic idea: Generate many candidates and evolve them toward desired difficulty and quality.&lt;/p&gt;

&lt;p&gt;Evolutionary algorithms take a different approach.&lt;/p&gt;

&lt;p&gt;Instead of generating one board and immediately accepting or rejecting it, we create a population of candidate boards.&lt;/p&gt;

&lt;p&gt;Each candidate receives a fitness score.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;fitness = (&lt;br&gt;
    weight_1 * dependency_depth&lt;br&gt;
    + weight_2 * blocking_density&lt;br&gt;
    + weight_3 * branching_score&lt;br&gt;
    - weight_4 * visual_repetition&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;The algorithm then:&lt;/p&gt;

&lt;p&gt;Generates an initial population.&lt;/p&gt;

&lt;p&gt;Evaluates each candidate.&lt;/p&gt;

&lt;p&gt;Selects better candidates.&lt;/p&gt;

&lt;p&gt;Mutates their arrow positions, lengths, and directions.&lt;/p&gt;

&lt;p&gt;Combines selected structures.&lt;/p&gt;

&lt;p&gt;Repeats the process over several generations.&lt;/p&gt;

&lt;p&gt;The objective is to find boards that satisfy a desired combination of properties.&lt;/p&gt;

&lt;p&gt;For example, an intermediate-level puzzle might aim for:&lt;/p&gt;

&lt;p&gt;A moderate number of initially available arrows.&lt;/p&gt;

&lt;p&gt;Several dependency chains.&lt;/p&gt;

&lt;p&gt;A few meaningful bottlenecks.&lt;/p&gt;

&lt;p&gt;A reasonable number of arrows unlocked per stage.&lt;/p&gt;

&lt;p&gt;A visually balanced board.&lt;/p&gt;

&lt;p&gt;Evolutionary algorithms can optimize for these characteristics.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;p&gt;Can explore unusual puzzle structures.&lt;/p&gt;

&lt;p&gt;Allows multi-objective optimization.&lt;/p&gt;

&lt;p&gt;Useful when the quality function is difficult to express as hard constraints.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;p&gt;Requires carefully designed fitness functions.&lt;/p&gt;

&lt;p&gt;Can converge toward repetitive structures.&lt;/p&gt;

&lt;p&gt;More computationally expensive than direct construction.&lt;/p&gt;

&lt;p&gt;A high fitness score does not guarantee an enjoyable puzzle.&lt;/p&gt;

&lt;p&gt;Evolutionary generation is probably unnecessary for a small game, but it becomes interesting when generating large collections of levels with specific difficulty targets.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How Should an Arrow Puzzle Generator Measure Difficulty?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This may actually be the most important part of the entire system.&lt;/p&gt;

&lt;p&gt;A board with 100 arrows is not necessarily harder than a board with 60 arrows.&lt;/p&gt;

&lt;p&gt;The number of arrows is only one dimension of complexity.&lt;/p&gt;

&lt;p&gt;For Arrow Escape-style puzzles, I would consider the following metrics.&lt;/p&gt;

&lt;p&gt;Metric&lt;/p&gt;

&lt;p&gt;What it measures&lt;/p&gt;

&lt;p&gt;Initial availability&lt;/p&gt;

&lt;p&gt;Number of arrows that can escape immediately&lt;/p&gt;

&lt;p&gt;Dependency depth&lt;/p&gt;

&lt;p&gt;Length of the longest chain of blocking relationships&lt;/p&gt;

&lt;p&gt;Blocking density&lt;/p&gt;

&lt;p&gt;Average number of arrows blocking each arrow&lt;/p&gt;

&lt;p&gt;Bottleneck severity&lt;/p&gt;

&lt;p&gt;How much progress depends on a small number of arrows&lt;/p&gt;

&lt;p&gt;Unlock potential&lt;/p&gt;

&lt;p&gt;Number of new arrows made available after a removal&lt;/p&gt;

&lt;p&gt;Board density&lt;/p&gt;

&lt;p&gt;Proportion of occupied cells&lt;/p&gt;

&lt;p&gt;Structural variety&lt;/p&gt;

&lt;p&gt;Diversity of arrow shapes and directions&lt;/p&gt;

&lt;p&gt;One particularly useful metric is the dependency depth.&lt;/p&gt;

&lt;p&gt;Consider two boards containing the same number of arrows.&lt;/p&gt;

&lt;p&gt;Board A:&lt;/p&gt;

&lt;p&gt;Many arrows can escape independently. Removing one arrow does not significantly affect the others.&lt;/p&gt;

&lt;p&gt;Board B:&lt;/p&gt;

&lt;p&gt;Most arrows depend on other arrows. Removing one particular arrow may unlock a long sequence of subsequent moves.&lt;/p&gt;

&lt;p&gt;Even if both boards contain 50 arrows, Board B may feel considerably more complex.&lt;/p&gt;

&lt;p&gt;Another useful metric is the number of available arrows at each stage.&lt;/p&gt;

&lt;p&gt;We can record this as a sequence:&lt;/p&gt;

&lt;p&gt;Stage 1: 3 available arrows&lt;br&gt;
Stage 2: 2 available arrows&lt;br&gt;
Stage 3: 1 available arrow&lt;br&gt;
Stage 4: 5 available arrows&lt;br&gt;
Stage 5: 8 available arrows&lt;br&gt;
...&lt;/p&gt;

&lt;p&gt;This sequence gives us a better understanding of how the puzzle unfolds.&lt;/p&gt;

&lt;p&gt;It can also help identify levels that are too straightforward or have repetitive progression.&lt;/p&gt;

&lt;p&gt;One caution: these metrics are proxies, not direct measurements of human difficulty. The best way to calibrate them is to compare generated levels with actual player performance.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Practical Architecture for a Procedural Arrow Puzzle Generator&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If I were building a procedural generation system for an Arrow Escape game, I would not rely on a single algorithm.&lt;/p&gt;

&lt;p&gt;I would combine several approaches into one pipeline.&lt;/p&gt;

&lt;p&gt;My preferred architecture would look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     Difficulty Configuration
               |
               v
      Dependency Generator
               |
               v
      Reverse Construction
               |
               v
      Geometric Randomization
               |
               v
      Constraint Validation
               |
               v
      Automatic Solver
               |
               v
      Difficulty Evaluation
               |
         +-----+-----+
         |           |
      Accept       Reject
         |           |
         v           v
    Save Level    Regenerate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Each component has a specific responsibility.&lt;/p&gt;

&lt;p&gt;Dependency Generator&lt;/p&gt;

&lt;p&gt;Defines the intended logical relationships between arrows.&lt;/p&gt;

&lt;p&gt;Reverse Construction&lt;/p&gt;

&lt;p&gt;Builds a board with a known valid removal sequence.&lt;/p&gt;

&lt;p&gt;Geometric Randomization&lt;/p&gt;

&lt;p&gt;Adds variation to arrow shapes, positions, and lengths.&lt;/p&gt;

&lt;p&gt;Constraint Validation&lt;/p&gt;

&lt;p&gt;Checks overlapping cells, invalid paths, board boundaries, and unintended geometry.&lt;/p&gt;

&lt;p&gt;Automatic Solver&lt;/p&gt;

&lt;p&gt;Confirms that the final board can be completely cleared.&lt;/p&gt;

&lt;p&gt;Difficulty Evaluation&lt;/p&gt;

&lt;p&gt;Measures the dependency structure and compares the results against the target difficulty.&lt;/p&gt;

&lt;p&gt;This architecture is modular, so individual components can be improved without rewriting the entire generator.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Final Thoughts: Random Generation Is Not the Same as Good Puzzle Design&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Procedural generation makes it possible to create a large number of Arrow Puzzle levels, but generating more levels does not automatically mean generating better levels.&lt;/p&gt;

&lt;p&gt;The most interesting systems combine three things:&lt;/p&gt;

&lt;p&gt;Mathematical validity: Every generated board has a complete solution.&lt;/p&gt;

&lt;p&gt;Structural variety: Different levels introduce different dependency patterns and geometric arrangements.&lt;/p&gt;

&lt;p&gt;Controlled difficulty: The generator can create a meaningful progression instead of simply increasing the number of arrows.&lt;/p&gt;

&lt;p&gt;Reverse construction is an excellent foundation. Dependency graphs provide more control over logical structure. Automatic solvers make validation straightforward. Constraint solving and evolutionary optimization can add more sophisticated control when needed.&lt;/p&gt;

&lt;p&gt;Ultimately, the best generator is not necessarily the one that creates the most complicated boards.&lt;/p&gt;

&lt;p&gt;It is the one that consistently creates puzzles that make players stop, observe, think, and finally discover the right move.&lt;/p&gt;

&lt;p&gt;Try an Arrow Puzzle&lt;/p&gt;

&lt;p&gt;If you enjoy exploring how directional logic and spatial relationships create interesting puzzle challenges, you can also try a browser-based Arrow Escape game at &lt;a href="https://puzzle-arrow.com" rel="noopener noreferrer"&gt;Puzzle Arrow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is a useful way to experience the mechanics discussed in this article and see how different arrow arrangements can create different levels of challenge.&lt;/p&gt;

&lt;p&gt;What generation approach would you use for an Arrow Puzzle game: reverse construction, graph-based generation, or a hybrid system?&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>algorithms</category>
      <category>webdev</category>
      <category>arrowpuzzle</category>
    </item>
    <item>
      <title>How to Build a Browser-Based Jigsaw Puzzle Game with JavaScript and HTML5 Canvas</title>
      <dc:creator>Cliff</dc:creator>
      <pubDate>Fri, 06 Nov 2026 01:47:01 +0000</pubDate>
      <link>https://dev.to/cliffwang/how-to-build-a-browser-based-jigsaw-puzzle-game-with-javascript-and-html5-canvas-33gm</link>
      <guid>https://dev.to/cliffwang/how-to-build-a-browser-based-jigsaw-puzzle-game-with-javascript-and-html5-canvas-33gm</guid>
      <description>&lt;p&gt;Building a jigsaw puzzle game for the browser is an interesting combination of geometry, graphics programming, and interactive game development.&lt;/p&gt;

&lt;p&gt;Unlike a traditional grid-based puzzle, a jigsaw puzzle requires irregular piece shapes, matching edges, image clipping, and precise drag-and-drop interactions. Players should be able to move individual pieces, connect matching pieces, and gradually reconstruct the original image.&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll explore how to build a browser-based jigsaw puzzle game using JavaScript and HTML5 Canvas, starting with the basic game architecture and moving through piece generation, rendering, interaction, and performance optimization.&lt;/p&gt;

&lt;p&gt;The goal is to create a fully playable game that runs directly in a web browser without requiring downloads or additional software.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Planning the Game Architecture&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before implementing the puzzle mechanics, it's useful to break the game into smaller components.&lt;/p&gt;

&lt;p&gt;A browser-based jigsaw puzzle game typically needs several systems:&lt;/p&gt;

&lt;p&gt;Component&lt;/p&gt;

&lt;p&gt;Responsibility&lt;/p&gt;

&lt;p&gt;Game Manager&lt;/p&gt;

&lt;p&gt;Controls the overall game state&lt;/p&gt;

&lt;p&gt;Puzzle Generator&lt;/p&gt;

&lt;p&gt;Divides the original image into pieces&lt;/p&gt;

&lt;p&gt;Shape Generator&lt;/p&gt;

&lt;p&gt;Creates realistic jigsaw piece boundaries&lt;/p&gt;

&lt;p&gt;Canvas Renderer&lt;/p&gt;

&lt;p&gt;Draws pieces and the game board&lt;/p&gt;

&lt;p&gt;Input Manager&lt;/p&gt;

&lt;p&gt;Handles mouse and touch interactions&lt;/p&gt;

&lt;p&gt;Snap Manager&lt;/p&gt;

&lt;p&gt;Detects matching pieces and connections&lt;/p&gt;

&lt;p&gt;Progress Tracker&lt;/p&gt;

&lt;p&gt;Tracks completed pieces and game progress&lt;/p&gt;

&lt;p&gt;Keeping these systems separate makes the game easier to maintain and extend.&lt;/p&gt;

&lt;p&gt;For example, changing the puzzle difficulty from 16 pieces to 100 pieces should not require rewriting the rendering or interaction logic.&lt;/p&gt;

&lt;p&gt;A basic game state might look like this:&lt;/p&gt;

&lt;p&gt;`const gameState = {&lt;br&gt;
  status: "playing",&lt;/p&gt;

&lt;p&gt;rows: 4,&lt;br&gt;
  cols: 4,&lt;/p&gt;

&lt;p&gt;pieces: [],&lt;/p&gt;

&lt;p&gt;selectedPiece: null,&lt;/p&gt;

&lt;p&gt;placedCount: 0,&lt;/p&gt;

&lt;p&gt;startTime: Date.now()&lt;br&gt;
};`&lt;/p&gt;

&lt;p&gt;Possible game states include:&lt;/p&gt;

&lt;p&gt;loading: Preparing the puzzle image and geometry.&lt;/p&gt;

&lt;p&gt;playing: The player is assembling the puzzle.&lt;/p&gt;

&lt;p&gt;paused: Gameplay is temporarily suspended.&lt;/p&gt;

&lt;p&gt;completed: All pieces have been correctly assembled.&lt;/p&gt;

&lt;p&gt;This simple structure provides a foundation for implementing the rest of the game.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating the Puzzle Grid&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first step is dividing the original image into a rectangular grid.&lt;/p&gt;

&lt;p&gt;Suppose the source image has a width of 1200 pixels and a height of 800 pixels.&lt;/p&gt;

&lt;p&gt;For a 4 × 4 puzzle:&lt;/p&gt;

&lt;p&gt;const rows = 4;&lt;br&gt;
const cols = 4;&lt;/p&gt;

&lt;p&gt;const pieceWidth = image.width / cols;&lt;br&gt;
const pieceHeight = image.height / rows;&lt;/p&gt;

&lt;p&gt;Each piece has a logical position in the completed image.&lt;/p&gt;

&lt;p&gt;We can calculate its original coordinates using its row and column:&lt;/p&gt;

&lt;p&gt;function getPiecePosition(row, col, width, height) {&lt;br&gt;
  return {&lt;br&gt;
    x: col * width,&lt;br&gt;
    y: row * height&lt;br&gt;
  };&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;However, these rectangular regions are only the starting point.&lt;/p&gt;

&lt;p&gt;A realistic jigsaw puzzle requires each piece to have a unique outline, with tabs and blanks that fit neighboring pieces.&lt;/p&gt;

&lt;p&gt;This brings us to the most important part of the geometry system.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generating Matching Jigsaw Piece Edges&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A common mistake when implementing jigsaw puzzles is generating every piece independently.&lt;/p&gt;

&lt;p&gt;This can lead to small differences between neighboring edges, creating visible gaps or overlaps.&lt;/p&gt;

&lt;p&gt;A better approach is to generate shared boundaries first.&lt;/p&gt;

&lt;p&gt;Each internal boundary is created once and reused by the two adjacent pieces.&lt;/p&gt;

&lt;p&gt;For a grid of rows and columns, we need two sets of boundaries:&lt;/p&gt;

&lt;p&gt;Horizontal boundaries between rows.&lt;/p&gt;

&lt;p&gt;Vertical boundaries between columns.&lt;/p&gt;

&lt;p&gt;Each boundary contains a geometric description and a polarity.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Positive polarity: A protruding tab.&lt;/p&gt;

&lt;p&gt;Negative polarity: A recessed blank.&lt;/p&gt;

&lt;p&gt;A simplified edge map can be generated as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;randomPolarity&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createEdgeMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;horizontal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;vertical&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;horizontal&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;horizontal&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;randomPolarity&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;vertical&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;vertical&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;randomPolarity&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;horizontal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vertical&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a complete implementation, each entry should store the full edge geometry rather than just its polarity.&lt;/p&gt;

&lt;p&gt;The neighboring pieces then reuse the same geometry in opposite directions.&lt;/p&gt;

&lt;p&gt;This ensures that their boundaries match exactly.&lt;/p&gt;

&lt;p&gt;Outer puzzle boundaries are treated differently: they remain straight rather than receiving tabs or blanks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating Realistic Piece Shapes with Bézier Curves&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Jigsaw puzzle pieces are recognizable because of their characteristic tabs and recessed edges.&lt;/p&gt;

&lt;p&gt;We can approximate these shapes using cubic Bézier curves.&lt;/p&gt;

&lt;p&gt;A cubic Bézier curve is defined by four control points:&lt;/p&gt;

&lt;p&gt;P0: Starting point.&lt;/p&gt;

&lt;p&gt;P1: First control point.&lt;/p&gt;

&lt;p&gt;P2: Second control point.&lt;/p&gt;

&lt;p&gt;P3: Ending point.&lt;/p&gt;

&lt;p&gt;Its mathematical representation is:&lt;/p&gt;

&lt;p&gt;B(t) = (1-t)³P0&lt;br&gt;
     + 3(1-t)²tP1&lt;br&gt;
     + 3(1-t)t²P2&lt;br&gt;
     + t³P3&lt;/p&gt;

&lt;p&gt;where t ranges from 0 to 1.&lt;/p&gt;

&lt;p&gt;By adjusting the control points, we can create the rounded head and narrow neck of a traditional jigsaw tab.&lt;/p&gt;

&lt;p&gt;For example, Canvas provides a convenient method:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctx.bezierCurveTo(&lt;br&gt;
  controlX1,&lt;br&gt;
  controlY1,&lt;br&gt;
  controlX2,&lt;br&gt;
  controlY2,&lt;br&gt;
  endX,&lt;br&gt;
  endY&lt;br&gt;
);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A simplified edge renderer might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;drawTab&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lineTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bezierCurveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.55&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bezierCurveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.55&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bezierCurveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.72&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.55&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lineTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The direction determines whether the tab protrudes or curves inward.&lt;/p&gt;

&lt;p&gt;For a production-quality game, the geometry should also account for:&lt;/p&gt;

&lt;p&gt;Consistent endpoints and tangent directions.&lt;/p&gt;

&lt;p&gt;Variable tab widths and depths.&lt;/p&gt;

&lt;p&gt;Different shapes for horizontal and vertical edges.&lt;/p&gt;

&lt;p&gt;Reversed traversal when rendering neighboring pieces.&lt;/p&gt;

&lt;p&gt;Shared control points to prevent mismatched boundaries.&lt;/p&gt;

&lt;p&gt;The objective is to generate varied-looking pieces while maintaining mathematically consistent connections.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Constructing the Complete Puzzle Piece&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once all four edges are available, we can construct the outline of each piece.&lt;/p&gt;

&lt;p&gt;A convenient strategy is to trace the shape clockwise:&lt;/p&gt;

&lt;p&gt;Start at the top-left corner.&lt;/p&gt;

&lt;p&gt;Draw the top edge from left to right.&lt;/p&gt;

&lt;p&gt;Draw the right edge from top to bottom.&lt;/p&gt;

&lt;p&gt;Draw the bottom edge from right to left.&lt;/p&gt;

&lt;p&gt;Draw the left edge from bottom to top.&lt;/p&gt;

&lt;p&gt;Close the path.&lt;/p&gt;

&lt;p&gt;A simplified structure looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createPiecePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;edges&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;drawEdge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;drawEdge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;drawEdge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;drawEdge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closePath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, drawEdge() is a reusable function that renders the corresponding edge geometry.&lt;/p&gt;

&lt;p&gt;For a clean implementation, it is helpful to define each edge in local coordinates and apply transformations when placing it on different sides of the piece.&lt;/p&gt;

&lt;p&gt;This avoids duplicating the same Bézier geometry for horizontal and vertical boundaries.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rendering Puzzle Pieces with HTML5 Canvas&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the geometry generated, we can start rendering the actual puzzle.&lt;/p&gt;

&lt;p&gt;The key technique is Canvas clipping.&lt;/p&gt;

&lt;p&gt;Instead of creating a separate cropped image for every piece, we draw the original image through each piece's irregular clipping path.&lt;/p&gt;

&lt;p&gt;This preserves image alignment across the entire puzzle.&lt;/p&gt;

&lt;p&gt;The basic process is:&lt;/p&gt;

&lt;p&gt;Save the current Canvas state.&lt;/p&gt;

&lt;p&gt;Translate to the piece's position.&lt;/p&gt;

&lt;p&gt;Define its clipping path.&lt;/p&gt;

&lt;p&gt;Draw the original image.&lt;/p&gt;

&lt;p&gt;Restore the Canvas state.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderPiece&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createLocalPiecePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sourceX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sourceY&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important detail is that every piece uses the same original image coordinate system.&lt;/p&gt;

&lt;p&gt;This means that when all pieces are placed correctly, the image lines up seamlessly.&lt;/p&gt;

&lt;p&gt;We can also draw a border around each piece:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createLocalPiecePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;strokeStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rgba(0, 0, 0, 0.25)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lineWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additional visual effects such as shadows, hover highlights, and selection outlines can make the game feel much more responsive.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implementing Drag-and-Drop Interaction&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A jigsaw puzzle would not be playable without intuitive piece movement.&lt;/p&gt;

&lt;p&gt;Each piece needs to track two different positions:&lt;/p&gt;

&lt;p&gt;Its original position in the completed puzzle.&lt;/p&gt;

&lt;p&gt;Its current position on the game board.&lt;/p&gt;

&lt;p&gt;A simple piece object might look like this:&lt;/p&gt;

&lt;p&gt;`const piece = {&lt;br&gt;
  id: 0,&lt;/p&gt;

&lt;p&gt;correctX: 120,&lt;br&gt;
  correctY: 80,&lt;/p&gt;

&lt;p&gt;currentX: 350,&lt;br&gt;
  currentY: 220,&lt;/p&gt;

&lt;p&gt;isDragging: false,&lt;br&gt;
  isPlaced: false&lt;br&gt;
};`&lt;/p&gt;

&lt;p&gt;When the player selects a piece, we record the pointer offset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;startDrag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pointerX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pointerY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDragging&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dragOffsetX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointerX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dragOffsetY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointerY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;While&lt;/span&gt; &lt;span class="nx"&gt;dragging&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;movePiece&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pointerX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pointerY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDragging&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointerX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dragOffsetX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointerY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dragOffsetY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the pointer is released, the game can check whether the piece is close enough to its correct position.&lt;/p&gt;

&lt;p&gt;For browser games, the Pointer Events API is particularly useful because it supports mouse, touch, and pen input through a unified event model.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;canvas.addEventListener("pointerdown", handlePointerDown);&lt;br&gt;
canvas.addEventListener("pointermove", handlePointerMove);&lt;br&gt;
canvas.addEventListener("pointerup", handlePointerUp);&lt;/p&gt;

&lt;p&gt;canvas.addEventListener("pointercancel", handlePointerUp);&lt;/p&gt;

&lt;p&gt;For mobile browsers, setting an appropriate touch-action CSS property on the game interaction surface also helps prevent unwanted browser gestures while dragging.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detecting Correct Placement and Snapping Pieces&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simple snapping system compares the current position of a piece with its original position.&lt;/p&gt;

&lt;p&gt;We can use Euclidean distance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkSnap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;threshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;correctX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;correctY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;distance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hypot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;distance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;correctX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;correctY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;piece&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isPlaced&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works well for a basic puzzle where pieces are placed directly into their final positions.&lt;/p&gt;

&lt;p&gt;However, more advanced games can support connections between neighboring pieces before they reach the correct location.&lt;/p&gt;

&lt;p&gt;For example, when two pieces are close enough and their corresponding edges match, they can snap together and form a larger group.&lt;/p&gt;

&lt;p&gt;This introduces the concept of connected piece clusters.&lt;/p&gt;

&lt;p&gt;A cluster can be represented as a collection of pieces that share a common movement offset.&lt;/p&gt;

&lt;p&gt;When the player drags one piece in a connected cluster, all the other pieces move with it.&lt;/p&gt;

&lt;p&gt;This creates a more natural puzzle-solving experience, especially for larger puzzles.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding Difficulty Levels and Game Progress&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A complete browser-based jigsaw puzzle game should offer more than just a fixed grid.&lt;/p&gt;

&lt;p&gt;Different piece counts can provide different difficulty levels.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Difficulty&lt;/p&gt;

&lt;p&gt;Grid&lt;/p&gt;

&lt;p&gt;Total Pieces&lt;/p&gt;

&lt;p&gt;Easy&lt;/p&gt;

&lt;p&gt;3 × 3&lt;/p&gt;

&lt;p&gt;9&lt;/p&gt;

&lt;p&gt;Medium&lt;/p&gt;

&lt;p&gt;5 × 5&lt;/p&gt;

&lt;p&gt;25&lt;/p&gt;

&lt;p&gt;Hard&lt;/p&gt;

&lt;p&gt;8 × 8&lt;/p&gt;

&lt;p&gt;64&lt;/p&gt;

&lt;p&gt;Expert&lt;/p&gt;

&lt;p&gt;10 × 10&lt;/p&gt;

&lt;p&gt;100&lt;/p&gt;

&lt;p&gt;The actual difficulty also depends on the image itself, the shape variation, and whether players can use a reference image.&lt;/p&gt;

&lt;p&gt;A progress tracker can be implemented with a simple counter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateProgress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gameState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cols&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;progress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gameState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;placedCount&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;gameState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;completed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other useful gameplay features include:&lt;/p&gt;

&lt;p&gt;A timer to track completion time.&lt;/p&gt;

&lt;p&gt;A preview of the completed image.&lt;/p&gt;

&lt;p&gt;A shuffle function.&lt;/p&gt;

&lt;p&gt;A restart option.&lt;/p&gt;

&lt;p&gt;A completion animation.&lt;/p&gt;

&lt;p&gt;A responsive puzzle board for smaller screens.&lt;/p&gt;

&lt;p&gt;These features turn the underlying rendering engine into a more complete game experience.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Optimizing Performance for Desktop and Mobile Browsers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Performance becomes increasingly important as the number of pieces grows.&lt;/p&gt;

&lt;p&gt;A 3 × 3 puzzle is relatively easy to render. A 100-piece puzzle requires more careful management.&lt;/p&gt;

&lt;p&gt;Several techniques can help.&lt;/p&gt;

&lt;p&gt;Separate rendering layers&lt;/p&gt;

&lt;p&gt;Instead of redrawing everything unnecessarily, divide the game into layers:&lt;/p&gt;

&lt;p&gt;Background and board.&lt;/p&gt;

&lt;p&gt;Static completed pieces.&lt;/p&gt;

&lt;p&gt;Loose puzzle pieces.&lt;/p&gt;

&lt;p&gt;Active dragging and interaction effects.&lt;/p&gt;

&lt;p&gt;Use offscreen rendering&lt;/p&gt;

&lt;p&gt;Static piece images can be rendered into offscreen canvases and reused.&lt;/p&gt;

&lt;p&gt;This reduces repeated clipping and drawing operations.&lt;/p&gt;

&lt;p&gt;Optimize hit testing&lt;/p&gt;

&lt;p&gt;Checking every pixel of every piece is expensive.&lt;/p&gt;

&lt;p&gt;Start with bounding-box checks to eliminate pieces that are clearly not under the pointer. More precise path-based checks can then be performed on the remaining candidates.&lt;/p&gt;

&lt;p&gt;Avoid unnecessary redraws&lt;/p&gt;

&lt;p&gt;A requestAnimationFrame-based rendering loop can be used to update the game smoothly, but static scenes do not need to be redrawn continuously.&lt;/p&gt;

&lt;p&gt;Consider device pixel ratio&lt;/p&gt;

&lt;p&gt;High-density mobile screens require careful Canvas scaling to keep puzzle edges sharp without creating excessively large rendering surfaces.&lt;/p&gt;

&lt;p&gt;The best optimization strategy depends on the puzzle size, device capabilities, and rendering architecture.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Putting Everything Together&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At this point, we have the major building blocks of a browser-based jigsaw puzzle game:&lt;/p&gt;

&lt;p&gt;Grid generation determines the number and dimensions of pieces.&lt;/p&gt;

&lt;p&gt;Edge generation creates matching boundaries.&lt;/p&gt;

&lt;p&gt;Bézier curves define realistic tabs and blanks.&lt;/p&gt;

&lt;p&gt;Canvas clipping maps the original image onto each piece.&lt;/p&gt;

&lt;p&gt;Pointer events enable interactive dragging.&lt;/p&gt;

&lt;p&gt;Snap detection handles correct placement.&lt;/p&gt;

&lt;p&gt;Game state management tracks progress and completion.&lt;/p&gt;

&lt;p&gt;The complete gameplay flow can be summarized as:&lt;/p&gt;

&lt;p&gt;Load Puzzle Image&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Generate Puzzle Grid&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Create Shared Edge Geometry&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Generate Individual Pieces&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Shuffle Pieces on the Board&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Player Drags and Connects Pieces&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Check Placement and Connections&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Update Game Progress&lt;br&gt;
       |&lt;br&gt;
       v&lt;br&gt;
Complete the Puzzle&lt;/p&gt;

&lt;p&gt;The most important architectural decision is keeping geometry, rendering, interaction, and game state independent.&lt;/p&gt;

&lt;p&gt;This makes it easier to add new features without introducing unnecessary complexity into the core puzzle engine.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Try a Browser-Based Jigsaw Puzzle Game&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The techniques discussed in this tutorial are the foundation of an interactive jigsaw puzzle experience.&lt;/p&gt;

&lt;p&gt;If you want to explore how a browser-based jigsaw puzzle game works in practice, you can try &lt;a href="https://jigsawpuzzlespot.com/" rel="noopener noreferrer"&gt;Jigsaw Puzzle Spot&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It offers free online jigsaw puzzles that can be played directly in the browser, providing a practical example of image-based puzzle gameplay without requiring a separate application or installation.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Building a browser-based jigsaw puzzle game with JavaScript and HTML5 Canvas involves several interesting engineering challenges.&lt;/p&gt;

&lt;p&gt;The most important ones are generating matching piece geometry, rendering irregular shapes, maintaining image alignment, and implementing intuitive drag-and-drop interactions.&lt;/p&gt;

&lt;p&gt;By separating these systems into reusable components, it is possible to build a flexible puzzle engine that supports different image sizes, difficulty levels, and gameplay mechanics.&lt;/p&gt;

&lt;p&gt;What starts as a simple image-splitting exercise can become a surprisingly rich browser game development project.&lt;/p&gt;

&lt;p&gt;And the best part is that the entire experience can run directly in a modern web browser.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>gamedev</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building a Browser-Based Boggle Game with Astro and Vue 3</title>
      <dc:creator>Cliff</dc:creator>
      <pubDate>Sat, 26 Sep 2026 23:29:23 +0000</pubDate>
      <link>https://dev.to/cliffwang/building-a-browser-based-boggle-game-with-astro-and-vue-3-1m6l</link>
      <guid>https://dev.to/cliffwang/building-a-browser-based-boggle-game-with-astro-and-vue-3-1m6l</guid>
      <description>&lt;p&gt;Building a word game looks simple at first.&lt;/p&gt;

&lt;p&gt;A Boggle-style game seems to need only a letter grid, a word list, some input handling, and a score counter. But once the game needs to work well on both desktop and mobile, the implementation becomes a combination of UI state management, graph traversal, word validation, touch interaction, and performance optimization.&lt;/p&gt;

&lt;p&gt;I recently built a browser-based Boggle game using &lt;strong&gt;Astro and Vue 3&lt;/strong&gt;, and this article explains some of the engineering decisions behind it.&lt;/p&gt;

&lt;p&gt;The goal was not to build a large game engine. Instead, I wanted a lightweight architecture where Astro handles the website and content-oriented pages, while Vue manages the interactive game itself.&lt;/p&gt;

&lt;p&gt;The resulting project is &lt;a href="https://puzzle-boggle.com/" rel="noopener noreferrer"&gt;Puzzle Boggle&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Astro + Vue 3?
&lt;/h2&gt;

&lt;p&gt;Astro is particularly interesting for projects that contain both static content and interactive applications.&lt;/p&gt;

&lt;p&gt;A word game website usually has two very different types of pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Content and informational pages&lt;/li&gt;
&lt;li&gt;Highly interactive game pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A traditional SPA can handle the second problem well, but it can be unnecessarily heavy for the first one.&lt;/p&gt;

&lt;p&gt;Astro provides a useful separation between the two.&lt;/p&gt;

&lt;p&gt;The static parts of the site can be rendered by Astro, while Vue components can be introduced where interactive behavior is required.&lt;/p&gt;

&lt;p&gt;The basic architecture looks roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Astro
│
├── Layout
├── SEO / Metadata
├── Content Pages
├── Game Pages
│
└── Vue
    ├── GameBoard
    ├── LetterTile
    ├── WordInput
    ├── ScorePanel
    └── GameResult
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important idea is that &lt;strong&gt;not everything needs to become a Vue application&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Only the parts that actually need client-side state need to be hydrated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separating the Game UI From the Website
&lt;/h2&gt;

&lt;p&gt;One of the first architectural decisions was separating the website layer from the game layer.&lt;/p&gt;

&lt;p&gt;The Astro side is responsible for things such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;page structure&lt;/li&gt;
&lt;li&gt;navigation&lt;/li&gt;
&lt;li&gt;metadata&lt;/li&gt;
&lt;li&gt;informational content&lt;/li&gt;
&lt;li&gt;SEO&lt;/li&gt;
&lt;li&gt;static layouts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vue is responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current game state&lt;/li&gt;
&lt;li&gt;selected letters&lt;/li&gt;
&lt;li&gt;user input&lt;/li&gt;
&lt;li&gt;word validation&lt;/li&gt;
&lt;li&gt;scoring&lt;/li&gt;
&lt;li&gt;timers&lt;/li&gt;
&lt;li&gt;animations&lt;/li&gt;
&lt;li&gt;game completion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation makes the project easier to reason about.&lt;/p&gt;

&lt;p&gt;The game can behave like a small application inside a larger content-oriented website.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/
├── components/
│   ├── GameBoard.vue
│   ├── LetterTile.vue
│   ├── ScorePanel.vue
│   └── GameResult.vue
│
├── composables/
│   ├── useGame.ts
│   ├── useBoard.ts
│   └── useTimer.ts
│
├── data/
│   ├── dictionaries/
│   └── puzzles/
│
├── pages/
│   ├── index.astro
│   ├── daily-challenge/
│   └── boggle/
│
└── layouts/
    └── Layout.astro
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not the only valid structure, but separating UI components, game logic, and data early makes the project much easier to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modeling the Boggle Board
&lt;/h2&gt;

&lt;p&gt;The board can be represented as a two-dimensional array.&lt;/p&gt;

&lt;p&gt;For example, a 4 × 4 board can be represented as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;T&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;R&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;P&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;S&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;N&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;L&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;O&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;G&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;D&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;M&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;T&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each cell needs to contain more than just a letter during gameplay.&lt;/p&gt;

&lt;p&gt;A useful internal representation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Cell&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;row&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The row and column coordinates are important because Boggle is fundamentally a path-search problem.&lt;/p&gt;

&lt;p&gt;A player is not simply selecting letters.&lt;/p&gt;

&lt;p&gt;They are creating a path through adjacent cells.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Gameplay Problem Is a Graph Traversal
&lt;/h2&gt;

&lt;p&gt;This is probably the most interesting part of implementing Boggle.&lt;/p&gt;

&lt;p&gt;Each letter tile can be considered a node in a graph.&lt;/p&gt;

&lt;p&gt;A tile can connect to its neighboring tiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A B C
D E F
G H I
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From &lt;code&gt;E&lt;/code&gt;, the player can potentially move to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A B C
D   F
G H I
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means the game board can be treated as a graph where each tile has up to eight neighbors.&lt;/p&gt;

&lt;p&gt;The eight possible directions are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;directions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a player selects a tile, the game needs to determine whether the next tile is adjacent to the previous tile.&lt;/p&gt;

&lt;p&gt;A simple helper function can handle this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isAdjacent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cell&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rowDistance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colDistance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;col&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;rowDistance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nx"&gt;colDistance&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rowDistance&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;colDistance&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next important rule is that the same tile cannot normally be used twice in the same word.&lt;/p&gt;

&lt;p&gt;So the game state needs to maintain the path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;selectedCells&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Cell&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the player selects a new tile, the game checks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is this tile adjacent to the previous tile?&lt;/li&gt;
&lt;li&gt;Has this tile already been selected?&lt;/li&gt;
&lt;li&gt;If valid, add it to the current path.&lt;/li&gt;
&lt;li&gt;Otherwise reject the selection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These rules become especially important on mobile devices where users interact with the board using touch rather than a mouse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Vue 3 Composition API
&lt;/h2&gt;

&lt;p&gt;Vue 3's Composition API is a good fit for this type of game because game logic can be separated into reusable composables.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentWord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;selectedCells&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Cell&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foundWords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;gameOver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the logic can be organized into functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;selectCell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;canSelect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;selectedCells&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;currentWord&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;letter&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;submitWord&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentWord&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;isValidWord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;resetSelection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;foundWords&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;resetSelection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;foundWords&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;calculateScore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="nf"&gt;resetSelection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the reasons I prefer Composition API for interactive game components.&lt;/p&gt;

&lt;p&gt;The state and behavior can stay close together without forcing the entire game into one huge component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Word Validation Is a Separate Problem
&lt;/h2&gt;

&lt;p&gt;The board traversal algorithm and the dictionary system should not be tightly coupled.&lt;/p&gt;

&lt;p&gt;These are two different problems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Can the player create this sequence of letters?
                    ↓
              currentWord

                    ↓

Is this sequence a valid word?
                    ↓
               dictionary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keeping them separate makes the game easier to modify.&lt;/p&gt;

&lt;p&gt;For example, the dictionary can be loaded into a &lt;code&gt;Set&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stone&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;game&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then validation becomes very fast:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isValidWord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dictionary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a real game, the dictionary is obviously much larger.&lt;/p&gt;

&lt;p&gt;One of the interesting engineering challenges is therefore not simply "finding words", but deciding how much dictionary data should be loaded into the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Client-Side vs Server-Side Validation
&lt;/h2&gt;

&lt;p&gt;For a casual browser word game, client-side validation can be extremely fast.&lt;/p&gt;

&lt;p&gt;The flow can be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Player
  ↓
Select tiles
  ↓
Build word
  ↓
Check dictionary
  ↓
Calculate score
  ↓
Update UI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This avoids sending a network request every time the player submits a word.&lt;/p&gt;

&lt;p&gt;For a competitive game, however, there is another consideration.&lt;/p&gt;

&lt;p&gt;If the client is responsible for everything, a technically sophisticated player can potentially manipulate the game state.&lt;/p&gt;

&lt;p&gt;For a casual game this may be acceptable.&lt;/p&gt;

&lt;p&gt;For competitive scoring or leaderboards, important results should be verified on a server.&lt;/p&gt;

&lt;p&gt;That leads to a useful distinction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Local gameplay
    ↓
Fast client-side validation

Competitive result
    ↓
Server-side verification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This architecture also makes it easier to introduce daily challenges or leaderboards later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating Interesting Boards
&lt;/h2&gt;

&lt;p&gt;Random letters do not necessarily produce an interesting Boggle board.&lt;/p&gt;

&lt;p&gt;A completely random board can generate too many impossible combinations or produce boards with very few playable words.&lt;/p&gt;

&lt;p&gt;A better approach is to treat board generation as a constrained problem.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Random letters
      ↓
Generate candidate board
      ↓
Evaluate board
      ↓
Check word count
      ↓
Check difficulty
      ↓
Accept / regenerate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The board generator can evaluate a candidate board using a dictionary and estimate how many valid words are available.&lt;/p&gt;

&lt;p&gt;This creates an interesting separation between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Board generation&lt;/li&gt;
&lt;li&gt;Word discovery&lt;/li&gt;
&lt;li&gt;Difficulty evaluation&lt;/li&gt;
&lt;li&gt;Gameplay&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A deterministic seed can also be useful.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;generateBoard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the same seed produces the same board, a daily puzzle can be reproduced consistently.&lt;/p&gt;

&lt;p&gt;This is useful for a daily challenge system because every player can receive the same puzzle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Designing a Daily Challenge
&lt;/h2&gt;

&lt;p&gt;A daily puzzle introduces another interesting engineering problem.&lt;/p&gt;

&lt;p&gt;The simplest model is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;date
  ↓
deterministic seed
  ↓
board generator
  ↓
daily board
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;seed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createDailySeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2026-09-26&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generateBoard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server does not necessarily need to store every generated board if the generation algorithm is deterministic.&lt;/p&gt;

&lt;p&gt;Instead, the date can act as the source of the seed.&lt;/p&gt;

&lt;p&gt;This can significantly simplify the data model.&lt;/p&gt;

&lt;p&gt;The same concept can also be used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;daily Sudoku&lt;/li&gt;
&lt;li&gt;daily Wordle-style games&lt;/li&gt;
&lt;li&gt;daily crossword puzzles&lt;/li&gt;
&lt;li&gt;daily logic puzzles&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Mobile Interaction Is Harder Than Desktop Interaction
&lt;/h2&gt;

&lt;p&gt;A desktop implementation can start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mousedown
mousemove
mouseup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But mobile users interact with their fingers.&lt;/p&gt;

&lt;p&gt;That introduces several issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finger size is much larger than a mouse cursor.&lt;/li&gt;
&lt;li&gt;The finger can obscure the selected tile.&lt;/li&gt;
&lt;li&gt;Touch movement can accidentally trigger page scrolling.&lt;/li&gt;
&lt;li&gt;Rapid movement between tiles needs to feel responsive.&lt;/li&gt;
&lt;li&gt;The selection path needs clear visual feedback.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interaction therefore needs to be designed around touch from the beginning rather than treating mobile as an afterthought.&lt;/p&gt;

&lt;p&gt;A good Boggle interface should make the current path visually obvious.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ T ][ R ][ A ][ P ]
       \   \
        [ E ][ S ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact visual design can vary, but the user should immediately understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;which tiles are selected&lt;/li&gt;
&lt;li&gt;what word is being formed&lt;/li&gt;
&lt;li&gt;where the path started&lt;/li&gt;
&lt;li&gt;what happens when the finger moves&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keeping the Vue Component Manageable
&lt;/h2&gt;

&lt;p&gt;One mistake I wanted to avoid was putting everything inside &lt;code&gt;GameBoard.vue&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A game board can quickly become responsible for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Board rendering
Touch events
Mouse events
Word validation
Scoring
Timer
Animations
Game state
Statistics
API calls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That becomes difficult to maintain.&lt;/p&gt;

&lt;p&gt;Instead, I prefer smaller responsibilities.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GameBoard.vue
    ↓
useGame()
    ↓
useBoard()
    ↓
useWordValidation()
    ↓
useScore()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The components handle presentation while composables handle stateful behavior.&lt;/p&gt;

&lt;p&gt;This is especially useful when the same game logic needs to be reused by different interfaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Astro Handles the Site, Vue Handles the Game
&lt;/h2&gt;

&lt;p&gt;The final architecture can be summarized as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Astro
                      │
          ┌───────────┼───────────┐
          │           │           │
       Content      SEO        Routing
          │                       │
          └───────────┬───────────┘
                      │
                  Vue Island
                      │
              ┌───────┴────────┐
              │                │
          Game Board        Game State
              │                │
        Touch / Mouse       Composables
              │                │
              └───────┬────────┘
                      │
                 Word Engine
                      │
              ┌───────┴────────┐
              │                │
          Dictionary       Board Logic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This architecture keeps the interactive portion focused while allowing the rest of the website to remain lightweight.&lt;/p&gt;

&lt;p&gt;It also leaves room for future features without turning the entire website into a monolithic JavaScript application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned From Building It
&lt;/h2&gt;

&lt;p&gt;The biggest lesson is that a simple word game is actually several different engineering problems combined together.&lt;/p&gt;

&lt;p&gt;The core gameplay requires:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Grid modeling&lt;/li&gt;
&lt;li&gt;Graph traversal&lt;/li&gt;
&lt;li&gt;Path validation&lt;/li&gt;
&lt;li&gt;Dictionary lookup&lt;/li&gt;
&lt;li&gt;Scoring&lt;/li&gt;
&lt;li&gt;State management&lt;/li&gt;
&lt;li&gt;Touch interaction&lt;/li&gt;
&lt;li&gt;Board generation&lt;/li&gt;
&lt;li&gt;Difficulty balancing&lt;/li&gt;
&lt;li&gt;Performance considerations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The technology stack is only part of the problem.&lt;/p&gt;

&lt;p&gt;The more interesting challenge is finding clean boundaries between these systems.&lt;/p&gt;

&lt;p&gt;Astro works well for the website layer because it allows the application to contain static and interactive parts without forcing everything to become a client-side application.&lt;/p&gt;

&lt;p&gt;Vue 3 works well for the game layer because reactive state and composable logic map naturally to gameplay.&lt;/p&gt;

&lt;p&gt;And the Boggle rules themselves provide a surprisingly interesting algorithmic problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Small Game Is a Good Engineering Exercise
&lt;/h2&gt;

&lt;p&gt;One reason I enjoy building browser games is that they force you to think about both software architecture and user experience.&lt;/p&gt;

&lt;p&gt;A Boggle board is small.&lt;/p&gt;

&lt;p&gt;The number of rules is small.&lt;/p&gt;

&lt;p&gt;The interface is small.&lt;/p&gt;

&lt;p&gt;But implementing it well requires thinking about algorithms, state, input devices, performance, accessibility, and product design at the same time.&lt;/p&gt;

&lt;p&gt;That's what makes these projects useful engineering exercises.&lt;/p&gt;

&lt;p&gt;If you'd like to see the result, I've published the browser version as &lt;a href="https://puzzle-boggle.com/" rel="noopener noreferrer"&gt;Puzzle Boggle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The project is still evolving, but building it has been a useful way to explore how Astro and Vue 3 can work together for a small, interactive web application.&lt;/p&gt;

&lt;p&gt;I hope some of these architectural ideas are useful for anyone building a browser game or another interactive application with Astro and Vue.&lt;/p&gt;

</description>
      <category>astro</category>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
