diff --git a/.Rbuildignore b/.Rbuildignore index 2a31e93..4be4dcb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,7 +5,6 @@ .V8history inst/db man-roxygen -NEWS\.md ^\.httr-oauth$ ^cran-comments\.md$ ^README\.Rmd$ diff --git a/.github/workflows/R-Wasm-check.yaml b/.github/workflows/R-Wasm-check.yaml new file mode 100644 index 0000000..8f21a7f --- /dev/null +++ b/.github/workflows/R-Wasm-check.yaml @@ -0,0 +1,21 @@ +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + workflow_dispatch: + +name: R-Wasm-check + +permissions: + contents: read + +jobs: + R-Wasm-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Build package for WebAssembly + uses: r-wasm/actions/build-rwasm@v3 + with: + packages: "." diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..949a29e --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,37 @@ +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +permissions: + contents: write + +jobs: + pkgdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r@v2 + with: + r-version: release + use-public-rspm: true + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + - name: Build site + shell: Rscript {0} + run: pkgdown::build_site() + - name: Deploy site + if: github.event_name != 'pull_request' + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/DESCRIPTION b/DESCRIPTION index e48f9bf..ce6b61d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,18 +1,18 @@ Package: rchess -Version: 0.1 -Title: Chess Move, Generation/Validation, Piece Placement/ - Movement, and Check/Checkmate/Stalemate Detection -Description: R package for chess validations, pieces movements and check - detection. Also integrates functions to plot chess boards given a - Forsyth Edwards and Portable Game notations. -Authors@R: as.person(c( - "Joshua Kunst [aut, cre]", - "Reto Wyss [ctb]", - "Ogan Mancarci [ctb]" - )) +Version: 0.1.0.9000 +Title: Chess Move Generation, Validation, and Visualization +Description: Tools for chess move generation and validation, piece placement + and movement, game-state detection, and board visualization. Integrates + bundled JavaScript libraries for chess rules and interactive board display. +Authors@R: c( + person("Joshua", "Kunst", email = "jbkunst@gmail.com", role = c("aut", "cre")), + person("Reto", "Wyss", email = "reto.wyss.ch@gmail.com", role = "ctb"), + person("Ogan", "Mancarci", email = "ogan.mancarci@gmail.com", role = "ctb") + ) License: MIT + file LICENSE -URL: https://github.com/jbkunst/rchess +URL: https://jbkunst.github.io/rchess/, https://github.com/jbkunst/rchess BugReports: https://github.com/jbkunst/rchess/issues +Encoding: UTF-8 Imports: htmlwidgets, V8, @@ -24,6 +24,7 @@ Imports: stringr, tibble Suggests: - testthat (>= 3.0.0) + testthat (>= 3.0.0), + shiny Config/testthat/edition: 3 RoxygenNote: 5.0.1 diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..4bf7908 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# rchess (development version) + +* Package maintenance has resumed after the CRAN archival. +* Development metadata now uses a conventional development version and a canonical pkgdown/GitHub URL. +* CI, tests, documentation, and compatibility updates are being prepared as focused follow-up changes. diff --git a/R/ggchessboard.R b/R/ggchessboard.R index d6377b8..be93231 100644 --- a/R/ggchessboard.R +++ b/R/ggchessboard.R @@ -1,4 +1,4 @@ -x <- y <- NULL +x <- y <- cc <- text <- NULL #' Plot a fen representation chessboard via ggplot2 #' @description Function to show the fen string in ggplot2. #' @param fen Fen notation of a chessboard @@ -37,9 +37,9 @@ ggchessboard <- function(fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ dplyr::mutate(x = factor(x, levels = lvls), y = factor(y, levels = lvls)) - p <- ggplot(dchess, aes_string("x", "y")) + - geom_tile(aes_string(fill = "cc")) + - geom_text(aes_string(label = "text"), size = piecesize) + + p <- ggplot(dchess, aes(x = x, y = y)) + + geom_tile(aes(fill = cc)) + + geom_text(aes(label = text), size = piecesize) + scale_fill_manual(values = cellcols) + coord_equal() + theme(legend.position = "none", diff --git a/README.md b/README.md index 9c9f42c..b9621ec 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,54 @@ -# ♛ `rchess` A chess package for R - -[![travis-status](https://api.travis-ci.org/jbkunst/rchess.svg)](https://travis-ci.org/jbkunst/rchess) -[![version](http://www.r-pkg.org/badges/version/rchess)](http://www.r-pkg.org/pkg/rchess) -[![downloads](http://cranlogs.r-pkg.org/badges/rchess)](http://www.r-pkg.org/pkg/rchess) - -The [`rchess`](http://jkunst.com/rchess) package is a chess move, generation/validation, piece placement/movement, and check/checkmate/stalemate detection. - -This Packages is a wrapper for the [chess.js](https://github.com/jhlywa/chess.js) javascript library -and integrates htmlwidget for plot chessboard using [chessboardjs](http://chessboardjs.com/) library. - -For installation you use: - -```r -install.packages("rchess") -# Or -devtools::install_github("jbkunst/rchess") -``` +# ♛ `rchess` — Chess tools for R + +[![R-CMD-check](https://github.com/jbkunst/rchess/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jbkunst/rchess/actions/workflows/R-CMD-check.yaml) + +`rchess` provides chess move generation and validation, piece placement and +movement, game-state detection, and board visualization from R. It wraps the +bundled [chess.js](https://github.com/jhlywa/chess.js) JavaScript library and +includes both an HTML widget and a `ggplot2` board renderer. + +> **CRAN status:** `rchess` was archived on November 14, 2023. Until a new CRAN +> release is prepared, install the maintained development version from GitHub. + +## Installation + +```r +# install.packages("pak") +pak::pak("jbkunst/rchess") +``` + +## Quick start + +```r +library(rchess) + +game <- Chess$new() + +game$moves() +game$move("e4") +game$move("e5") +game$fen() +game$history() +``` + +Plot the current position with the HTML widget: + +```r +plot(game) +``` + +Or use the `ggplot2` renderer: + +```r +plot(game, type = "ggplot") +``` + +## Documentation + +Package documentation and examples are being rebuilt with pkgdown at +. + +## Development + +Issues and pull requests are welcome at +. diff --git a/demo/shiny-ex.R b/demo/shiny-ex.R index 074b4e8..fd00b69 100644 --- a/demo/shiny-ex.R +++ b/demo/shiny-ex.R @@ -1,18 +1,42 @@ library("shiny") library("rchess") -ui = shinyUI(fluidPage( - chessboardjsOutput('board', width = 300), - chessboardjsOutput('board2', width = 300) -)) +ui <- fluidPage( + textInput("move", "Move", placeholder = "e4"), + actionButton("make_move", "Move"), + chessboardjsOutput("board", width = 300, height = "300px"), + verbatimTextOutput("status") +) + +server <- function(input, output, session) { + game <- Chess$new() + current_fen <- reactiveVal(game$fen()) + current_history <- reactiveVal(game$history()) + + observeEvent(input$make_move, { + req(nzchar(input$move)) + + if (!input$move %in% game$moves()) { + showNotification("Invalid move", type = "error") + return() + } + + game$move(input$move) + current_fen(game$fen()) + current_history(game$history()) + updateTextInput(session, "move", value = "") + }) -server = function(input, output) { output$board <- renderChessboardjs({ - chessboardjs("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2") + chessboardjs(current_fen(), width = 300, height = 300) }) - output$board2 <- renderChessboardjs({ - chessboardjs() + output$status <- renderPrint({ + history <- current_history() + list( + turn = game$turn(), + history = history + ) }) } diff --git a/tests/testthat/test-chess.R b/tests/testthat/test-chess.R new file mode 100644 index 0000000..af29927 --- /dev/null +++ b/tests/testthat/test-chess.R @@ -0,0 +1,27 @@ +starting_fen <- "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" + +test_that("Chess initializes the standard position", { + game <- Chess$new() + + expect_equal(game$fen(), starting_fen) + expect_equal(game$turn(), "w") + expect_length(game$history(), 0) + expect_true("e4" %in% game$moves()) +}) + +test_that("moves update history, turn, and board state", { + game <- Chess$new() + + expect_invisible(game$move("e4")) + expect_equal(game$turn(), "b") + expect_equal(game$history(), "e4") + expect_false(identical(game$fen(), starting_fen)) + + game$undo() + expect_equal(game$fen(), starting_fen) + expect_equal(game$turn(), "w") +}) + +test_that("invalid FEN strings are rejected", { + expect_error(Chess$new("not-a-fen")) +})