Hi All
I am trying a simple example on GHpython (please see attached) and got stuck at the end of the recursive function by its meaning.
I know it is a kind of a way to stop the recursion but cannot understand the meaning behind the code.
I would be so grateful of someone can explain these lines to me in simple English so I can understand it , thank you so much in advance!!
Well … there’s no adios amigos question around: something (an if clause) to tell the Method that game is over. (see public vars Loops. Loop in the C# above).
Note the usage of the found bool: since lines “srink”" per Loop … is possible to end with tiny segments that are not a very good thing. So a 2nd if is required.
Lesson of the way: in Recursion PRIOR anything else mastermind some safe exit.
Some tips:
In real life a Recursion in most of cases terminates PRIOR the max Loops are reached. Obviously I’m talking with some serious piece of code in mind - not just a few lines,
When you first call the recursion() function you need to pass it an initial line and an integer number for gen, say 10. Now, the function will call itself recursively as long as gen is greater than 0 and before that decrement gen by one.
I think line 25 should read return recursion(newline, gen) though.
Find 5 minutes more for that entry level thingy: Added Wind and Gravity. Spot the obvious: Method SHOULD terminate (in real-life) PRIOR max Loops … if you want some sort of rational results (so mastermind proper exit clauses).
Yes, each time the function is called it, decrements gen by 1, then if gen is still greater than 0, it calls itself with the decremented gen value. Otherwise, if gen is equal to 0, it simply stops and None gets returned, since you’re not returning anything else at the end of the function.
If you don’t decrement gen, than your function will call itself infinitely, but the program will probably stop at the default recursion limit that is set in Python by your OS.