random_board: Create a random (but solvable) Lights Out board

Description Usage Arguments Value See Also Examples

View source: R/board.R

Description

Create a Lights Out board that can be played by the user or solved automatically. Only square boards of size 3x3, 5x5, 7x7, or 9x9 are supported. The initial lights configuration is randomly generated, but always solvable. To create a board with a user-defined configuration, use the new_board function.

Usage

1
random_board(size, classic = TRUE)

Arguments

size

Number of rows and columns for the board

classic

If TRUE, then pressing a light will toggle it and its adjacent neighbours only. If FALSE, then pressing a light will toggle the entire row and column of the pressed light.

Value

A lightsout board object.

See Also

new_board play solve_board

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(10)

# Create a random 5x5 classic board
board <- random_board(5)
board

# Get the solution for the board
solution <- solve_board(board)
solution

# Press the lights according to the solution, the result should be a board
# with all lights switched off
play(board, matrix = solution)

Example output

Lights Out 5x5 board
Game mode: classic 

	0 1 0 0 1
	0 0 0 0 0
	0 1 0 1 1
	1 0 1 0 0
	0 0 0 0 1
	
	1 0 0 1 0
	1 0 1 1 0
	0 0 0 1 1
	1 1 0 0 1
	1 0 0 0 0
	Good job, you won!

lightsout documentation built on May 2, 2019, 1:10 p.m.