Skip to contents

Solves a Dominosa (Domino Solitaire) puzzle given a grid of pip values.

Usage

solve_dominosa(pips)

Arguments

pips

A matrix of non-negative integer pip values, or a string with rows of integers separated by "/". For a double-n domino set the grid must have (n + 1)(n + 2) cells and each pip value 0:n must appear exactly n + 2 times.

Value

A list with components:

domino_ids

An integer matrix of the same dimensions as pips where cells belonging to the same domino share the same integer value.

pips

The input pips matrix.

ppn

A string of Portable Piecepack Notation for the solution.

Examples

pips <- matrix(c(0, 1, 0, 1, 3,
                 3, 1, 0, 2, 2,
                 3, 2, 1, 0, 3,
                 2, 3, 1, 0, 2), nrow = 4L, byrow = TRUE)
s <- solve_dominosa(pips)
if (rlang::is_installed(c("piecepackr", "ppn"))) {
  g <- ppn::read_ppn(textConnection(s$ppn))[[1]]
  envir <- piecepackr::game_systems(round = TRUE)
  ppn::plot_move(g, open_device = FALSE, annotate = FALSE, envir = envir, scale = 0.95)
}