Package 'ppgamer'

Title: Players for Piecepack Games like Fuji-san
Description: Functions that provide players for piecepack games like a solver for "Fuji-san".
Authors: Trevor L. Davis [aut, cre] (ORCID: <https://orcid.org/0000-0001-6341-4639>)
Maintainer: Trevor L. Davis <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0-1
Built: 2026-05-17 07:39:53 UTC
Source: https://github.com/piecepackr/ppgamer

Help Index


Solve Dominosa puzzle

Description

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.

See Also

https://www.solitairelaboratory.com/puzzlelaboratory/DominoGG.html and https://puzzlebreaks.com/dominosa/ for more information about Dominosa.

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)
}

Solve Fujisan game

Description

Solves a game of Fujisan (if possible).

Usage

solve_fujisan(
  coins = random_fujisan_coins(),
  dice = random_dice() - 1,
  pawns = "S12M/A12C"
)

Arguments

coins

A vector or matrix of Fujisan coin layout. Default is a random layout.

dice

A vector of Fujisan dice layout. Default is random dice. Usually not needed.

pawns

A FEN-like string of the pawns position. The four pawns S, M, C, and A are represented by their letter and empty spaces by a number. The two rows are separated by /. Default is "S12M/A12C" (all pawns at starting corners).

Value

A list with solution of Fujisan solution, its length, coin layout, dice (if needed), pawn position string, and portable piecepack notation.

Examples

puzzle2 <- matrix(c(4, 4, 4, 5, 2, 0, 2, 4, 0, 3, 1, 1,
                     1, 2, 5, 3, 3, 5, 3, 2, 5, 1, 0, 0), nrow = 2, byrow = TRUE)
 s <- solve_fujisan(coins = puzzle2)
 print(s$shortest_distance) # minimum number of moves to solve game