Ben B.
Ben B.

Reputation: 3826

Print a Tree of Recursion

I am writing minimax as part of a project, but its awfully hard to check that it is working correctly. If I could print a tree of what it does, it would be extremely useful.

Is there an easy way to print a tree of recursive calls, selecting whatever variables are important to the situation?

Upvotes: 1

Views: 1163

Answers (1)

Fred Foo
Fred Foo

Reputation: 363547

Keep track of recursion depth by means of a parameter (in minimax, you'd do that anyway). Then print depth * a small number of spaces, followed by the interesting variables in each call to obtain

player=1, move=...
  player=2, move=...
    player=1, move=...
    ...
  player=2, move=...

You might also want to print the return value of each recursive call.

If you desperately want a pretty picture of a tree, post-process the output of the above and feed it to a tree-drawing package.

Upvotes: 1

Related Questions