Package featurecat.lizzie.rules
Class BoardHistoryNode
- java.lang.Object
-
- featurecat.lizzie.rules.BoardHistoryNode
-
public class BoardHistoryNode extends java.lang.Object
Node structure for the board history / sgf tree
-
-
Constructor Summary
Constructors Constructor Description BoardHistoryNode(BoardData data)
Initializes a new list node
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoardHistoryNode
add(BoardHistoryNode node)
Sets up for a new node.BoardHistoryNode
addOrGoto(BoardData data)
If we already have a next node with the same BoardData, move to it, otherwise add it and move to it.BoardHistoryNode
addOrGoto(BoardData data, boolean newBranch)
If we already have a next node with the same BoardData, move to it, otherwise add it and move to it.BoardHistoryNode
childAtDepth(int depth)
Given some depth, returns the child at the given depth in the main trunk.void
clear()
Remove all subsequent nodes.void
deleteChild(int idx)
int
depthOfNode(BoardHistoryNode childNode)
Given a child node, find the depth of that child node in its parentjava.util.Optional<BoardHistoryNode>
findChildOfPreviousWithVariation()
Find first move with variations in tree above node.int
findIndexOfNode(BoardHistoryNode childNode, boolean allSub)
Given a child node, find the index of that child node in its parentBoardHistoryNode
findTop()
Find top of variation (the first move that is on the main trunk)java.util.Optional<BoardHistoryNode>
firstParentWithVariations()
Finds the first parent with variations.BoardData
getData()
int
getDepth()
Returns the number of moves in a tree (only the left-most (trunk) variation)int
getFromBackChildren()
java.util.Optional<BoardHistoryNode>
getVariation(int idx)
java.util.List<BoardHistoryNode>
getVariations()
int
goToNextNodeWithComment()
Go to the next node with the comment.int
goToPreviousNodeWithComment()
Go to the previous node with the comment.boolean
hasDepth(int depth)
Check if there is a branch that is at least depth deep (at least depth moves)boolean
hasVariations()
int
indexOfNode(BoardHistoryNode childNode)
Given a child node, find the index of that child node in its parentboolean
isFirstChild()
boolean
isMainTrunk()
Check if node is part of the main trunk (rightmost branch)void
moveChildDown(BoardHistoryNode child)
void
moveChildUp(BoardHistoryNode child)
void
moveDown()
int
moveNumberInBranch()
The move number of that node in its branchint
moveNumberOfNode()
The move number of that nodevoid
moveUp()
java.util.Optional<BoardHistoryNode>
next()
int
numberOfChildren()
java.util.Optional<BoardHistoryNode>
previous()
void
resetMoveNumberList(int start)
void
resetMoveNumberListBranch(int start)
void
setFromBackChildren(int fromBackChildren)
void
swapMoveNumberList(BoardHistoryNode child)
BoardHistoryNode
topOfBranch()
-
-
-
Constructor Detail
-
BoardHistoryNode
public BoardHistoryNode(BoardData data)
Initializes a new list node
-
-
Method Detail
-
clear
public void clear()
Remove all subsequent nodes.
-
add
public BoardHistoryNode add(BoardHistoryNode node)
Sets up for a new node. Overwrites future history.- Parameters:
node
- the node following this one- Returns:
- the node that was just set
-
addOrGoto
public BoardHistoryNode addOrGoto(BoardData data)
If we already have a next node with the same BoardData, move to it, otherwise add it and move to it.- Parameters:
data
- the node following this one- Returns:
- the node that was just set
-
addOrGoto
public BoardHistoryNode addOrGoto(BoardData data, boolean newBranch)
If we already have a next node with the same BoardData, move to it, otherwise add it and move to it.- Parameters:
data
- the node following this onenewBranch
- add a new branch- Returns:
- the node that was just set
-
getData
public BoardData getData()
- Returns:
- data stored on this node
-
getVariations
public java.util.List<BoardHistoryNode> getVariations()
- Returns:
- variations for display
-
previous
public java.util.Optional<BoardHistoryNode> previous()
-
next
public java.util.Optional<BoardHistoryNode> next()
-
topOfBranch
public BoardHistoryNode topOfBranch()
-
numberOfChildren
public int numberOfChildren()
-
hasVariations
public boolean hasVariations()
-
isFirstChild
public boolean isFirstChild()
-
getVariation
public java.util.Optional<BoardHistoryNode> getVariation(int idx)
-
moveUp
public void moveUp()
-
moveDown
public void moveDown()
-
moveChildUp
public void moveChildUp(BoardHistoryNode child)
-
moveChildDown
public void moveChildDown(BoardHistoryNode child)
-
swapMoveNumberList
public void swapMoveNumberList(BoardHistoryNode child)
-
resetMoveNumberListBranch
public void resetMoveNumberListBranch(int start)
-
resetMoveNumberList
public void resetMoveNumberList(int start)
-
deleteChild
public void deleteChild(int idx)
-
setFromBackChildren
public void setFromBackChildren(int fromBackChildren)
- Parameters:
fromBackChildren
- the fromBackChildren to set
-
getFromBackChildren
public int getFromBackChildren()
- Returns:
- the fromBackChildren
-
getDepth
public int getDepth()
Returns the number of moves in a tree (only the left-most (trunk) variation)- Returns:
- number of moves in a tree
-
childAtDepth
public BoardHistoryNode childAtDepth(int depth)
Given some depth, returns the child at the given depth in the main trunk. If the main variation is too short, silently stops early.- Returns:
- the child at the given depth
-
hasDepth
public boolean hasDepth(int depth)
Check if there is a branch that is at least depth deep (at least depth moves)- Returns:
- true if it is deep enough, false otherwise
-
findTop
public BoardHistoryNode findTop()
Find top of variation (the first move that is on the main trunk)- Returns:
- top of variation, if on main trunk, return start move
-
firstParentWithVariations
public java.util.Optional<BoardHistoryNode> firstParentWithVariations()
Finds the first parent with variations.- Returns:
- the first parent with variations, if any, Optional.empty otherwise
-
findChildOfPreviousWithVariation
public java.util.Optional<BoardHistoryNode> findChildOfPreviousWithVariation()
Find first move with variations in tree above node.- Returns:
- The child (in the current variation) of the first node with variations
-
indexOfNode
public int indexOfNode(BoardHistoryNode childNode)
Given a child node, find the index of that child node in its parent- Returns:
- index of child node, -1 if child node not a child of parent
-
findIndexOfNode
public int findIndexOfNode(BoardHistoryNode childNode, boolean allSub)
Given a child node, find the index of that child node in its parent- Returns:
- index of child node, -1 if child node not a child of parent
-
depthOfNode
public int depthOfNode(BoardHistoryNode childNode)
Given a child node, find the depth of that child node in its parent- Returns:
- depth of child node, 0 if child node not a child of parent
-
moveNumberInBranch
public int moveNumberInBranch()
The move number of that node in its branch- Returns:
- move number of node, 0 if node not a child of branch
-
moveNumberOfNode
public int moveNumberOfNode()
The move number of that node- Returns:
- move number of node
-
isMainTrunk
public boolean isMainTrunk()
Check if node is part of the main trunk (rightmost branch)- Returns:
- true if node is part of main trunk, false otherwise
-
goToNextNodeWithComment
public int goToNextNodeWithComment()
Go to the next node with the comment.- Returns:
- the move count to the next node with comment, 0 otherwise
-
goToPreviousNodeWithComment
public int goToPreviousNodeWithComment()
Go to the previous node with the comment.- Returns:
- the move count to the previous node with comment, 0 otherwise
-
-