N
N
Niobis2015-10-26 18:00:37
Programming
Niobis, 2015-10-26 18:00:37

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

4 answer(s)
A
Alexey Ostin, 2015-10-26
@nitso

There are no secret techniques. But there is Toria Counts
What is your task?

M
Maxim Kudryavtsev, 2015-10-26
@kumaxim

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.

A
Artem Vereschaka, 2015-10-26
@And3en

Also look at such a thing as a state machine . Should help you understand.

A
asArtem, 2015-11-06
@asArtem

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 question

Ask a Question

731 491 924 answers to any question