Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Lights Out

An interactive Python implementation of the classic Lights Out puzzle, extended with multiple algebraic state spaces and nontrivial topological grids.


Overview

This project implements a fully playable version of Lights Out with several enhancements:

  • Variable grid sizes from 2×2 up to 15×15
  • Multiple state spaces over Z_p for p in {2,3,5,7}
  • Support for nontrivial topologies:
    • Simple grid
    • Cylinder
    • Möbius strip
    • Torus
    • Klein bottle
    • Projective plane
  • Built-in solver using linear algebra over finite fields
  • Graphical user interface with topology visualization

Each game is initialized in a way that guarantees it is solvable.


How It Works

Each board configuration is modeled as a vector over Z_p, and button presses correspond to adding columns of an adjacency matrix A.

To solve the puzzle, we seek a press vector x that sends the current board state b back to the zero state. This means solving the linear system

A x ≡ -b (mod p)

where:

  • b is the current board state
  • x is the solution vector of button presses

A reduced form of the adjacency matrix is computed along with a solver matrix A⁺, allowing solutions to be generated efficiently during gameplay.

If the system has nontrivial nullity, multiple solutions may exist; the program returns one valid solution.


Features

  • Topology-aware neighbor structure
    Button interactions depend on the selected surface, including wraparound and twist identifications on spaces such as the torus, Möbius strip, Klein bottle, and projective plane.

  • Guaranteed solvability
    Initial states are generated from valid press vectors, ensuring that every puzzle can be completed.

  • Hint system
    Generates a valid sequence of button presses to solve the current board.

  • Dynamic UI

    • Adjustable board size and state space
    • Visual preview of each topology
    • Responsive grid layout

Requirements

  • Python 3.x
  • numpy
  • Pillow

Install dependencies with:

pip install numpy pillow

Running the Program

From the project directory:

python Lights_Out.py

Notes

  • The appearance of the application icon may vary depending on the operating system and desktop environment.
  • Image paths are resolved relative to the script location for portability.

About

Generalized Lights Out implementation with modular arithmetic (Z₂, Z₃, Z₅, Z₇), multiple board topologies, and linear-algebra-based solver.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages