Wolfram Research

Function Repository Resource:

LightsOutGame

Source Notebook

Start a Lights Out game

Contributed by: Aster Ctor

ResourceFunction["LightsOutGame"][n]

starts an n by n game of Lights Out.

ResourceFunction["LightsOutGame"][n,m]

starts an m by n game.

Details and Options

White indicates a lit light; black indicates a light that is extinguished.
Turn off all the lights to win.
The algorithm avoids the generation of games with no solution.
The solution of higher-rank games can be extremely complicated, but the algorithm guarantees at least one solution.

Examples

Basic Examples (1) 

Start a game with 2 rows and 2 columns:

In[1]:=
ResourceFunction["LightsOutGame"][2]
Out[1]=

Scope (1) 

Start a game with 2 rows and 3 columns:

In[2]:=
ResourceFunction["LightsOutGame"][2, 3]
Out[2]=

Options (2) 

Mode (2) 

The game has two modes; normal mode is initially all white:

In[3]:=
ResourceFunction["LightsOutGame"][3, Mode -> Normal]
Out[3]=

The random mode's start result is random:

In[4]:=
ResourceFunction["LightsOutGame"][3, 3, Mode -> Random]
Out[4]=

Resource History

Related Resources

License Information