Learn R Programming

⚠️There's a newer version (1.14.1) of this package.Take me there.

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("tibble")
df_board <- tibble(piece_side = "board_face", suit = 3, rank = 8,
               x = 4.5, y = 4.5)
df_w <- tibble(piece_side = "bit_face", suit = 6, rank = 1,
               x = rep(1:8, 2), y = rep(1:2, each=8))
df_b <- tibble(piece_side = "bit_face", suit = 1, rank = 1,
               x = rep(1:8, 2), y = rep(7:8, each=8))
df <- rbind(df_board, df_w, df_b)
df$cfg <- "checkers1"
pmap_piece(df, envir=game_systems(), default.units="in", 
           trans=op_transform, op_scale=0.5)

Dice

game_systems() returns several configurations for dice:

  • The dice configuration makes standard 6-sided dice with pips.
  • The dominoes_chinese and dominoes_chinese_black configurations have Asian-style pipped dice.
  • The dice_d4, dice_numeral, dice_d8, dice_d10, dice_d10_percentile, dice_d12, and dice_d20 configurations provide the seven polyhedral dice most commonly used by wargames, roleplaying games, and trading card games.
  • The dice_fudge configuration 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:

  1. dominoes
  2. dominoes_black
  3. dominoes_blue
  4. dominoes_green
  5. dominoes_red
  6. dominoes_white (identical to dominoes)
  7. dominoes_yellow

The dominoes_chinese and dominoes_chinese_black configurations support Chinese dominoes.

library("piecepackr")
library("tibble")
envir <- game_systems("dejavu")

colors <- rep(c("black", "red", "green", "blue", "yellow", "white"), 2)
df_dominoes <- 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))
df_tiles <- tibble(piece_side = "tile_back", suit=1:3, rank=1:3, 
                   cfg="piecepack", x=5.5, y=c(2,4,6))
df_dice <- tibble(piece_side = "die_face", suit=1:6, rank=1:6, 
                  cfg="dice", x=6, y=0.5+1:6)
df_coins1 <- tibble(piece_side = "coin_back", suit=1:4, rank=1:4, 
                    cfg="piecepack", x=5, y=0.5+1:4)
df_coins2 <- tibble(piece_side = "coin_face", suit=1:2, rank=1:2,
                    cfg="piecepack", x=5, y=0.5+5:6)
df <- rbind(df_dominoes, df_tiles, df_dice, df_coins1, df_coins2)

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:

Piecepack

game_systems() returns three different piecepack configurations:

  1. piecepack
  2. playing_cards_expansion
  3. dual_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")
envir <- game_systems("dejavu", round=TRUE)

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")
pmap_piece(df, default.units="in", envir=envir)

Other included games and components

  • An alquerque configuration that produces "boards"/"bits" for Alquerque in a variety of colors.
  • chess1 and chess2 configurations with checkered "boards" and matching chess "bits" (currently "disc" pieces instead of "Staunton" pieces).
  • A meeples configuration that produces "meeple" bits in a variety of colors.
  • A morris configuration that can produce Three/Six/Seven/Nine/Twelve men's morris "board"/"bits" in a variety of colors.
  • A reversi configuration 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,\U0001f31c,\U0001f451,\u269c,\uaa5c", # 

Copy Link

Version

Install

install.packages('piecepackr')

Monthly Downloads

653

Version

1.13.8

License

MIT + file LICENSE

Maintainer

Trevor L Davis

Last Published

January 12th, 2025

Functions in piecepackr (1.13.8)

save_piece_obj

Save Wavefront OBJ files of board game pieces
render_piece

Render image of game pieces
piece3d

Render board game pieces with rgl
piece_mesh

Create rayvertex board game piece objects
save_piece_images

Save piecepack images
scale_x_piece

ggplot2 game diagram scales
spdx_license_list

SPDX License List data
save_print_and_play

Save piecepack print-and-play (PnP) file
grid.cropmark

Crop Mark Grob
grid.piece

Draw board game pieces with grid
aabb_piece

Calculate axis-aligned bounding box for set of game pieces
game_systems

Standard game systems
basicPieceGrobs

Piece Grob Functions
font_utils

Font utility functions
save_ellipsoid_obj

Alternative Wavefront OBJ file generators
AA_to_R

Helper functions for making geometric calculations.
geom_piece

Draw board game pieces with ggplot2
animate_piece

Animate board game pieces
pp_shape

Shape object for generating various grobs
pmap_piece

Create graphics using data frame input
pp_cfg

Configuration list R6 object
op_transform

Oblique projection helper function
piece

Create rayrender board game piece objects
pp_utils

Miscellaneous piecepackr utility functions
piecepackr-defunct

Defunct functions
piecepackr-package

piecepackr: Board Game Graphics