-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from ftc16072/debugBehaviorTrees
Adding debugging for behavior trees
- Loading branch information
Showing
6 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/Util/DebugTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.Util; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Stack; | ||
|
||
public class DebugTree { | ||
static class NodeInfo { | ||
int indent; | ||
public Node node; | ||
Node.State state = Node.State.RUNNING; | ||
|
||
NodeInfo(int indent, Node node){ | ||
this.indent = indent; | ||
this.node = node; | ||
} | ||
|
||
@NonNull | ||
public String toString(){ | ||
String prefix = new String(new char[indent]).replace("\0", "-"); | ||
String name = node.getClass().getSimpleName(); | ||
|
||
switch(state){ | ||
case FAILURE: | ||
return prefix + name + ":F\n"; | ||
case SUCCESS: | ||
return prefix + name + ":S\n"; | ||
case RUNNING: | ||
return prefix + name + ":R\n"; | ||
} | ||
return ""; | ||
} | ||
} | ||
List<NodeInfo> nodeInfoList; | ||
Stack<Node> parents = new Stack<>(); | ||
|
||
public DebugTree(){ | ||
reset(); | ||
} | ||
public void reset(){ | ||
nodeInfoList = new LinkedList<>(); | ||
parents = new Stack<>(); | ||
} | ||
public void startParent(Node parent){ | ||
parents.push(parent); | ||
} | ||
|
||
public void addNode(Node node){ | ||
nodeInfoList.add(new NodeInfo(parents.size(), node)); | ||
} | ||
|
||
public void updateNode(Node node, Node.State newState){ | ||
if (node == parents.peek()){ | ||
parents.pop(); | ||
} | ||
for (NodeInfo nodeInfo : nodeInfoList){ | ||
if(nodeInfo.node == node){ | ||
nodeInfo.state = newState; | ||
} | ||
} | ||
} | ||
|
||
@NonNull | ||
public String toString(){ | ||
StringBuilder retString = new StringBuilder(); | ||
for(NodeInfo nodeInfo : nodeInfoList){ | ||
retString.append(nodeInfo.toString()); | ||
} | ||
return retString.toString(); | ||
} | ||
} |