- Home /
Decision tree without a ton of if else statements
I have a classic tree structure situation on my hands. If A is true d and f are now available and B, C, and E are no longer available or vise versa. What is the best way to do this on a large scale?
Answer by JVene · Sep 04, 2018 at 05:52 PM
You're rejecting an answer already given on another thread you launched. The answer is to implement boolean relationships in the data, and build code that can read those relationships and make the decisions based on data. The data itself can identify the yes/no matching criteria, and the code need only read that and implement the decisions. The complete 'tree' of relationships thus emerges from the data. The code is merely processing that data to find what matches are valid and which are invalid.
Think about your question for a few minutes. Your question actually outlines the solution (that's a peculiar property of most classical logical problems, a careful statement of the problem happens to outline the solution). You actually gave an outline in your query, by showing data having attributes of matching properties. 'A' being true provides the properties that 'd' and 'f' are matches, but 'B', 'C' and 'E' are not. You've just listed the database I'm telling you about (now on a second question of the same nature), where A has a list of D and F as matches. It nearly makes an English description of an XML data entry. The fact A doesn't list B, C and E indicate they are not matches. That does it. In data, not code. You just need to 'see' it.
I'm obviously struggling to understand what your trying to explain to me. So ins$$anonymous$$d of trying to berate me with mile long explanations, why don't you give me an actual code example that I can understand.
@$$anonymous$$derbuns, I've given an example in the previous question a few $$anonymous$$utes ago. When you see it, and think about it a bit, you'll realize a short snippet (contrary to the comment on a previous answer that it was too long to post), it is short, and can deter$$anonymous$$e matches for any volume of data, though I've used a List assu$$anonymous$$g the match list is small, it could be a Dictionary for better performance.
Answer by Rexidecimal · Sep 04, 2018 at 05:27 PM
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch
Switch should work for you if i get your meaning
A switch state would work, but I am looking for a solution with a little more finesse.
The switch statements be get large very quickly and would lack easy scale-ability.
Answer by UnityCoach · Sep 04, 2018 at 05:39 PM
You can use Animator State Machines, with StateMachineBehaviour. This allows you to visualise things, and edit everything without much coding, by simply adding transitions from a state to another. Although, it'll take a bit of coding ahead.
Not within a single answer. I've been considering pulling a tutorial about this for some time. If you're familiar with Animator Controller, it's fairly simple actually.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
An OS design issue: File types associated with their appropriate programs 1 Answer
When to use a factory? 0 Answers
how to planning n designing game structure/architecture? 0 Answers