Tree data structure for representing an annotated game with variations. Work in progress, use at your own risk.
Tree data structure for representing an annotated game with variations. Work in progress, use at your own risk.
(add-byte-move game byte-move & {:keys [node-id remove-existing-moves?]})
Adds a move in byte notation to the game at the given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Adds a move in byte notation to the game at the given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-byte-move-sequence game
byte-moves
&
{:keys [node-id remove-existing-moves?]})
Like add-byte-move, but adds a sequence of moves rather than a single move. This is faster than calling add-byte-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Like add-byte-move, but adds a sequence of moves rather than a single move. This is faster than calling add-byte-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-comment game cmt & {:keys [node-id]})
Adds a comment to the move leading to the node with the given node id. Uses current node if no node id is supplied. Adding a comment at the root of the game has no effect; if you want to add a comment before the first move of the game, use add-pre-comment instead.
Adds a comment to the move leading to the node with the given node id. Uses current node if no node id is supplied. Adding a comment at the root of the game has no effect; if you want to add a comment before the first move of the game, use add-pre-comment instead.
(add-key-value-pair game key value & {:keys [node-id]})
Adds a key value pair to the map at the given node id of the game. If no node id is supplied, the key value pair is added at the current node.
Adds a key value pair to the map at the given node id of the game. If no node id is supplied, the key value pair is added at the current node.
(add-map-move game map-move & {:keys [node-id remove-existing-moves?]})
Adds a map move (see documentation for clj-chess.board/board-to-map) to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Adds a map move (see documentation for clj-chess.board/board-to-map) to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-move game move-function move node-id remove-existing-moves?)
Takes a game, a move function (a function that, given a board and some other value, translates that value to a chess move), a a value representing a move, a node id, and a boolean that says whether the existing moves at the current nodes should be removed, and returns an updated game where the move has been added as the last child at the given node. If no node id is supplied, the current node of the game is used.
Takes a game, a move function (a function that, given a board and some other value, translates that value to a chess move), a a value representing a move, a node id, and a boolean that says whether the existing moves at the current nodes should be removed, and returns an updated game where the move has been added as the last child at the given node. If no node id is supplied, the current node of the game is used.
(add-move-sequence game move-function moves node-id remove-existing-moves?)
Like add-move, but adds a sequence of moves rather than a single move. This is faster than calling add-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Like add-move, but adds a sequence of moves rather than a single move. This is faster than calling add-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-pre-comment game cmt & {:keys [node-id]})
Adds a pre-comment to the node with the given node-id. Uses the current node if no node id is supplied. When exporting as PGN, the pre-comment is displayed before the move rather than after. It is probably only useful for the first move of the game or the first move of a recursive annotation variation.
Adds a pre-comment to the node with the given node-id. Uses the current node if no node id is supplied. When exporting as PGN, the pre-comment is displayed *before* the move rather than after. It is probably only useful for the first move of the game or the first move of a recursive annotation variation.
(add-san-move game san-move & {:keys [node-id remove-existing-moves?]})
Adds a move in short algebraic notation to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Adds a move in short algebraic notation to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-san-move-sequence game
san-moves
&
{:keys [node-id remove-existing-moves?]})
Like add-san-move, but adds a sequence of moves rather than a single move. This is faster than calling add-san-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Like add-san-move, but adds a sequence of moves rather than a single move. This is faster than calling add-san-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-uci-move game uci-move & {:keys [node-id remove-existing-moves?]})
Adds a move in UCI notation to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Adds a move in UCI notation to a game at a given node id. The move is added as the last child. If no node id is supplied, the current node of the game is used. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(add-uci-move-sequence game
uci-moves
&
{:keys [node-id remove-existing-moves?]})
Like add-uci-move, but adds a sequence of moves rather than a single move. This is faster than calling add-uci-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
Like add-uci-move, but adds a sequence of moves rather than a single move. This is faster than calling add-uci-move multiple times, because we don't have to unzip and zip the tree for each added move. If remove-existing-moves? is true, any previously existing moves at the point of insertion are removed.
(at-beginning? game)
Tests whether we are currently at the beginning of the game, i.e. that the current node equals the root node.
Tests whether we are currently at the beginning of the game, i.e. that the current node equals the root node.
(at-end? game)
Tests whether we are currently at the end of the game, i.e. that the current node has no children.
Tests whether we are currently at the end of the game, i.e. that the current node has no children.
(black-elo game)
The Elo of the black player (as an integer), or nil.
The Elo of the black player (as an integer), or nil.
(black-player game)
Name of the black player.
Name of the black player.
(board game)
Returns the current board position of a game.
Returns the current board position of a game.
(boards game)
A sequence of all the board positions along the main line of the game, beginning at the root node.
A sequence of all the board positions along the main line of the game, beginning at the root node.
(boards-with-moves game)
A sequence of two element vectors, one for each board position along the main line, beginning at the root node. Each two-element vector consists of a board along with the move made from that board.
A sequence of two element vectors, one for each board position along the main line, beginning at the root node. Each two-element vector consists of a board along with the move made from that board.
(current-node-id game)
Returns the node id of the current node.
Returns the node id of the current node.
(date game)
The date the game was played, as a joda.time.DateTime object in Clojure, and a string in ClojureScript.
The date the game was played, as a joda.time.DateTime object in Clojure, and a string in ClojureScript.
(event game)
The event of the game, as a string.
The event of the game, as a string.
(find-node game node-id)
Returns the node with the given node id, or nil if no such node exists.
Returns the node with the given node id, or nil if no such node exists.
(find-node-matching game predicate & [start-node])
Finds the first (as found by a depth-first search) game tree node matching the given predicate. If no such node is found, returns nil.
Finds the first (as found by a depth-first search) game tree node matching the given predicate. If no such node is found, returns nil.
(from-ecn ecn
&
{:keys [include-annotations? san]
:or {include-annotations? true san false}})
Creates a game from ECN data, or from parsed PGN.
Creates a game from ECN data, or from parsed PGN.
(from-pgn pgn-string
&
{:keys [include-annotations?] :or {include-annotations? true}})
Creates a game from a PGN string.
Creates a game from a PGN string.
(games-in-file file-name & {:keys [format]})
Returns a lazy sequence of all games in an ECN or PGN file. The optional :format keyword parameter can take the values :ecn or :pgn, and is used to specify the file format. If this parameter is ommited, the function tries to guess the file type by inspecting the extension. If the extension is neither ".pgn", ".PGN", ".ecn" nor ".ECN", PGN format is assumed.
Returns a lazy sequence of all games in an ECN or PGN file. The optional :format keyword parameter can take the values :ecn or :pgn, and is used to specify the file format. If this parameter is ommited, the function tries to guess the file type by inspecting the extension. If the extension is neither ".pgn", ".PGN", ".ecn" nor ".ECN", PGN format is assumed.
(goto-node-id game node-id)
Returns a game equal to the input game, except that :current-node is set to the node with the given node id. If no node with the supplied node id exists in the game, returns nil.
Returns a game equal to the input game, except that :current-node is set to the node with the given node id. If no node with the supplied node id exists in the game, returns nil.
(goto-node-matching game predicate)
Returns a game equal to the input game, except that :current-node is set to the first node matching the given predicate. If no such node is found, returns nil.
Returns a game equal to the input game, except that :current-node is set to the first node matching the given predicate. If no such node is found, returns nil.
(main-line game)
Returns a vector of all nodes along the main line of the game, beginning with the root and selecting the oldest child until a leaf is reached.
Returns a vector of all nodes along the main line of the game, beginning with the root and selecting the oldest child until a leaf is reached.
(move-text game
&
{:keys [include-comments? include-variations?]
:or {include-comments? true include-variations? true}})
The move text of the game in short algebraic notation, optionally including comments and variations.
The move text of the game in short algebraic notation, optionally including comments and variations.
(move-tree game)
Returns a tree of UCI move strings for the given game. Mostly useful for inspecting and debugging the tree structure.
Returns a tree of UCI move strings for the given game. Mostly useful for inspecting and debugging the tree structure.
(moves game)
A sequence of all moves along the main line of the game, beginning at the root.
A sequence of all moves along the main line of the game, beginning at the root.
(new-game &
{:keys [white black event site date round result start-fen other-tags]
:or {white "?"
black "?"
event "?"
site "?"
date "?"
round "?"
result "*"
start-fen board/start-fen}})
Creates a new game object with the given PGN tags and start position. The seven standard tags that make up the "Seven Tag Roster" in the PGN standard are supplied by individual keyword parameters, as is the start-fen parameter that is used to specify the initial position of the game. If any further PGN tags are desired, they should be supplied in a sequence of two-element vectors of the form [<tag-name> <tag-value>].
Creates a new game object with the given PGN tags and start position. The seven standard tags that make up the "Seven Tag Roster" in the PGN standard are supplied by individual keyword parameters, as is the start-fen parameter that is used to specify the initial position of the game. If any further PGN tags are desired, they should be supplied in a sequence of two-element vectors of the form [<tag-name> <tag-value>].
(promote-node game & {:keys [node-id]})
Returns a modified game where the node with the given node id (if no node id is supplied, the current node is used) is moved one place to the left among its siblings. If the node is already the leftmost (oldest) child of its parent node, the game is returned unchanged.
Returns a modified game where the node with the given node id (if no node id is supplied, the current node is used) is moved one place to the left among its siblings. If the node is already the leftmost (oldest) child of its parent node, the game is returned unchanged.
(promote-node-to-main-line game & {:keys [node-id]})
Returns a modified game where the node with the given node id (if no node id is supplied, the current node is used) is made the main line among its siblings, i.e. moved to the front of the list of child nodes. If the node is already the leftmost (oldest) child of its parent node, the game is returned unchanged.
Returns a modified game where the node with the given node id (if no node id is supplied, the current node is used) is made the main line among its siblings, i.e. moved to the front of the list of child nodes. If the node is already the leftmost (oldest) child of its parent node, the game is returned unchanged.
(remove-children game & {:keys [node-id]})
Removes all child nodes of a node (by default, the current node), and returns a modified game with the current node set to the node whose children we just removed.
Removes all child nodes of a node (by default, the current node), and returns a modified game with the current node set to the node whose children we just removed.
(remove-node game & {:keys [node-id]})
Removes a node (by default, the current node) from the game, and returns a modified game with the current node set to the parent of the deleted node.
Removes a node (by default, the current node) from the game, and returns a modified game with the current node set to the parent of the deleted node.
(remove-tag game tag-name)
Returns a new game equal to the input game, but with the given tag removed (if it exists).
Returns a new game equal to the input game, but with the given tag removed (if it exists).
(result game)
The result of the game. Should be one of the strings "1-0", "0-1", "1/2-1/2" and "*".
The result of the game. Should be one of the strings "1-0", "0-1", "1/2-1/2" and "*".
(round game)
The tournament round of the game.
The tournament round of the game.
(set-tag game name value)
Returns a new game equal to the input game, but with the given tag set to the given value. If the tag does not exist in the input game, it is added to the end of the tags list.
Returns a new game equal to the input game, but with the given tag set to the given value. If the tag does not exist in the input game, it is added to the end of the tags list.
(side-to-move game)
The side to move at the current game position, :white or :black.
The side to move at the current game position, :white or :black.
(step-back game)
Steps one move backward in the game (goes back to the parent node), and returns the resulting game. The retracted move is not deleted from the game, only the :current-node of the game is changed. If we are already at the beginning of the game, the original game is returned unchanged.
Steps one move backward in the game (goes back to the parent node), and returns the resulting game. The retracted move is not deleted from the game, only the :current-node of the game is changed. If we are already at the beginning of the game, the original game is returned unchanged.
(step-forward game)
Steps one step forward in the game (moves down to the first child node), and returns the resulting game. If we are already at the end of the game, the original game is returned unchanged.
Steps one step forward in the game (moves down to the first child node), and returns the resulting game. If we are already at the end of the game, the original game is returned unchanged.
(tag-value game tag-name)
Returns the value of the given PGN tag in the game, or nil if no such tag exists.
Returns the value of the given PGN tag in the game, or nil if no such tag exists.
(take-back game)
Takes back the move that led to the current node, and returns a game tree with the corresponding node removed and the current node set to the parent. Does nothing if we're already at the beginning of the game.
Takes back the move that led to the current node, and returns a game tree with the corresponding node removed and the current node set to the parent. Does nothing if we're already at the beginning of the game.
(to-beginning game)
Returns a game identical to the input game, except that current-node is set to the root node.
Returns a game identical to the input game, except that current-node is set to the root node.
(to-beginning-of-variation game)
Returns a game identical to the input game, except that we have stepped back until reaching the beginning of the variation containing the previous current node. In other words, we step back until we reach a branch point where the current variation started, or to the root of the game.
Returns a game identical to the input game, except that we have stepped back until reaching the beginning of the variation containing the previous current node. In other words, we step back until we reach a branch point where the current variation started, or to the root of the game.
(to-ecn game
&
{:keys [include-comments? include-variations? binary?]
:or {include-comments? true include-variations? true}})
Exports the game as ECN data, optionally including comments and variations.
Exports the game as ECN data, optionally including comments and variations.
(to-end game)
Returns a game identical to the input game, except that current-node is set to the leaf node obtained by following the main line from the root, i.e. by following the sequence of first children from the root node until a leaf node is reached.
Returns a game identical to the input game, except that current-node is set to the leaf node obtained by following the main line from the root, i.e. by following the sequence of first children from the root node until a leaf node is reached.
(to-end-of-variation game)
Returns a game identical to the input game, except that current node is set to the leaf node obtained by following the current variation to its end, i.e. by following the sequence of first children from the current node until a leaf node is reached.
Returns a game identical to the input game, except that current node is set to the leaf node obtained by following the current variation to its end, i.e. by following the sequence of first children from the current node until a leaf node is reached.
(to-pgn game
&
{:keys [include-comments? include-variations?]
:or {include-comments? true include-variations? true}})
Creates a PGN string from a game, optionally including comments and variations.
Creates a PGN string from a game, optionally including comments and variations.
(to-uci game)
Exports the current game state in a format ready to be sent to a UCI chess engine, i.e. like 'position fen' followed by a sequence of moves.
Exports the current game state in a format ready to be sent to a UCI chess engine, i.e. like 'position fen' followed by a sequence of moves.
(white-elo game)
The Elo of the white player (as an integer), or nil.
The Elo of the white player (as an integer), or nil.
(white-player game)
Name of the white player.
Name of the white player.
(zip-promote-node zipper)
Takes a game tree zipper and returns a zipper for a modified game tree where the current node is promoted one rank among its sibling. If the current node is already the oldest child, returns the original zipper.
Takes a game tree zipper and returns a zipper for a modified game tree where the current node is promoted one rank among its sibling. If the current node is already the oldest child, returns the original zipper.
(zip-promote-node-to-front zipper)
Takes a game tree zipper and returns a zipper for a modified game tree where the current node is promoted to the oldest among its siblings (i.e. made the main line). If the current node is already the oldest child, returns the original zipper.
Takes a game tree zipper and returns a zipper for a modified game tree where the current node is promoted to the oldest among its siblings (i.e. made the main line). If the current node is already the oldest child, returns the original zipper.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close