play | R Documentation |
In classic mode, pressing a light will toggle it and its four adjacent lights. In variant mode, pressing a light will toggle it and all other lights in its row and column. Toggling a light means switching it from on to off or from off to on.
play(board, row, col, matrix)
board |
A |
row |
The row of the light to press. To press multiple lights, use a list
of row numbers. If a list is provided, then the |
col |
The column of the light to press. To press multiple lights, use a list
of column numbers. If a list is provided, then the |
matrix |
Instead of using |
A new lightsout
board object after the given lights are pressed.
solve_board
empty_board
new_board
random_board
# Create a 5x5 board with all lights switched off and then press some lights
board <- empty_board(5)
board
# Press the light at (2,1)
newboard <- play(board, 2, 1)
newboard
# Press the light at (2,1) and then at (3,4)
newboard <- board %>% play(2, 1) %>% play(3, 4)
newboard
# Press both lights with one call
newboard <- play(board, c(2, 3), c(1, 4))
newboard
# Press both lights using a matrix instead of specifying rows and columns
newboard <- play(board, matrix = matrix(
c(0, 0, 0, 0, 0,
1, 0, 0, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0),
nrow = 5, byrow = TRUE))
newboard
# Press the same lights, but this time when the game mode is not classic,
# and the whole row/column get toggled
empty_board(5, classic = FALSE) %>% play(2, 1)
empty_board(5, classic = FALSE) %>% play(c(2, 3), c(1, 4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.