Title: | Read, Write, Create and Explore Chess Games |
Version: | 1.0.1 |
Description: | This is an opinionated wrapper around the python-chess package. 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. |
License: | GPL-3 |
URL: | https://github.com/curso-r/chess |
BugReports: | https://github.com/curso-r/chess/issues |
Depends: | R (≥ 2.10) |
Imports: | cli, magrittr, purrr, reticulate, rsvg |
Suggests: | covr, graphics, knitr, png, rmarkdown, testthat |
VignetteBuilder: | knitr |
Config/reticulate: | list( packages = list( list(package = "python-chess", pip = TRUE) ) ) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | no |
Packaged: | 2020-12-04 22:00:17 UTC; clente |
Author: | C. Lente [aut, cre] |
Maintainer: | C. Lente <clente@curso-r.com> |
Repository: | CRAN |
Date/Publication: | 2020-12-04 22:20:02 UTC |
Pipe operator
Description
See magrittr::%>%
for details.
Usage
lhs %>% rhs
Go back in the game tree, reverting the last move from current branch
Description
Go back in the game tree, reverting the last move from current branch
Usage
back(game, steps = 1)
Arguments
game |
A game node |
steps |
How many steps (half-turns) to go back |
Value
A game node
Get information about the current board given a color
Description
Get information about the current board given a color
Usage
has_insufficient_material(game, color)
has_castling_rights(game, color)
has_kingside_castling_rights(game, color)
has_queenside_castling_rights(game, color)
Arguments
game |
A game node |
color |
Color to use ( |
Value
A boolean
Get information about the current board
Description
Get information about the current board
Usage
is_checkmate(game)
is_check(game)
is_game_over(game)
is_stalemate(game)
is_insufficient_material(game)
is_seventyfive_moves(game)
is_fivefold_repetition(game)
is_repetition(game, count = 3)
can_claim_draw(game)
can_claim_fifty_moves(game)
can_claim_threefold_repetition(game)
has_en_passant(game)
Arguments
game |
A game node |
count |
Number of moves to count for repetition |
Value
A boolean
Get information about the current board given a move
Description
Get information about the current board given a move
Usage
gives_check(game, move, notation = c("san", "uci", "xboard"))
is_en_passant(game, move, notation = c("san", "uci", "xboard"))
is_capture(game, move, notation = c("san", "uci", "xboard"))
is_zeroing(game, move, notation = c("san", "uci", "xboard"))
is_irreversible(game, move, notation = c("san", "uci", "xboard"))
is_castling(game, move, notation = c("san", "uci", "xboard"))
is_kingside_castling(game, move, notation = c("san", "uci", "xboard"))
is_queenside_castling(game, move, notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
move |
Move to consider |
notation |
Notation used for |
Value
A boolean
Convert a board to either unicode or ASCII string
Description
Convert a board to either unicode or ASCII string
Usage
board_to_string(x, unicode = FALSE, invert_color = FALSE, empty_square = ".")
Arguments
x |
A board |
unicode |
Use unicode characters? |
invert_color |
Invert piece color? Useful for white text on dark background. |
empty_square |
Character used for empty square |
Value
A string
Get FEN representation of board
Description
Get FEN representation of board
Usage
fen(game)
Arguments
game |
A game node |
Value
A string
Advance in the game tree, playing next move from current branch
Description
Advance in the game tree, playing next move from current branch
Usage
forward(game, steps = 1)
Arguments
game |
A game node |
steps |
How many steps (half-turns) to advance |
Value
A game node
Create a new game
Description
A game is a tree with nodes, where each node represents the board after a move and each branch represents a variation of the game (not to be confused with a variant of chess). This tree mirrors the PGN of the game.
To explore a game, an object of this class supports print()
, plot()
,
str()
, fen()
, pgn()
and more.
Usage
game(headers = NULL, fen = NULL)
Arguments
headers |
A named list like |
fen |
FEN representing the starting position of the board |
Value
A game root node
Convert glyph to NAG
Description
Convert glyph to NAG
Usage
glyph_to_nag(glyph)
Arguments
glyph |
A game node |
Value
An integer
Get number of half-moves since the last capture or pawn move
Description
Get number of half-moves since the last capture or pawn move
Usage
halfmove_clock(game)
Arguments
game |
A game node |
Value
An integer
Install python-chess
Description
Install the python library used as the backbone of this package. You can
pass arguments on to reticulate::py_install()
, but python-chess
needs
python_version = "3.8"
and pip = TRUE
.
Usage
install_chess(method = "auto", conda = "auto", ...)
Arguments
method |
Installation method |
conda |
The path to a conda executable |
... |
Other arguments passed on to |
Branch game with next move
Description
Branch game with next move
Usage
line(game, moves, notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
moves |
Vector of one or more description of moves |
notation |
Notation used for |
Value
A game node
Make moves and create variations
Description
Adding moves to a game works roughly in the same way as PGN.
Strings are added as single moves, and lists are added as variations
(siblings) to the last move made. After adding moves, the game node returned
corresponds to the last move of the mainline. See vignette("chess")
for
more information.
Usage
move(game, ..., notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
... |
Sequence of moves (lists are converted to a variation the same way parentheses work in PGN) |
notation |
Notation used for |
Value
A game node
Make moves and create variations
Description
Make moves and create variations
Usage
move_(game, moves, notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
moves |
List of moves |
notation |
Notation used for moves |
Value
A game node
Get number of move
Description
Get number of move
Usage
move_number(game)
Arguments
game |
A game node |
Value
An integer
Get all legal moves available
Description
Get all legal moves available
Usage
moves(game)
Arguments
game |
A game node |
Value
A vector of strings
Parse Numeric Annotation Glyph (NAG) of a move
Description
Parse Numeric Annotation Glyph (NAG) of a move
Usage
nag(game)
Arguments
game |
A game node |
Value
A string
Get comment for a move
Description
Get comment for a move
Usage
note(game)
Arguments
game |
A game node |
Value
A string
Parse move in context
Description
Parse move in context
Usage
parse_move(game, moves, notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
moves |
A move string |
notation |
Notation used for |
Value
A move object
Get PGN for node of a game
Description
Get PGN for node of a game
Usage
pgn(game)
Arguments
game |
A game node |
Value
A string
Move a piece on the board
Description
Move a piece on the board
Usage
play(game, moves, notation = c("san", "uci", "xboard"))
Arguments
game |
A game node |
moves |
Vector of one or more description of moves |
notation |
Notation used for |
Value
A game node
Plot rendering of the board
Description
Plot rendering of the board
Usage
## S3 method for class 'chess.pgn.GameNode'
plot(x, ...)
Arguments
x |
A game node |
... |
Not used |
Get number of ply
Description
Get number of ply
Usage
ply_number(game)
Arguments
game |
A game node |
Value
An integer
Print board
Description
Print board
Usage
## S3 method for class 'chess.Board'
print(x, unicode = FALSE, invert_color = FALSE, empty_square = ".", ...)
Arguments
x |
A game board |
unicode |
Use unicode characters? |
invert_color |
Invert piece color? Useful for white text on dark background. |
empty_square |
Character used for empty square |
... |
Not used |
Print game node
Description
Print game node
Usage
## S3 method for class 'chess.pgn.GameNode'
print(x, unicode = FALSE, invert_color = FALSE, empty_square = ".", ...)
Arguments
x |
A game node |
unicode |
Use unicode characters? |
invert_color |
Invert piece color? Useful for white text on dark background. |
empty_square |
Character used for empty square |
... |
Not used |
Print a list of variations
Description
Print a list of variations
Usage
## S3 method for class 'chess.pgn.Variations'
print(x, unicode = FALSE, invert_color = FALSE, empty_square = ".", ...)
Arguments
x |
A game node |
unicode |
Use unicode characters? |
invert_color |
Invert piece color? Useful for white text on dark background |
empty_square |
Character used for empty square |
... |
Not used |
Read a game from a PGN
Description
Read a .pgn
file with one or more annotated games; if there is more than 1
game in the file, a list is returned (which you can access with [[[
()]).
Some sample .pgn
files are included in the package. See vignette("games")
for more information.
Usage
read_game(file, n_max = Inf)
Arguments
file |
File or connection to read from |
n_max |
Maximum number of games to read |
Value
A game node or list of game nodes
Get result of the game ("*" if it hasn't ended)
Description
Get result of the game ("*" if it hasn't ended)
Usage
result(game)
Arguments
game |
Any node of a game |
Value
A string
Get the root node of a game
Description
Get the root node of a game
Usage
root(game)
Arguments
game |
A game node |
Value
A game node
Get whose turn it is
Description
Get whose turn it is
Usage
turn(game)
Arguments
game |
A game node |
Value
A boolean (TRUE
is White and FALSE
is Black)
Follow variation of a move, playing its first move
Description
Follow variation of a move, playing its first move
Usage
variation(game, id = 1)
Arguments
game |
A game node |
id |
Index of variation (1 is the current branch) |
Value
A game node
Get all variations for next move (the children of current node)
Description
Get all variations for next move (the children of current node)
Usage
variations(game)
Arguments
game |
A game node |
Value
A list of games nodes
Save a game as an PGN
Description
Save a game as an PGN
Usage
write_game(x, file)
Arguments
x |
Any node of a game |
file |
File or connection to write to |
Save an SVG with rendering of the board
Description
Save an SVG with rendering of the board
Usage
write_svg(x, file)
Arguments
x |
A game node |
file |
File or connection to write to |