ALGORITHM & GRAPH THEORY

Beneath the colorful visual presentation of ArrowsGame lies a rigorous mathematical structure based on Directed Acyclic Graphs (DAG), In-Degree dependency counts, and Topological Sorting algorithms.

The Mathematics of Arrow Puzzles: Graph Theory & DAG Design

Every solvable arrow puzzle board is a physical manifestation of a Directed Acyclic Graph (DAG). Here is how computer scientists and puzzle designers use graph theory to guarantee 100% solvable puzzle boards without brute force guessing.

Representing Board Obstacles as Directed Acyclic Graphs

1. Nodes & Directed Edges

Each arrow on a 60×60 grid represents a node \(V_i\). A directed edge \(E_{i \to j}\) exists if Arrow \(i\) lies along the straight exit path of Arrow \(j\), creating a dependency where \(j\) cannot exit until \(i\) is removed.

2. Acyclic Property (Zero Deadlocks)

A graph is acyclic if there are no directed cycles (\(V_1 \to V_2 \to V_3 \to V_1\)). In arrow puzzles, an acyclic graph guarantees that at least one arrow has zero incoming blocking dependencies at any stage.

3. Topological Ordering

A topological sort of a DAG produces a linear ordering of vertices such that for every directed edge \(u \to v\), vertex \(u\) comes before \(v\). This ordering represents the exact optimal move sequence to clear the board.

In-Degree, Out-Degree, and Topological Sorting Algorithms

During gameplay, an arrow is playable on turn 1 if and only if its In-Degree is 0 (no other non-removed arrows intersect its exit vector). When the player taps an arrow with In-Degree 0, its node is removed from the graph, decrementing the In-Degree of all downstream dependent nodes. This chain reaction forms the core gameplay loop of ArrowsGame.

Reverse-Growth Level Generation vs Solvability Verification

Procedural level generation in generateLevel(w, h, count, rng) works in reverse:

  1. Step 1: Place exit arrowheads along the outer border of the grid, pointing outwards (guaranteeing In-Degree = 0).
  2. Step 2: Grow winding paths backwards into the grid interior from tail to head, ensuring newly placed paths intersect previous paths in controlled directions.
  3. Step 3: By building from the outside-in backwards, the resulting graph is mathematically guaranteed to be a valid DAG with 100% solvability.

Frequently Asked Questions

What is a Directed Acyclic Graph (DAG) in arrow puzzle design?

A Directed Acyclic Graph (DAG) represents arrow dependencies where directed edges point from blocking arrows to blocked arrows. Being acyclic guarantees that no circular deadlock cycles exist.

How does Topological Sorting solve an Arrow Puzzle?

Topological sorting orders arrows such that every arrow is removed before any arrows that depend on it, providing a step-by-step mathematical proof of solvability.