/// <summary> /// Recursively expand and build a game tree in a DFS manner /// Ends recursion on opponents turn /// </summary> /// <param name="ParentNode">the node currently to be expanded</param> private void ExpandNode(GameNode ParentNode, int depth = 0) { //if game has ended do not try to expand if (ParentNode.data.State.State != State.RUNNING) { return; } // do not expand the opponent's round if (ParentNode.data.State.CurrentPlayer.PlayerId != _BoundController.PlayerId) { return; } if (depth > MaxDepth) { return; } List <PlayerTask> options = ParentNode.data.State.ControllerById(EntityID).Options(); foreach (PlayerTask task in options) { // first create this node Game GameCopy = ParentNode.data.State.Clone(); GameCopy.Process(task); string GameHash = GameCopy.Hash(); if (EvaluatedPositions.Contains(GameHash)) { continue; } EvaluatedPositions.Add(GameHash); NodeData NewNode = new NodeData(task, GameCopy); NewNode.Evaluation = EvaluateGame(GameCopy); if (NewNode.Evaluation < ParentNode.data.Evaluation) { continue; //don't bother if we are making our situation worse } GameNode node = ParentNode.AddChild(NewNode); //then expand it ExpandNode(node, depth + 1); } }
/// <summary> /// This method adds a child to the node of this model element /// </summary> /// <param name="childNode"></param> public void AddChild(SceneNode childNode) { GameNode.AddChild(childNode); }