chess_board() returns a square checkered board of desired size and type.
chess_bits() returns chess pieces.
Usage
chess_board(
nrows = 8L,
ncols = nrows,
x0 = 1,
y0 = 1,
...,
side = "face",
piece_side = paste0("board_", side),
suit = "green",
angle = 0,
cell_width = getOption("ppdf.chess_cell_width", 1)
)
chess_bits(
...,
suit = rep(1:6, each = 6L),
rank = rep(1:6, 6L),
x = rep(1:6, 6L),
y = rep(1:6, each = 6L),
angle = 0,
cell_width = getOption("ppdf.chess_cell_width", 1),
length.out = NA_integer_
)Arguments
- nrows
Number of rows in game board
- ncols
Number of columns in game board
- x0
X coordinate for the center of the first cell
- y0
Y coordinate for the center of the first cell
- ...
Should be left empty.
- side
Either "face" or "back"
- piece_side
If
"board_face"a checkered board (as in American Checkers). If"board_back"a lined board (as in Turkish Checkers).- suit
Suit value (color) of board and pieces.
1Lis "red",2Lis "black",3Lis "green",4Lis "blue",5Lis "yellow", and6Lis "white". Will be coerced bypiece_suit().- angle
Rotation of bit/board (numeric vector of degrees, counter-clockwise). Will be coerced by
piece_angle().- cell_width
Width of board cell.
piecepackr::game_systems()supports1or2.- rank
Rank value of chess pieces from
1L(pawn) to6L(king). Will be coerced bychess_rank().- x, y
Cartesian coordinates (numeric vectors)
- length.out
The number of pieces. Not needed if all the arguments are the same length (or of length one) and this length is the same as the number of desired pieces.
Value
A tibble::tibble() data frame with the following columns:
"piece_side"
"suit"
"rank"
"cfg" (optional, defaults to
"piecepack")"x"
"y"
"angle" (optional, defaults to
0).
This data frame is compatible with piecepackr::render_piece() and likely ppcli::cat_piece().
Examples
# David Silverman's "Mini chess 4x4"
dfb <- chess_board(nrows = 4L, ncol = 4L)
df1 <- chess_bits(suit = "white", rank = c("R", "Q", "K", "R"),
x = 1:4, y= 1)
df2 <- chess_bits(suit = "white", rank = "P", x = 1:4, y= 2)
df3 <- chess_bits(suit = "black", rank = "P", x = 1:4, y= 3)
df4 <- chess_bits(suit = "black", rank = c("r", "q", "k", "r"),
x = 1:4, y= 4)
df <- rbind(dfb, df1, df2, df3, df4)
if (require("piecepackr", quietly = TRUE) &&
packageVersion("piecepackr") >= "1.15.0-1" &&
requireNamespace("systemfonts", quietly = TRUE) &&
piecepackr::has_font("Dejavu Sans") &&
piecepackr:::device_supports_unicode()) {
grid::grid.newpage()
envir = game_systems("dejavu")
pmap_piece(df, envir = envir, default.units = "in")
}