Liking cljdoc? Tell your friends :D

chessica.formats.fen

Functions for querying and writing Forsyth-Edwards Notation data used in reproducing chess positions.

See: https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

Functions for querying and writing Forsyth-Edwards Notation 
data used in reproducing chess positions.

See:
https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
raw docstring

->dataclj

(->data fen)

Transforms a FEN string into a map with keys :pos, an 8x8 vector of vectors of piece keywords or nil for spaces where each piece symbol in FEN is keywordized. :turn, the side to move, one of :w or :b :castling, a vector of up to 4 keywordized FEN symbols (:K,:Q etc) can be empty when no side can castle :en-passant, a [row col] vector of the square 'behind' the pawn just having made an initial (2 squares) move if any, or nil :clock, an int (0 or positive) for the half-move clock :move, the move number in the game. The output map can be more easily queried and transformed.

Transforms a FEN string into a map with keys 
   :pos, an 8x8 vector of vectors of piece keywords or nil for spaces
         where each piece symbol in FEN is keywordized.
   :turn, the side to move, one of :w or :b
   :castling, a vector of up to 4 keywordized FEN symbols (:K,:Q etc)
              can be empty when no side can castle
   :en-passant, a [row col] vector of the square 'behind' the pawn just
                having made an initial (2 squares) move if any, or nil
   :clock, an int (0 or positive) for the half-move clock
   :move, the move number in the game.
The output map can be more easily queried and transformed.
sourceraw docstring

->fenclj

(->fen {:keys [pos turn castling en-passant clock move]})

Transforms a data map (as per the output of ->data) into a FEN string.

Transforms a data map (as per the output of ->data)
into a FEN string.
sourceraw docstring

->intclj

(->int c)
source

->numclj

(->num s)
source

->pos-dataclj

(->pos-data fen-pos)
source

->pos-fenclj

(->pos-fen pos)
source

->row-fenclj

(->row-fen col)
source

complete-dataclj

(complete-data other-dat-str board)
source

fen-startclj

source

kws->strclj

(kws->str kws)
source

populateclj

(populate pairs completion-dat)
(populate board pairs completion-dat)

Creates a FEN string from a starting board - an 8x8 vovs, pairs of [piece-or-pieces, locations-string] and tailing data (turn to move, castling state etc). Each pair is in a user-friendly format representing cumulative board updates - see update-board. Example:

(populate [[:p "a7 g6 f7 e6 d5 c7 b7 a7"] ;; black pawn structure

        ["krrnq" "g8 f8 a8 e5 c4"]   ;; black king on g8, rooks on 
                                     ;; f8 and a8, and so forth  

        [:P "g5 f2 c2 b2 a3"]        ;; white pawn structure

        ["QKRRBN" "g3 d1 h1 a1 g1 b1"]] ;; white pieces

        "b KQ - 0 40")  ;; FEN string tail: turn to play, etc.

;;=> "r4rk1/ppp2p2/4p1p1/3pn1P1/2q5/P5Q1/1PP2P2/RN1K2BR b KQ - 0 40"

Creates a FEN string from a starting board - an 8x8 vovs,
 pairs of [piece-or-pieces, locations-string] and tailing
 data (turn to move, castling state etc).
 Each pair is in a user-friendly format representing cumulative 
 board updates - see `update-board`.
 Example:

 (populate [[:p "a7 g6 f7 e6 d5 c7 b7 a7"] ;; black pawn structure

            ["krrnq" "g8 f8 a8 e5 c4"]   ;; black king on g8, rooks on 
                                         ;; f8 and a8, and so forth  

            [:P "g5 f2 c2 b2 a3"]        ;; white pawn structure

            ["QKRRBN" "g3 d1 h1 a1 g1 b1"]] ;; white pieces

            "b KQ - 0 40")  ;; FEN string tail: turn to play, etc.

;;=> "r4rk1/ppp2p2/4p1p1/3pn1P1/2q5/P5Q1/1PP2P2/RN1K2BR b KQ - 0 40"
sourceraw docstring

str->castleclj

(str->castle s)
source

str->epclj

(str->ep s)
source

str->kwsclj

(str->kws s)
source

update-boardclj

(update-board p-or-ps locs-str board)

Adds/remove/replace a chess piece to one or more locations on a chess board, where p-or-ps is a either a single piece keyword or a string of space-delimited piece-letters (in which case each piece is inserted at its respective location in locs-str) locs-str is a space separated string of chessboard coordinates, e.g. 'a3 b2' and board is an 8x8 vector of vectors of either nil or occupied squares. The updated board is returned. 'piece can be set to nil to remove the content of each square in 'locs-str.

Adds/remove/replace a chess piece to one or more locations on a chess board,
where p-or-ps is a either a single piece keyword or a string of space-delimited
piece-letters (in which case each piece is inserted at its respective location
in locs-str)
locs-str is a space separated string of chessboard coordinates, e.g. 'a3 b2'
and board is an 8x8 vector of vectors of either nil or occupied squares.
The updated board is returned. 'piece can be set to `nil` to remove the content 
of each square in 'locs-str.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close