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
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.V8history
inst/db
man-roxygen
NEWS\.md
^\.httr-oauth$
^cran-comments\.md$
^README\.Rmd$
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/R-Wasm-check.yaml
Original file line number Diff line number Diff line change
@@ -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: "."
37 changes: 37 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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)'
27 changes: 14 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <jbkunst@gmail.com> [aut, cre]",
"Reto Wyss <reto.wyss.ch@gmail.com> [ctb]",
"Ogan Mancarci <ogan.mancarci@gmail.com> [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,
Expand All @@ -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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 4 additions & 4 deletions R/ggchessboard.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
72 changes: 54 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<https://jbkunst.github.io/rchess/>.

## Development

Issues and pull requests are welcome at
<https://github.com/jbkunst/rchess>.
40 changes: 32 additions & 8 deletions demo/shiny-ex.R
Original file line number Diff line number Diff line change
@@ -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
)
})
}

Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-chess.R
Original file line number Diff line number Diff line change
@@ -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"))
})
Loading