Sliding puzzle in R

Share:

Description

Use R to play sliding puzzle (currently only the Windows screen display).

Usage

1
sliding_puzzle(size = c(3, 3), bg = "lightblue", z = NULL)

Arguments

size

two dimensional vector, the size of sliding puzzle. Note: the element of size must be greater than 1.

bg

the background color of blocks.

z

the matrix of sliding puzzle, if z is specified, size will be omited.

Details

If size is specified and z is NULL, then the function will generate a solvable sliding puzzle. In addition, the function only works under the Windows screen display because of the limitation of function getGraphicsEvent.

Note

Linux/Mac users have to use X11(type = 'Xlib') or the Cairo graphics device Cairo() in the package cairoDevice.

Author(s)

Taiyun Wei

References

About the sliding puzzle: http://en.wikipedia.org/wiki/Sliding_puzzle

How to Solve a Slider Puzzle: http://www.justadventure.com/articles/Slider/Slider.shtm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## should use Xlib for the x11() device under *nix, e.g
## Not run: 
if (.Platform$OS.type == "windows") 
    x11() else x11(type = "Xlib")

## End(Not run)

sliding_puzzle()

sliding_puzzle(z = matrix(0:11, 3, 4))