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] |
Maintainer: | Trevor L Davis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0-2 |
Built: | 2024-11-03 05:07:17 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, new_device = TRUE, 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, new_device = TRUE, annotation_scale = NULL )
game |
A list containing a parsed ppn game (as parsed by |
file |
Filename to save animation unless |
annotate |
If |
... |
Arguments 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. |
new_device |
If |
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. |
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", new_device = TRUE, 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", new_device = TRUE, 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 ( |
new_device |
If |
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 |