/// <summary> /// Removes the given child of node. /// </summary> /// <param name="child">Child to remove</param> public void RemoveChild(GameTreeNode child) { if (!Branches.RemoveNode(child)) { throw new InvalidOperationException("Cannot remove child: The given node is not a child of current node"); } }
/// <summary> /// Creates a game tree with a given ruleset /// </summary> public GameTree(IRuleset ruleset, GameBoardSize boardSize) { Ruleset = ruleset; BoardSize = boardSize; GameTreeRoot = new GameTreeNode(); GameTreeRoot.BoardState = new GameBoard(boardSize); GameTreeRoot.GroupState = new GroupState(ruleset.RulesetInfo); LastNode = GameTreeRoot; }
/// <summary> /// Creates a game tree with a given ruleset and root /// </summary> /// <param name="ruleset">Ruleset</param> /// <param name="boardSize">Board size</param> /// <param name="gameTreeRoot">Root</param> public GameTree(IRuleset ruleset, GameBoardSize boardSize, GameTreeNode gameTreeRoot) { Ruleset = ruleset; BoardSize = boardSize; GameTreeRoot = gameTreeRoot; var lastNode = gameTreeRoot; while (lastNode.NextNode != null) { lastNode = lastNode.NextNode; } LastNode = lastNode; }
public static StoneColor GetOpponentColor(this StoneColor color, GameTreeNode prevNode, GameTreeNode root) { if (color == StoneColor.White) { return(StoneColor.Black); } else if (color == StoneColor.Black) { return(StoneColor.White); } else { if (prevNode.Equals(root)) { return(StoneColor.Black); } else { return(StoneColor.White); } } }
/// <summary> /// Implementation of adding a new node into the primary timeline of the tree /// </summary> /// <param name="move">Added move</param> /// <param name="boardState">State of the board</param> /// <param name="groupState">Group state associated with that board state.</param> /// <returns></returns> private GameTreeNode AddMoveToEndInternal(Move move, GameBoard boardState, GroupState groupState) { GameTreeNode node = new GameTreeNode(move) { BoardState = boardState, GroupState = groupState }; LastNode.Branches.Insert(0, node); node.Parent = LastNode; node.Prisoners.BlackPrisoners = node.Parent.Prisoners.BlackPrisoners; node.Prisoners.WhitePrisoners = node.Parent.Prisoners.WhitePrisoners; if (move.WhoMoves == StoneColor.Black) { node.Prisoners.BlackPrisoners += move.Captures.Count(); } else { node.Prisoners.WhitePrisoners += move.Captures.Count(); } LastNode = node; return(node); }