All Projects → curso-r → chess

curso-r / chess

Licence: GPL-3.0 license
An R package to read, write, create and explore chess games

Programming Languages

r
7636 projects
shell
77523 projects

Projects that are alternatives of or similar to chess

chess-puzzle-maker
Creates chess puzzles from chess games and positions
Stars: ✭ 34 (-43.33%)
Mutual labels:  chess, pgn, stockfish
kokopu
A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.
Stars: ✭ 18 (-70%)
Mutual labels:  chess, pgn
stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (-65%)
Mutual labels:  chess, stockfish
stockfish.js
The strong open source chess engine Stockfish compiled to JavaScript and WebAssembly using Emscripten
Stars: ✭ 140 (+133.33%)
Mutual labels:  chess, stockfish
pgn-tactics-generator
Generate chess puzzles / tactics from a pgn file
Stars: ✭ 83 (+38.33%)
Mutual labels:  chess, stockfish
chessalyzer.js
A JavaScript library for batch analyzing chess games
Stars: ✭ 14 (-76.67%)
Mutual labels:  chess, pgn
php-chess
A chess library for PHP.
Stars: ✭ 42 (-30%)
Mutual labels:  chess, pgn
rust-pgn-reader
Fast non-allocating and streaming reader for chess games in PGN notation
Stars: ✭ 46 (-23.33%)
Mutual labels:  chess, pgn
liPGN
This program uses the lichess REST API to retrieve all the games of a user and transform them into a big PGN file that you can then import into your favourite game analysis tool (ie. scid)
Stars: ✭ 14 (-76.67%)
Mutual labels:  chess, pgn
cm-pgn
Parse and create PGNs (Portable Game Notation for chess games)
Stars: ✭ 16 (-73.33%)
Mutual labels:  chess, pgn
chess-openings
An aggregated data set of chess opening names
Stars: ✭ 223 (+271.67%)
Mutual labels:  chess
chessboard-recognizer
Uses neural networks to extract chess positions from images
Stars: ✭ 59 (-1.67%)
Mutual labels:  chess
bevy chess
Chess demo in Bevy
Stars: ✭ 59 (-1.67%)
Mutual labels:  chess
python-chess-annotator
Reads chess games in PGN format and adds annotations using an engine
Stars: ✭ 48 (-20%)
Mutual labels:  chess
Chessman
Chess analysis Universal Windows 10 application.
Stars: ✭ 14 (-76.67%)
Mutual labels:  chess
chess graph
A program that will produce a graphical sunburst chart of chess openings from the PGN that is provided to it
Stars: ✭ 35 (-41.67%)
Mutual labels:  chess
lila-openingexplorer
Opening explorer for lichess.org that can handle all the variants and billions of unique positions
Stars: ✭ 89 (+48.33%)
Mutual labels:  chess
tea-chess
A chess-themed tutorial on writing an SPA in Bucklescript-TEA
Stars: ✭ 28 (-53.33%)
Mutual labels:  chess
shogi-pieces
Shogi (Japanese Chess) pieces and boards
Stars: ✭ 25 (-58.33%)
Mutual labels:  chess
Demolito
UCI Chess Engine
Stars: ✭ 41 (-31.67%)
Mutual labels:  chess

chess

CRAN status Codecov test coverage R build status Lifecycle: maturing

Overview

{chess} is an opinionated wrapper for R around python-chess, an amazing library created by Niklas Fiekas. It allows users to read and write PGN files as well as create and explore game trees such as the ones seen in chess books.

Installation

Install the released version of {chess} from CRAN:

install.packages("chess")

Or install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("curso-r/chess")

This should automatically install python-chess to your {reticulate} environment, but you can also explicitly do it with a convenient function:

chess::install_chess()

Example

To read an existing game, simply use read_game(). To explore it you can use forward()/back(), as well as variations()/variation() to see all variations listed for the next move and choose one of them.

library(chess)

# Read final game from the Queen's Gambit
file <- system.file("harmon.pgn", package = "chess")
harmon_borgov <- read_game(file)

# Starting position
harmon_borgov
#>         <Start>
#> r n b q k b n r
#> p p p p p p p p
#> . . . . . . . .
#> . . . . . . . .
#> . . . . . . . .
#> . . . . . . . .
#> P P P P P P P P
#> R N B Q K B N R

# Navigate to 2. c4
harmon_borgov %>%
  forward(3)
