| Title: | Chess Game Creation and Tools |
|---|---|
| Description: | A chess program which allows the user to create a game, add moves, check for legal moves and game result, plot the board, take back, read and write FEN (Forsyth–Edwards Notation). A basic chess engine based on minimax is implemented. |
| Authors: | Luigi Annicchiarico [cre, aut] |
| Maintainer: | Luigi Annicchiarico <[email protected]> |
| License: | GPL-3 |
| Version: | 0.3.0 |
| Built: | 2026-05-22 09:54:24 UTC |
| Source: | https://github.com/luigi-annic/chess2plyrs |
Takes in input a move, evaluates whether it is legal, and if it is, then the game is updated
chess_move(game, piece, initialposition = "", finalposition = "")chess_move(game, piece, initialposition = "", finalposition = "")
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
piece |
letter indicating the piece to be moved (p, N, B, R, Q, K) |
initialposition |
initial square of the piece |
finalposition |
destination square |
makes move
newgame() |> chess_move("N", "g1", "f3")newgame() |> chess_move("N", "g1", "f3")
plots the current position
chessplot(game, style = 1)chessplot(game, style = 1)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
style |
font style. 1: chess pieces according to unicode; 2: chess labels |
plot
All tools used for letting the chess program work.
chesstoolschesstools
An object of class list
engine which chooses minimax between legal moves, with alpha beta pruning
engine2(game, depth)engine2(game, depth)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
depth |
depth of the minimax. depth of 1 and 2 are fairly rapid. |
game with new move done
This function tells if the game is still ongoing, or if a checkamte or stalemate are on the board
game_result(game)game_result(game)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
a message
lists legal moves
legalmoves(game)legalmoves(game)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
character vector
newgame() |> legalmoves()newgame() |> legalmoves()
Creates move scorelist, in scientific notation
moves_scoresheet(game, shortnotation = TRUE)moves_scoresheet(game, shortnotation = TRUE)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
shortnotation |
Use short scientific notation? TRUE is the default |
moves scoresheet
g <- newgame() |> chess_move("p", "e2", "e4") |> chess_move("p", "e7", "e5") |> chess_move("N", "g1", "f3") |> chess_move("N", "b8", "c6") |> chess_move("B", "f1", "b5") |> chess_move("N", "g8", "f6") |> chess_move("K", "e1", "0-0")|> chess_move("N", "f6", "e4") moves_scoresheet(g)g <- newgame() |> chess_move("p", "e2", "e4") |> chess_move("p", "e7", "e5") |> chess_move("N", "g1", "f3") |> chess_move("N", "b8", "c6") |> chess_move("B", "f1", "b5") |> chess_move("N", "g8", "f6") |> chess_move("K", "e1", "0-0")|> chess_move("N", "f6", "e4") moves_scoresheet(g)
engine which chooses randomly between legal moves
random_mover(game)random_mover(game)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
game with new move done
read fen (Forsyth–Edwards Notation) notation
readfen(fenstring)readfen(fenstring)
fenstring |
fen string (pieces and turn) |
board and turn
readfen("r3kb1r/pp1nqppp/4bp2/2p5/3P4/1B3N2/PPP1QPPP/R1B1K2R w")readfen("r3kb1r/pp1nqppp/4bp2/2p5/3P4/1B3N2/PPP1QPPP/R1B1K2R w")
takeback
takeback(game)takeback(game)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
game (last move being deleted)
write fen (Forsyth–Edwards Notation) notation
writefen(game, cb = NULL, tb = NULL, cb_tb_insteadof_game = FALSE)writefen(game, cb = NULL, tb = NULL, cb_tb_insteadof_game = FALSE)
game |
chess game object (i.e., a list with elements board, turn, history, and fen_history as created by newgame function) |
cb |
chess board if cb_tf_insteadof_game set to TRUE |
tb |
turn if cb_tf_insteadof_game set to TRUE |
cb_tb_insteadof_game |
if FALSE, uses game to create fen, if TRUE it uses cb and tb |
fen