Skip to contents

str_piece() generates plaintext piecepack diagrams.

Usage

str_piece(
  df,
  color = NULL,
  reorient = "none",
  annotate = FALSE,
  ...,
  annotation_scale = NULL,
  style = c("Unicode", "Game Bit Mono", "Game Bit Duo"),
  xbreaks = NULL,
  ybreaks = NULL
)

Arguments

df

Data frame containing piece info.

color

How should the text be colorized. If FALSE won't colorize output at all. If "html" will colorize output for html. Otherwise will colorize output for the terminal using ANSI CSI SGR control sequences.

reorient

Determines whether and how we should reorient (the angle) of pieces or symbols:

  1. The default "none" (or FALSE) means don't reorient any pieces/symbols.

  2. "all" (or TRUE) means setting the angle to zero for all pieces (reorienting them all “up”).

  3. "symbols" means just re-orient suit/rank symbols but not the orientation of the piece itself. In particular, in contrast with "all" this preserves the location of the upper-left "corner" of piecepack tile faces.

annotate

If TRUE or "algebraic" annotate the plot with “algrebraic” coordinates, if FALSE or "none" don't annotate, if "cartesian" annotate the plot with “cartesian” coordinates.

...

Mainly ignored except for a couple of undocumented features.

annotation_scale

Multiplicative factor that scales (stretches) any annotation coordinates. By default uses attr(df, "scale_factor") %||% 1.

style

If "Unicode" (default) only use glyphs in Unicode proper. If "Game Bit Duo" use glyphs in Private Use Area of "Game Bit Duo" font. If "Game Bit Mono" use glyphs in Private Use Area of "Game Bit Mono" font.

xbreaks, ybreaks

Subset (of integers) to provide axis labels for if annotate is TRUE. If NULL infer a reasonable choice.

Value

Character vector for text diagram.

See also

cat_piece() for printing to the terminal. See https://github.com/trevorld/game-bit-font for more information about the “Game Bit” family of fonts.

Examples

dfb <- data.frame(piece_side = "board_face", x= 3, y = 3, suit = 3)
dfsw <- data.frame(piece_side = "bit_back",
                   x = c(1:5, 1:5, 4:5),
                   y = rep.int(1:3, c(5L, 5L, 2L)),
                   suit = 6L)
dfsb <- data.frame(piece_side = "bit_back",
                   x = c(1:5, 1:5, 1:2),
                   y = rep.int(5:3, c(5L, 5L, 2L)),
                   suit = 2L)
df <- rbind(dfb, dfsw, dfsb)
df$cfg <- "alquerque"
s <- str_piece(df)
is.character(s)
#> [1] TRUE
cat(s, sep = "\n")
#>             
#>   ●─●─●─●─● 
#>   │╲│╱│╲│╱│ 
#>   ●─●─●─●─● 
#>   │╱│╲│╱│╲│ 
#>   ●─●─┼─○─○ 
#>   │╲│╱│╲│╱│ 
#>   ○─○─○─○─○ 
#>   │╱│╲│╱│╲│ 
#>   ○─○─○─○─○ 
#>             
#>             
#>