Example Code

Lights Out 2014 Game

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview

Lights out 2014 is a software version of the classic LightsOut (and LightsOut 2000) game. The aim of this addictive game is to reduce the 5x5 matrix of lights such that no lights are on.

 

Description

Pressing a lit light toggles it to the off position but also toggles its 4 neighbouring lights. The image below best describes the game:

Game.PNG

Image taken from http://people.math.sfu.ca/~jtmulhol/math302/notes/24-Lights-Out.pdf

The matrix is generated from patterns that are stored in the "Levels.txt" file - there is code supplied that also allows you to generate your own levels. If you use this code, please check what level you're currently at (by looking in the levels.txt file) and counting the rows. Then add one to this value and that goes in the level control on the front panel.

It uses the Queued Message Handler architecture so that it's modular and expandable I'm currently working on the code for solving the matrix mathematically. This can be done by using Gaussian elemination (in mod 2) and solving the linear equation Ax = b where 'A' is a 25x25 matrix of how each light interacts with the whole matrix, 'x' is the "toggle matrix" indicating which lights need to be toggled to complete the game and 'b' is the "inital configuration matrix". I would also like to add in more states for the lights to increase the difficulty - hence why I use an array of colour box constants instead of Boolean switches.

I've used the "Determine Clicked Array Element Index in LabVIEW" SubVI from here - https://decibel.ni.com/content/docs/DOC-22434 to determine the clicked cell.

 

Requirement 

  1. LabVIEW 2014 (or compatible)

 

Steps to Implement or Execute Code

  1. Download the zipped file and extract it to your computer
  2. Open the LabVIEW project "Lights Out 2014 NIVerified".
  3. Open the "LightsOut2014.vi" and press "run"
  4. Press play and solve the puzzle!

NOTE: The "Reset Levels" resets your level back to 1.

 

Additional Information or References

Block Diagram

251bg.JPG

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

You should include the entire distribution of the Determine Clicked Array Element Index.  You failed to include the subVIs in your zip file.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
msimmonds
NI Employee (retired)
on

Hi crossrulz, thanks for pointing that out, I've uploaded the new revision, all should be fine now!

evaelfie
Member
Member
on

The whole distribution of the Determine Clicked Array Element Index should be used. The subVIs were missing from your zip file. The whole distribution of the Determine Clicked Array Element Index should be used. The subVIs were missing from your zip file.