#>         <2. c4>
#> r n b q k b n r
#> p p p . p p p p
#> . . . . . . . .
#> . . . p . . . .
#> . . P P . . . .
#> . . . . . . . .
#> P P . . P P P P
#> R N B Q K B N R

# See all variations for 2...
harmon_borgov %>%
  forward(3) %>%
  variations()
#>       <2... e5>          <2... e6>
#> r n b q k b n r    r n b q k b n r
#> p p p . . p p p    p p p . . p p p
#> . . . . . . . .    . . . . p . . .
#> . . . p p . . .    . . . p . . . .
#> . . P P . . . .    . . P P . . . .
#> . . . . . . . .    . . . . . . . .
#> P P . . P P P P    P P . . P P P P
#> R N B Q K B N R    R N B Q K B N R

# Follow the sideline
harmon_borgov %>%
  forward(3) %>%
  variation(2)
#>       <2... e6>
#> r n b q k b n r
#> p p p . . p p p
#> . . . . p . . .
#> . . . p . . . .
#> . . P P . . . .
#> . . . . . . . .
#> P P . . P P P P
#> R N B Q K B N R

Many other games are included with the package so you can get up and running as soon as you install {chess}! See vignette("games") for more information.

You can also create your own game with game() and add variations to it: the move() function adds moves as well as branches the tree of the game. Strings are converted to simple moves, while list()s behave exactly as parenthesis in PGN, creating a variation of the last move. Here you can see how to recreate a Scholar’s mate and some ways to avoid it:

# Scholar's mate and some defenses
scholars_mate <- game() %>%
  move("e4") %>%
  move("e5", list("e6"), list("d5")) %>%
  move("Bc4") %>%
  move("Nc6", list("Nf6")) %>%
  move("Qh5") %>%
  move("Nf6", list("g6", "Qf3", "Nf6")) %>%
  move("Qxf7")

# Last mainline move
scholars_mate
#>      <4. Qxf7#>
#> r . b q k b . r
#> p p p p . Q p p
#> . . n . . n . .
#> . . . . p . . .
#> . . B . P . . .
#> . . . . . . . .
#> P P P P . P P P
#> R N B . K . N R

Note that there are many ways to structure the input to move(). See vignette("chess") for more information.

{chess} also features many ways of seeing both the game as a whole and the board at a specific point in time.

# Print with unicode (doesn't look good on GitHub)
print(scholars_mate, unicode = TRUE)
#>      <4. Qxf7#>
#> ♜ . ♝ ♛ ♚ ♝ . ♜
#> ♟ ♟ ♟ ♟ . ♕ ♟ ♟
#> . . ♞ . . ♞ . .
#> . . . . ♟ . . .
#> . . ♗ . ♙ . . .
#> . . . . . . . .
#> ♙ ♙ ♙ ♙ . ♙ ♙ ♙
#> ♖ ♘ ♗ . ♔ . ♘ ♖

# Export the FEN of the board
fen(scholars_mate)
#> [1] "r1bqkb1r/pppp1Qpp/2n2n2/4p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 0 4"

# See the PGN after some move
str(back(scholars_mate, 3))
#> 2... Nc6 3. Qh5 Nf6 ( 3... g6 4. Qf3 Nf6 ) 4. Qxf7#

# Export the PGN after some move
pgn(back(scholars_mate, 3))
#> [1] "2... Nc6 3. Qh5 Nf6 ( 3... g6 4. Qf3 Nf6 ) 4. Qxf7#"

# Plot current board
plot(scholars_mate)

Motivation

python-chess served as the inspiration (and backbone) for {chess}. While the original version (and {rchess} for that matter) broadly handles “move generation, move validation” (with powerful classes and object-oriented syntax), {chess} focuses on making it easy to create and explore PGNs as trees.

By narrowing down the scope of the API, I believe the package becomes more intuitive to people who just want to quickly create shareable game analyses or easily explore other people’s games without having to resort to point and click software.

{chess}’s first use was helping me study Bobby Fischer’s My 60 Memorable Games. After some very difficult parsing, I was able to convert the whole book to PGN and upload it to lichess, but I still felt like the interface was too clumsy…

Roadmap

  • NAGs
  • Comments
  • Headers
  • Start game from FEN
  • Better plotting
  • More status functions
  • Other OSs
  • Unit tests
  • Advanced usage
  • Styler
  • CRAN
  • Stockfish API
  • Static boards (puzzles)
  • Shiny?

Code of Conduct

Please note that the {chess} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

{chess} is licensed under the GPL 3 (or any later version at your option). Check out LICENSE.md for the full text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].