A grid-based puzzle game where players must connect all tiles to a central power station
by rotating wire segments to complete a circuit. The board is generated using
Kruskal's algorithm to create a minimum spanning tree, guaranteeing
a solvable puzzle with a unique solution path. Power flows outward from the station
using breadth-first search, illuminating connected tiles. The player
wins when every tile on board is lit up and receiving power.
play the game
Difficulty:
Size:
Moves:0Time:0:00
Click to rotate · Click to rotate · ↑↓←→ or WASD to move power station ·
R toggle radius · H toggle hex
how to play
goal: Connect all tiles to the power station, by rotating the wire
by clicking on it and lighting up every cell. The Star is the power source from which
each tile must receive power through connected wires.
click: Rotate any tile 90° clockwise. Each rotation counts as
one move. Like chess, you plan ahead to minimize your move count.
arrow keys / WASD: Move the power station along connected wires
to a neighboring tile. This also counts as a move but can help reach distant sections.
R key: Toggle the power radius effect. When enabled, power
extends a limited distance from the source, adding even more strategic depth.
H key: Toggle hexagonal grid mode. This adds diagonal connections
(8 directions instead of 4), creating more complex and harder puzzles. I myself
have not completed the hex 8x8 on hard yet.
visuals
Initially, the game renders a dark grid where each cell displays wire segments extending in
cardinal directions. Powered wires glow yellow while unpowered wires remain gray.
The UI panel shows elapsed time, move count, current radius, and difficulty level.
powered tiles: The tiles turning yellow indicate successful connection to
the Star, watch the electricity flow as you solve the puzzle.
power station: A cyan Star with an orange outline marks your
power source. It starts at (0,0) but can be moved along connected paths with the arrow keys.
difficulty colors: Easy, Medium, and Hard buttons in the UI
regenerate the board with increasingly complex wire patterns.
game mechanics
wire connections: Each tile stores boolean flags for up to 8
directions (4 cardinal + 4 diagonal in hex mode) and rotation cycles these flags
clockwise.
connection validation: Two tiles are connected only if both have
wires pointing toward each other, a tile with right=true connects
to a neighbor with left=true.
power radius: When turned on, power diminishes over distance. The
initial radius is calculated as half the graph's diameter + 1, found via two BFS
passes to locate the furthest endpoints.
difficulty scaling: Edge weights in Kruskal's algorithm vary by
difficulty. Easy uses weights 0-50, Medium 0-100, Hard 50-200. Higher variance
creates more irregular, challenging mazes.
Built in Java using Northeastern's impworld game library,
which provides a World class with onTick, onMouseClicked,
and onKeyEvent hooks. The rendering uses javalib.worldimages
for compositing rectangles, stars, and overlays into each frame.
maze generation: Kruskal's algorithm builds the minimum spanning
tree. All possible edges are created with random weights, sorted, then processed.
Union-Find tracks connected components, an edge is added only if it connects two
previously separate components.
union-find with path compression: The find() operation
recursively locates the root representative and flattens the binary tree by pointing all
nodes directly to the root which makes it really fast, on average.
power propagation: BFS from the power station explores all connected
neighbors, tracking distance. Tiles within the radius threshold are marked as powered,
running after every rotation or station move.
hexagonal mode: Diagonal connections add 4 additional directions
per tile. The rotation logic cycles through 8 positions instead of 4, and edge
generation includes diagonal neighbors.
architecture
GamePiece→Edge→UnionFind→LightEmAll
GamePiece represents a single tile with position, connection flags,
and power state. It handles rotation and connection checking. Edge
stores weighted connections between two pieces for Kruskal's algorithm.
UnionFind manages disjoint sets with path compression for efficient
MST construction. LightEmAll extends World and orchestrates
the game loop, rendering, and event handling.
The game state includes a 2D ArrayList board, a flat nodes list
for iteration, the MST edge list, power station coordinates, and UI state (moves, time,
difficulty, animation frames). The makeScene() method composites all tiles
and UI elements into a single WorldScene each frame.
key algorithms
kruskal's MST: Guarantees a connected, acyclic graph (tree) with
minimum total edge weight. Since all tiles must be reachable, this ensures exactly
one solution path exists. Time complexity is O(E log E) for sorting & O(E α(V)) for
union-find operations.
BFS for power flow: Explores tiles level-by-level from the power
station. Each tile's distance from the source determines if it's within the power
radius. Time complexity is O(V + E) where V is tiles and E is connections.
diameter calculation: Two BFS passes find the graph's diameter.
First BFS from any node finds the furthest node A. Second BFS from A finds the
furthest node B. Distance A→B is the diameter, used to set initial power radius.
Source? This project was built as part of Northeastern's Fundamentals
of Computer Science II course (CS 2510). The implementation demonstrates graph algorithms,
data structure design, and event-driven game programming in Java.