Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Encoding: UTF-8
Package: ppn
Type: Package
Title: Portable Piecepack Notation Parser
Version: 0.2.2-2
Version: 0.3.0-1
Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"),
email="trevor.l.davis@gmail.com",
comment = c(ORCID = "0000-0001-6341-4639")))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(domino_parser)
export(go_parser)
export(marble_parser)
export(morris_parser)
export(piecepack_parser)
export(plot_move)
export(read_ppn)
export(tarot_parser)
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
ppn 0.2.2 (development)
ppn 0.3.0 (development)
=======================

New features
------------

* We now export (and document their arguments) the following movetext parsers:

+ `piecepack_parser()`

Bug fixes and minor improvements
--------------------------------

* Fixes bug in `process_exclamation_move()` (e.g. `!PieceId` moves).
* Eliminated use of deprecated `ppdf` functions.

ppn 0.2.1
Expand Down
4 changes: 4 additions & 0 deletions R/default_parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ default_parser <- function(
game_list
}

#' @rdname ppn_parsers
#' @export
piecepack_parser <- default_parser

#' @rdname ppn_parsers
#' @export
alquerque_parser <- function(movetext = character(), metadata = list(), ...) {
Expand Down
2 changes: 1 addition & 1 deletion R/parse_moves.R
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ process_rotate_move <- function(df, text, state = create_state(df), clockwise =
}

process_exclamation_move <- function(df, text, state = create_state(df)) {
piece_id <- str_sub(text, 2L, 2L)
piece_id <- str_sub(text, 2L)
process_hyphen_move(df, paste0(piece_id, "-<0,0>"), state)
}

Expand Down
9 changes: 9 additions & 0 deletions man/ppn_parsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions tests/testthat/test_ppn.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ test_that("process_submove works as expected", {
expect_true(any(grepl("die_face", df$piece_side)))

expect_error(process_submove(df, "!"))
id_b2 <- df$id[df$x == 2 & df$y == 2]
df_b2 <- process_submove(df, "!b2")
expect_equal(tail(df_b2$id, 1L), id_b2)
expect_error(get_id_from_coords(df, "e5"))

df <- read_ppn(textConnection("1. S@a{1..6} M@a1 5a1-b1"))[[1]]$dfs[[2]]
Expand Down Expand Up @@ -928,3 +931,58 @@ test_that("ID computation works as expected", {
c("23..1", "24..1", "24..2", "30..3")
)
})

test_that("parsers work as expected", {
do.call(rlang::local_options, default_options())

ppn_movetext_parser <- function(name, game_type, movetext = character()) {
ppn <- paste0("---\nMovetextParser: ", name, "\nGameType: ", game_type, "\n...\n", movetext)
read_ppn(textConnection(ppn))[[1]]
}

# piecepack_parser is an alias for default_parser
g <- ppn_movetext_parser("Piecepack", "Four Field Kono")
expect_equal(nrow(g$dfs[[1]]), 20L)

# alquerque_parser: colored bits get "alquerque" cfg
df <- alquerque_parser(c("R●@a1"))$dfs[[2]]
expect_equal(df$cfg, "alquerque")
g <- ppn_movetext_parser("Alquerque", "Alquerque")
expect_equal(nrow(g$dfs[[1]]), 25L)

# checker_parser: checker bits get "checkers2" (default) or "checkers1" (cell_width=1)
expect_equal(checker_parser(c("Kc@a1"))$dfs[[2]]$cfg, "checkers2")
expect_equal(checker_parser(c("Kc@a1"), cell_width = 1)$dfs[[2]]$cfg, "checkers1")
g <- ppn_movetext_parser("Checker", "American Checkers")
expect_equal(nrow(g$dfs[[1]]), 25L)

# chess_parser: chess bits get "chess2" (default) or "chess1" (cell_width=1)
expect_equal(chess_parser(c("♚@e1"))$dfs[[2]]$cfg, "chess2")
expect_equal(chess_parser(c("♚@e1"), cell_width = 1)$dfs[[2]]$cfg, "chess1")
g <- ppn_movetext_parser("Chess", "International Chess")
expect_equal(nrow(g$dfs[[1]]), 33L)

# domino_parser: default system loads domino setup
g <- ppn_movetext_parser("Domino", "Fujisan")
expect_equal(nrow(g$dfs[[1]]), 19L)

# go_parser: colored bits get "go" cfg
df <- go_parser(c("R●@a1"))$dfs[[2]]
expect_equal(df$cfg, "go")
g <- ppn_movetext_parser("Go", "Go")
expect_equal(nrow(g$dfs[[1]]), 1L)

# marble_parser: colored bits get "marbles" cfg
df <- marble_parser(c("R●@a1"))$dfs[[2]]
expect_equal(df$cfg, "marbles")

# morris_parser: colored bits get "morris" cfg
df <- morris_parser(c("R●@a1"))$dfs[[2]]
expect_equal(df$cfg, "morris")
g <- ppn_movetext_parser("Morris", "Nine Mens Morris")
expect_equal(nrow(g$dfs[[1]]), 1L)

# tarot_parser: colored bits get "playing_cards_tarot" cfg
df <- tarot_parser(c("R●@a1"))$dfs[[2]]
expect_equal(df$cfg, "playing_cards_tarot")
})
Loading