piecepackr: Board Game Graphics
piecepackr is an R package designed to
make configurable board game graphics. It can be used with the
ggplot2,
grid,
rayrender,
rayvertex, and
rgl graphics packages to
make board game diagrams, board game animations, and custom Print &
Play
layouts.
By default it is configured to make piecepack game
diagrams, animations, and "Print & Play" layouts but can be configured
to make graphics for other board game systems as well.
Built-in Game Systems
The function game_systems() returns configurations for multiple public
domain game systems:
Checkers
game_systems() returns a checkers1 and checkers2 configuration
which has checkered and lined "boards" with matching checker "bits" in
various sizes and colors.
library("piecepackr")
library("ppdf") # remotes::install_github("piecepackr/ppdf")
stopifnot(packageVersion("ppdf") >= "0.2.0-13")
df_board <- checker_board()
df_w <- checker_bits(suit = "white", x = rep(1:8, 2), y = rep(1:2, each=8))
df_b <- checker_bits(suit = "red", x = rep(1:8, 2), y = rep(7:8, each=8))
df <- rbind(df_board, df_w, df_b)
envir <- game_systems()
pmap_piece(df, envir=envir, default.units="in", trans=op_transform, op_scale=0.5)Dice
game_systems() returns several configurations for dice:
- The
diceconfiguration makes standard 6-sided dice with pips. - The
dominoes_chineseanddominoes_chinese_blackconfigurations have Asian-style pipped dice. - The
dice_d4,dice_numeral,dice_d8,dice_d10,dice_d10_percentile,dice_d12, anddice_d20configurations provide the seven polyhedral dice most commonly used by wargames, roleplaying games, and trading card games. - The
dice_fudgeconfiguration make the six-sided Fudge dice with two plus, two minus, and two blank faces most commonly used in the Fudge and Fate roleplaying games.
library("piecepackr")
envir <- game_systems()
dice <- c("d4", "numeral", "d8", "d10_percentile", "d10", "d12", "d20")
cfg <- paste0("dice_", dice)
grid.piece("die_face", suit = c(1:6, 1), rank = 1:7,
cfg = cfg, envir = envir, x = 1:7, y = 1,
default.units = "in", op_scale = 0.5)Dominoes
game_systems() returns seven different configurations for double-18
dominoes:
dominoesdominoes_blackdominoes_bluedominoes_greendominoes_reddominoes_white(identical todominoes)dominoes_yellow
The dominoes_chinese and dominoes_chinese_black configurations
support Chinese
dominoes.
library("piecepackr")
library("tibble")
colors <- rep(c("black", "red", "green", "blue", "yellow", "white"), 2L)
df <- tibble(piece_side = "tile_face",
suit=1:12, rank=7:18+1,
cfg = paste0("dominoes_", colors),
x=rep(4:1, 3), y=rep(2*3:1, each=4) - 0.5)
envir <- game_systems(round = TRUE)
pmap_piece(df, default.units="in", envir=envir, op_scale=0.5, trans=op_transform)Go
game_systems() returns a go configuration for
Go boards and stones in a
variety of colors and sizes. Here are is an example
diagram for a game of
Multi-player
go plotted
using rgl:
library("ppdf")
library("piecepackr")
stopifnot(packageVersion("ppdf") >= "0.2.0-13")
dfb <- go_board()
dfB <- go_bits(suit = "blue",
x = c(2,2,2, 3,3, 4,4, 5,5, 6,6,6, 7,7, 8),
y = c(11,13,14, 12,15, 13,16, 12,16, 12,13,16, 15,17, 16))
dfR <- go_bits(suit = "red",
x = c(3,3, 4, 5, 6, 7, 8,8, 9),
y = c(2:3, 4, 3, 4, 4, 2:3, 2))
dfY <- go_bits(suit = "yellow",
x = 20 - c(3, 4, 5,5, 7, 8, 9,9,9),
y = 20 - c(3, 2, 2:3, 2, 5, 2:4))
dfG <- go_bits(suit = "green",
x = 20 - rep.int(3:6, times = c(5L, 4L, 3L, 2L)),
y = c(4,5,7,12,13, 6,7, 10,11, 7,9,10, 8,9))
dfK <- go_bits(
suit = "black",
x = rep.int(2:17,
times = c(5L, 5L, 4L, 5L, 2L, 4L, 7L, 5L, 5L, 4L, 5L, 6L, 2L, 6L, 6L, 2L)),
y = c(2:3,8:9,12, 4:5,10,13:14, 5,10,14:15, 6,8,10:11,14, 5,11,
5,7,12,14, 4,7,9,11:13,15, 3:4,11,14,16, 8:9,14:16,
3,6,8,15, 9:11,16,18, 6,8:9,11:12,16, 6:7,
5:6,8,11:12,16, 3,5,12,14,16:17, 3,16)
)
dfW <- go_bits(
suit = "white",
x = rep.int(3:14,
times = c(1L, 1L, 1L, 3L, 3L, 2L, 5L, 3L, 4L, 4L, 2L, 1L)),
y = c(9,9,9, 7:8,10, 8,10:11, 8,10, 8:10,12:13, 10:11,13,
9,11,13:14, 7:8,12:13, 7,10, 11)
)
df <- rbind(dfb, dfB, dfR, dfY, dfG, dfK, dfW)
envir <- game_systems(shading = TRUE, background_color = "burlywood")
pmap_piece(df, envir = envir, default.units = "in")Marbles
game_systems() returns a marbles configuration with spherical
marbles in a variety of colors and sizes along with holed square boards
sized for the 1" diameter marbles.
library("ppdf")
library("piecepackr")
stopifnot(packageVersion("ppdf") >= "0.2.0-13")
set.seed(42)
dfb <- marble_board(suit = "green", nrows = 4L, ncol = 4L, x0 = 1, y0 = 1)
dfm <- marble_bits(
suit = sample.int(6L, 30L, replace = TRUE),
x = c(rep(1:4, 4L), rep(0.5 + rep(1:3, 3L)), rep(2:3, 2L), 2.5),
y = c(rep(1:4, each = 4L), rep(0.5 + rep(1:3, each = 3L)), rep(2:3, each = 2L), 2.5)
)
df <- rbind(dfb, dfm)
envir <- game_systems(round = TRUE, shading = TRUE)
pmap_piece(df, default.units = "in", envir = envir,
trans = marbles_transform, op_scale = 0.5)Piecepack
game_systems() returns three different piecepack
configurations:
piecepackplaying_cards_expansiondual_piecepacks_expansion
Plus a configuration for a subpack aka "mini" piecepack and a
hexpack configuration.
The piecepack configurations also contain common piecepack accessories like piecepack pyramids, piecepack matchsticks, and piecepack saucers.
Playing Cards
game_systems() returns playing_cards, playing_cards_colored, and
playing_cards_tarot (French Tarot) configurations for making diagrams
with various decks of playing cards.
library("piecepackr")
library("tibble")
df <- tibble(piece_side = "card_face",
x=1.25 + 2.5 * 0:3, y=2,
suit=1:4, rank=c(1,6,9,12),
cfg = "playing_cards")
envir <- game_systems("dejavu", round=TRUE)
pmap_piece(df, default.units="in", envir=envir)Other included games and components
- An
alquerqueconfiguration that produces "boards"/"bits" for Alquerque in a variety of colors. chess1andchess2configurations with checkered "boards" and matching chess "bits" (currently "disc" pieces instead of "Staunton" pieces).- A
meeplesconfiguration that produces "meeple" bits in a variety of colors. - A
morrisconfiguration that can produce Three/Six/Seven/Nine/Twelve men's morris "board"/"bits" in a variety of colors. - A
reversiconfiguration that can produce "boards"/"bits" for Reversi in a variety of colors.
Looney Pyramids
Configurations for the proprietary Looney Pyramids aka Icehouse Pieces
game system by Andrew Looney can be found in the companion R package
piecenikr: https://github.com/piecepackr/piecenikr
API Intro
grid.piece() ({grid})
grid.piece() is the core function that can used to draw board game
components (by default piecepack game components) using
grid:
library("piecepackr")
g.p <- function(...) { grid.piece(..., default.units="in") }
g.p("tile_back", x=0.5+c(3,1,3,1), y=0.5+c(3,3,1,1))
g.p("tile_back", x=0.5+3, y=0.5+1)
g.p("tile_back", x=0.5+3, y=0.5+1)
g.p("die_face", suit=3, rank=5, x=1, y=1)
g.p("pawn_face", x=1, y=4, angle=90)
g.p("coin_back", x=3, y=4, angle=180)
g.p("coin_back", suit=4, x=3, y=4, angle=180)
g.p("coin_back", suit=2, x=3, y=1, angle=90)configuration lists
One can use lists to
configure
to quickly adjust the appearance of the game components drawn by
grid.piece:
library("piecepackr")
dark_colorscheme <- list(
suit_color="darkred,black,darkgreen,darkblue,black",
invert_colors.suited=TRUE, border_color="black", border_lex=2
)
piecepack_suits <- list(
suit_text="\U0001f31e\ufe0e,\U0001f31c\ufe0e,\U0001f451\ufe0e,\u269c,\uaa5c", #