• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursive Problem.

 
Jon Bud
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've ended up changing the else's to if there by allowing the program to run through each case in effect. But, when I run this program the console window doesn't pop up. I'm sure that this is because the program is in sort of an infinite recursion type situation. I guess I have to some how have the return value of the method triggger the stoppage of the function so I don't get caught in a loop. I don't know how to do this though. Does anyone have any suggestions. Do I have to return true each time one of the if blocks is done calling the traverse method? Should I check if the space has been traversed already?

















 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I have to return true each time one of the if blocks is done calling the traverse method? Should I check if the space has been traversed already?

The if-conditions are not sufficient for controlling the recursion. They should not evaluate to "true" if "board[ver][hor]" already has a value, because that would mean that the the field is about to be stepped on a second time.

So you need to initialize all the values of the board to some value that "count" can never take (maybe -1), and then check that value as part of the if-condition.

What do you mean calling "return true"?

That's actually not crucial, as long as the if conditions check for not stepping on a field a second time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic