The Game and Comments

We present here a very challenging game which is a variation and extension of the classic "Lights Out" puzzle. The goal of the game is to click on the lights until you can get them all to be green. Clicking on a light will change its color, but also the color of all of the neighbor lights attached to it. The light colors cycle through green, yellow, and red, just like a traffic light. The puzzles are made from a grid of lights (of varying sizes depending on the settings) which are connected in randomized configurations.

Click the screen shot below or this link to open the puzzle in a new window:

An Android version of Traffic Lights game is coming very soon!

Download the Complete AS3 Code

The following zip package contains complete code and the custom AS3 classes behind the puzzle:

About the Code

The lights connected together by lines represent the mathematical notion of a "graph." In mathematical language, the lights represent "nodes," while the lines connecting them are "edges." One of the challenges in writing our code was to create an algorithm which would build a randomized graph in such a way as to guaranteee the result would be one connected whole. Our solution is to use the well-known Kruskal's algorithm to form a "spanning tree." A spanning tree is essentially a connected graph with no loops. After the spanning tree is created, we add some more edges to create a more interesting graph.

The graph structure which determines a puzzle is an abstract concept, and to create each graph we make use of a custom built Graph class. This class could be reused for any situation where one would like to build a graph, which is likely to come up in the creation of other puzzles. The class contains methods for adding nodes to the graph and connecting nodes with edges. There is also a method for creating a graph which is a complete rectangular lattice, plus a method for creating a spanning tree for a given connected graph.

Enjoy the puzzle!

Our Other Games and Puzzles

The first three of the puzzles below are available in the browser form as well as Android apps. The fourth will be posted on the Android Market soon.

Back to Advanced Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.