Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:17 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 BASIC; Question about recursion

Author Message
Lodovik

Regular Member

Joined: 17/05/2021
Location: Canada
Posts: 41
Posted: 12:11am 07 Sep 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 6283
Posted: 02:06am 07 Sep 2021
Copy link to clipboard 
Print this post

  Quote  I would like to know if a function can call itself within a FOR NEXT loop that may exited with an EXIT FOR statement


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: Canada
Posts: 41
Posted: 05:06am 07 Sep 2021
Copy link to clipboard 
Print this post

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.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025