Answer the question
In order to leave comments, you need to log in
How to implement a decision graph?
What is meant by the words "implement a decision graph"?
Those. I have a graph of options drawn on my sheet:
1 -> 2 -> 4 -> victory.
______ -> 5 -> 7 -> defeat.
__-> 3 -> 6 -> win.
Those. the program may take different paths, perhaps overlapping, perhaps not. Do I understand correctly that the implementation is to describe all these options using branch statements (if-else-switch etc.)? Or are there some secret programming techniques that allow you to do this: maybe a special data type that would allow you to change this tree dynamically?
upd: I'll clarify. Not really "the program can go different ways". The path is always the same, but the action is different. I'm trying to implement a bot for a game that would analyze the moves made and make its own.
Answer the question
In order to leave comments, you need to log in
There are no secret techniques. But there is Toria Counts
What is your task?
The only "secret" technique that comes to my mind here is the " Chain of Responsibility " pattern, instead of your if - elseif - else - switch - case -default , which will be in huge numbers in graphs ...
Although these are implementation details, the theory itself graphs does not change.
Also look at such a thing as a state machine . Should help you understand.
For starters, this is not a graph at all. This is a tree. A young programmer decided to write a game? Commendable, well done.
However, the approaches are similar. Google information on the topics "tree traversal", "graph traversal". An example of a traversal is either breadth-first search or depth-first search.
And there and there the principle is recursion (this is when you enter the same method inside the same method).
God forbid if-else. If the graph or tree is dynamic and changes from 100 to 1,000,000 branches, will we describe all 1,000,000?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question