public final class NodeUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static ConstNode |
backward(ConstNode node,
int n)
Get node reached by going a number of nodes backward.
|
static SgfProperties |
cleanSgfProps(ConstNode node)
Remove SGF properties for information already contained in game info.
|
static boolean |
commentContains(ConstNode node,
java.util.regex.Pattern pattern)
Check if the comment of the current node contains a pattern.
|
static ConstNode |
findByMoveNumber(ConstNode node,
int moveNumber)
Find first node with a certain move number in main variation
of a given node.
|
static ConstNode |
findByVariation(ConstNode root,
java.lang.String variation)
Get first node of a given variation.
|
static ConstNode |
findInComments(ConstNode node,
java.util.regex.Pattern pattern)
Find next node with a comment containing a pattern in the iteration
through complete tree.
|
static ConstNode |
findNextComment(ConstNode node)
Find next node with a comment in the iteration through complete tree.
|
static ConstNode |
forward(ConstNode node,
int n)
Get node reached by going a number of nodes forward.
|
static ConstNode |
getBackToMainVariation(ConstNode node)
Find the last node that was still in the main variation.
|
static PointList |
getChildrenMoves(ConstNode node)
Get all children moves.
|
static ConstNode |
getChildWithMove(ConstNode node,
Move move)
Get child node containing a certain move.
|
static java.lang.String |
getCommentStart(ConstNode node,
boolean firstLineOnly,
int maxChar)
Get comment, but no more than a maximum number of characters.
|
static int |
getDepth(ConstNode node)
Get depth of a node.
|
static ConstNode |
getLast(ConstNode node)
Get last node in main variation.
|
static int |
getMoveNumber(ConstNode node)
Get the move number of a node.
|
static int |
getMovesLeft(ConstNode node)
Moves left in main variation.
|
static ConstNode |
getNextEarlierVariation(ConstNode node)
Return next variation before this node.
|
static ConstNode |
getNextVariation(ConstNode node)
Return next variation of this node.
|
static int |
getNodesLeft(ConstNode node)
Nodes left in main variation.
|
static void |
getPathToRoot(ConstNode node,
java.util.ArrayList<ConstNode> result)
Get nodes in path from a given node to the root node.
|
static ConstNode |
getPreviousEarlierVariation(ConstNode node)
Return previous variation before this node.
|
static ConstNode |
getPreviousVariation(ConstNode node)
Return previous variation of this node.
|
static ConstNode |
getRoot(ConstNode node)
Get the root node.
|
static java.lang.String |
getVariationString(ConstNode node)
Get a text representation of the variation to a certain node.
|
static boolean |
hasSiblingMoves(ConstNode node)
Check if a node contains a move and has sibling nodes containing other
moves.
|
static boolean |
hasSubtree(ConstNode node)
Subtree of node contains at least one node with 2 or more children.
|
static boolean |
isInCleanup(ConstNode node)
Check if game is in cleanup stage.
|
static boolean |
isInMainVariation(ConstNode node)
Check if a node is in the main variation of the tree.
|
static boolean |
isRootWithoutChildren(ConstNode node)
Check if node is root node and has no children.
|
static boolean |
isTimeLeftKnown(ConstNode node,
GoColor color)
Check that the time left for a color at a node is known.
|
static void |
makeMainVariation(Node node)
Make the variation of the current node to be the main variation
of the tree.
|
static GameTree |
makeTreeFromPosition(ConstGameInfo info,
ConstBoard board)
Create a game tree with the current board position as setup stones.
|
static ConstNode |
nextNode(ConstNode node)
Get next node for iteration through complete tree.
|
static ConstNode |
nextNode(ConstNode node,
int depth)
Get next node for iteration through subtree.
|
static java.lang.String |
nodeInfo(ConstNode node)
Return a string containing information about a node.
|
static void |
restoreClock(ConstNode node,
Clock clock)
Restore the clock to the state corresponding to a node.
|
static ConstNode |
selectRandom(ConstNode root,
int minDepth,
int maxDepth)
Select a random node in the main variation within a certain depth
interval.
|
static boolean |
subtreeGreaterThan(ConstNode node,
int size)
Check if the number of nodes in the subtree of a node is greater
than a given limit.
|
static int |
subtreeSize(ConstNode node)
Count number of nodes in subtree.
|
static java.lang.String |
treeInfo(ConstNode node)
Return a string containing information and statistics of the subtree
of a node.
|
static void |
truncateChildren(Node node)
Remove all children.
|
public static ConstNode backward(ConstNode node, int n)
node
- The start node.n
- The number of moves to go backward.public static SgfProperties cleanSgfProps(ConstNode node)
public static boolean commentContains(ConstNode node, java.util.regex.Pattern pattern)
node
- The node to check.pattern
- The pattern.public static ConstNode findByMoveNumber(ConstNode node, int moveNumber)
node
- The given node.moveNumber
- The move number of the wanted node.null
if
no such node exists.public static ConstNode findByVariation(ConstNode root, java.lang.String variation)
root
- The root node of the tree.variation
- The variation string (e.g. "1.1.3.1.5").null
, if the
variation string is invalid or does not specify a node in the
given tree.public static ConstNode findInComments(ConstNode node, java.util.regex.Pattern pattern)
node
- The current node in the iteration.pattern
- The pattern.public static ConstNode findNextComment(ConstNode node)
node
- The current node in the iteration.public static ConstNode forward(ConstNode node, int n)
node
- The start node.n
- The number of moves to go forward.public static ConstNode getBackToMainVariation(ConstNode node)
public static PointList getChildrenMoves(ConstNode node)
public static ConstNode getChildWithMove(ConstNode node, Move move)
public static java.lang.String getCommentStart(ConstNode node, boolean firstLineOnly, int maxChar)
public static int getDepth(ConstNode node)
node
- The node.public static int getMoveNumber(ConstNode node)
node
- The node.public static int getMovesLeft(ConstNode node)
public static ConstNode getNextVariation(ConstNode node)
public static ConstNode getNextEarlierVariation(ConstNode node)
public static int getNodesLeft(ConstNode node)
public static void getPathToRoot(ConstNode node, java.util.ArrayList<ConstNode> result)
node
- The noderesult
- The resulting path. Passed as an argument to allow
reusing an array list. It will be cleared before it is used.public static ConstNode getPreviousVariation(ConstNode node)
public static ConstNode getPreviousEarlierVariation(ConstNode node)
public static ConstNode getRoot(ConstNode node)
node
- The node.public static java.lang.String getVariationString(ConstNode node)
public static boolean hasSiblingMoves(ConstNode node)
public static boolean hasSubtree(ConstNode node)
public static boolean isInCleanup(ConstNode node)
public static boolean isInMainVariation(ConstNode node)
node
- The node.public static boolean isRootWithoutChildren(ConstNode node)
node
- The node to check.public static boolean isTimeLeftKnown(ConstNode node, GoColor color)
public static void makeMainVariation(Node node)
node
- The current node.public static GameTree makeTreeFromPosition(ConstGameInfo info, ConstBoard board)
public static ConstNode nextNode(ConstNode node)
public static ConstNode nextNode(ConstNode node, int depth)
public static java.lang.String nodeInfo(ConstNode node)
public static void restoreClock(ConstNode node, Clock clock)
node
- The current node.clock
- The clock to update.public static ConstNode selectRandom(ConstNode root, int minDepth, int maxDepth)
root
- The root nodeminDepth
- The minimum depth of the interval (inclusive)maxDepth
- The maximum depth of the interval (inclusive)public static boolean subtreeGreaterThan(ConstNode node, int size)
public static int subtreeSize(ConstNode node)
node
- The root node of the subtree.public static java.lang.String treeInfo(ConstNode node)
public static void truncateChildren(Node node)