![]() |
Forum Index : Microcontroller and PC projects : CMM2 BASIC; Question about recursion
Author | Message | ||||
Lodovik![]() Regular Member ![]() Joined: 17/05/2021 Location: CanadaPosts: 41 |
Hello, I'm currently writing a strategy game in MMBASIC on the CMM2. I already have the minimax search implemented and it sometimes has to go about 15 levels deep. I avoided recursion by unrolling the search algorithm but the code is ugly, non elegant and a nightmare to maintain and optimize. I've read in the forums here about recursion and it seems to be preferable to avoid it when there's a loop involved but I would like some clarification on that, if possible. I would like to know if a function can call itself within a FOR NEXT loop that may exited with an EXIT FOR statement. Is it really different than having a series of functions that call each other in sequence? Most of my game state variables are global. In the MMBasic manual, there's a limit of 50 for the nested functions and subs. I will never have to go near that far. Let's say I need about 20 levels of recursion at max. Is that possible? |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
How well recursion works will depend on the overall program flow, not just any EXIT FOR. I am always happy to use recursion provided it doesn't go too deep. Jim VK7JH MMedit |
||||
Lodovik![]() Regular Member ![]() Joined: 17/05/2021 Location: CanadaPosts: 41 |
So, since I just have to be careful about the depth, I think I will try to convert my ugly code into something neater. Thanks, Jim. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |