| Title: | Portable Piecepack Notation Parser |
|---|---|
| Description: | Parse "Portable Piecepack Notation" files. This allows you to visualize the moves for over one hundred board games. |
| 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.3.0-2 |
| Built: | 2026-05-31 07:02:46 UTC |
| Source: | https://github.com/piecepackr/ppn |
Animate a ppn game
animate_game( game, file = "animation.gif", annotate = TRUE, ..., .f = piecepackr::grid.piece, cfg = NULL, envir = NULL, n_transitions = 0L, n_pauses = 1L, fps = n_transitions + n_pauses, width = NULL, height = NULL, ppi = NULL, annotation_scale = NULL )animate_game( game, file = "animation.gif", annotate = TRUE, ..., .f = piecepackr::grid.piece, cfg = NULL, envir = NULL, n_transitions = 0L, n_pauses = 1L, fps = n_transitions + n_pauses, width = NULL, height = NULL, ppi = NULL, annotation_scale = NULL )
game |
A list containing a parsed ppn game (as parsed by |
file |
Filename to save animation unless |
annotate |
If |
... |
Passed to |
.f |
Low level graphics function to use e.g. |
cfg |
A piecepackr configuration list |
envir |
Environment (or named list) of piecepackr configuration lists |
n_transitions |
Integer, if over zero (the default) how many transition frames to add between moves. |
n_pauses |
Integer, how many paused frames per completed move. |
fps |
Double, frames per second. |
width |
Width of animation (in inches). Inferred by default. |
height |
Height of animation (in inches). Inferred by default. |
ppi |
Resolution of animation in pixels per inch. By default set so image max 600 pixels wide or tall. |
annotation_scale |
Multiplicative factor that scales (stretches) any annotation coordinates.
By default uses |
Nothing, as a side effect saves an animation of ppn game
game_file <- system.file("ppn/tic-tac-toe.ppn", package = "ppn") game <- read_ppn(game_file)[[1]] if (require("gifski")) { animate_game(game, file = "tic-tac-toe.gif") unlink("tic-tac-toe.gif") }game_file <- system.file("ppn/tic-tac-toe.ppn", package = "ppn") game <- read_ppn(game_file)[[1]] if (require("gifski")) { animate_game(game, file = "tic-tac-toe.gif") unlink("tic-tac-toe.gif") }
cat_move() prints a plaintext diagram of a single move to the terminal.
cat_game() prints a plaintext "animation" of every move to the terminal.
cat_move(game, move = NULL, ...) cat_game(game, ..., fps = 1)cat_move(game, move = NULL, ...) cat_game(game, ..., fps = 1)
game |
A list containing a parsed ppn game (as parsed by |
move |
Which move to cat game state (after the move, will use |
... |
Passed to |
fps |
Frames per second. |
default_parser() is the default PPN movetext parser.
default_parser( movetext = character(), metadata = list(), ..., scale_factor = NULL, default_system = "piecepack" ) piecepack_parser( movetext = character(), metadata = list(), ..., scale_factor = NULL, default_system = "piecepack" ) alquerque_parser(movetext = character(), metadata = list(), ...) checker_parser(movetext = character(), metadata = list(), ..., cell_width = 2) chess_parser(movetext = character(), metadata = list(), ..., cell_width = 2) domino_parser(movetext = character(), metadata = list(), ...) go_parser(movetext = character(), metadata = list(), ...) marble_parser(movetext = character(), metadata = list(), ...) morris_parser(movetext = character(), metadata = list(), ...) tarot_parser(movetext = character(), metadata = list(), ...)default_parser( movetext = character(), metadata = list(), ..., scale_factor = NULL, default_system = "piecepack" ) piecepack_parser( movetext = character(), metadata = list(), ..., scale_factor = NULL, default_system = "piecepack" ) alquerque_parser(movetext = character(), metadata = list(), ...) checker_parser(movetext = character(), metadata = list(), ..., cell_width = 2) chess_parser(movetext = character(), metadata = list(), ..., cell_width = 2) domino_parser(movetext = character(), metadata = list(), ...) go_parser(movetext = character(), metadata = list(), ...) marble_parser(movetext = character(), metadata = list(), ...) morris_parser(movetext = character(), metadata = list(), ...) tarot_parser(movetext = character(), metadata = list(), ...)
movetext |
A named character vector of move text. |
metadata |
A named list of metadata |
... |
Should be empty for |
scale_factor |
How many inches a coordinate unit is worth. |
default_system |
Default game system to use for setup functions. |
cell_width |
Width of checker/chess board cell. Either |
A named list of data frames with parsed game states.
l <- read_ppn(system.file("ppn/relativity.ppn", package = "ppn"), parse = FALSE)[[1]] game <- default_parser(l$movetext, l$metadata)l <- read_ppn(system.file("ppn/relativity.ppn", package = "ppn"), parse = FALSE)[[1]] game <- default_parser(l$movetext, l$metadata)
Plot game move
plot_move( game, file = NULL, move = NULL, annotate = TRUE, ..., .f = piecepackr::grid.piece, cfg = NULL, envir = NULL, width = NULL, height = NULL, ppi = 72, bg = "white", annotation_scale = NULL )plot_move( game, file = NULL, move = NULL, annotate = TRUE, ..., .f = piecepackr::grid.piece, cfg = NULL, envir = NULL, width = NULL, height = NULL, ppi = 72, bg = "white", annotation_scale = NULL )
game |
A list containing a parsed ppn game (as parsed by |
file |
Filename to save animation unless |
move |
Which move to plot game state (after the move, will use |
annotate |
If |
... |
Passed to |
.f |
Low level graphics function to use e.g. |
cfg |
A piecepackr configuration list |
envir |
Environment (or named list) of piecepackr configuration lists |
width |
Width of animation (in inches). Inferred by default. |
height |
Height of animation (in inches). Inferred by default. |
ppi |
Resolution of animation in pixels per inch. By default set so image max 600 pixels wide or tall. |
bg |
Background color ( |
annotation_scale |
Multiplicative factor that scales (stretches) any annotation coordinates.
By default uses |
An invisible list of the dimensions of the image, as a side effect saves a graphic
Read/write Portable Piecepack Notation (PPN) files
read_ppn(file, parse = TRUE) write_ppn(games = list(), file = "")read_ppn(file, parse = TRUE) write_ppn(games = list(), file = "")
file |
Filename, if "" will use |
parse |
Logical of whether to parse the moves in the ppn file |
games |
A list of parsed PPN games (as returned by |
A list, for each game in the file a list containing info about the game
plot_move(), animate_game(), and cat_move() for visualizing parsed ppn games.
list.files(system.file("ppn", package = "ppn")) file <- system.file("ppn/tic-tac-toe.ppn", package = "ppn") games <- read_ppn(file) tmp <- tempfile(fileext = ".ppn") write_ppn(games, tmp) unlink(tmp)list.files(system.file("ppn", package = "ppn")) file <- system.file("ppn/tic-tac-toe.ppn", package = "ppn") games <- read_ppn(file) tmp <- tempfile(fileext = ".ppn") write_ppn(games, tmp) unlink(tmp)
Launch PPN game viewer/editor
view_game( game, shiny = FALSE, ..., editor = getOption("editor"), reorient = "none", annotate = FALSE, fps = 1 )view_game( game, shiny = FALSE, ..., editor = getOption("editor"), reorient = "none", annotate = FALSE, fps = 1 )
game |
A list containing a parsed ppn game (as parsed by |
shiny |
If |
... |
Passed to |
editor |
usually a character string naming (or giving the path to) the text editor you want to use. |
reorient |
Determines whether and how we should reorient (the angle) of pieces or symbols:
|
annotate |
If |
fps |
Frames per second. Passed to |