new_board: Initialize a Lights Out board with a given lights...

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 must be provided. To create a board with a random configuration, use the random_board function.

Usage

1
new_board(entries, classic = TRUE)

Arguments

entries

The initial configuration of lights on the board. entries can either be a vector or a matrix. If a vector is used, the vector is assumed to start at the top-left corner of the board and is read row-by-row. Only values of 0 (light off) and 1 (light on) are allowed in the vector or matrix. See the examples below.

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

random_board play solve_board

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
vector <- c(1, 1, 0,
            1, 0, 1,
            0, 1, 1)
new_board(entries = vector)

matrix <- matrix(
            c(1, 1, 0,
              1, 0, 1,
              0, 1, 1),
            nrow = 3, byrow = TRUE)
new_board(entries = matrix)

Example output

Lights Out 3x3 board
Game mode: classic 

	1 1 0
	1 0 1
	0 1 1
	Lights Out 3x3 board
Game mode: classic 

	sh: 1: rm: Permission denied
1 1 0
	1 0 1
	0 1 1
	

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