Recursive functions and program oddness

BlitzMax Forums/BlitzMax Programming/Recursive functions and program oddness

peltazoid(Posted 2007) [#1]
Hi, I have written a program that will determine possible moves in a board style game. When I was testing on a small grid it works fine and solves the board. As soon as I upped the scale to a larger board (18x18) after a random amount of time I start to get some odd behavior.

i'm sorry I would rather not paste the source here, but when I get chance I will post a similar test rig as it were that mimics my program.

How my program works tho.

I have a list of unused pieces, this is a 4x4 array (each piece has 4 sides and 4 rotations)

I have the gameboard which is a 18x18 array holding a type which in turn holds the pieces and what rotation they are played in.

There is also a node type, which holds piece and state data for the main function

A basenode is created and passed to the main function along with starting coords (0,0)

My main function does the following
Creates a list of possible pieces to fit in that square
if there was not fits then the function returns.
there was a ft, the first of these is used and played on the board and removed from the free list.
If there are no rotations left to use the piece is removed from the possible list.

a node is created
the coords are updated for the next cell
should the beyond the last element be reached then done is set and the program returns.
Otherwise the main function then calls it self with the new node and the next coords

a flag is set to say a return has occoured
when the function returns, the new_node is Nulled as it is no longer needed.

This continues until either the no fits are found at all and the program exits or the board is solved and the output displayed.

For testing and debugging, I placed graphical output commands in the main function to display what pieces had been played.

Also outputting the amount of ram used.

The odd behavior is that the the program uses 99% of cpu time and if the output window is minimised or has another window put over it, it no longer updates (flip is called in the main loop, straight after the drawing commands) but If i'm running with the debugger the debug output continues.

After around 30mins of execution the output also stops, if running in the ide, then that can stop responding as well.

Memory used is at around the same level, it does not run away, it peaks then falls always to the same values depending on how many nodes have been generated.

I have complied with blitz 1.24 and tried 1.22 to the same outcome. I have also tried it on two different machines same results.

Any suggestions as to why this is happening?

Thanks.


ninjarat(Posted 2007) [#2]
I don't really know, but it sounds like you're either sticking yourself in an infinite loop, not handling events properly (that is if you're coding on system level,) or causing a memory exception which apparently doesn't crash. I've had those, so I know they're real. Sorry I couldn't be more helpful. Maybe show us some source code?


Dreamora(Posted 2007) [#3]
Minimizing a window will always stop the graphics to update as there is no gadget redraw done anymore.

Check for AppSuspended() AppResumed() to prevent running into this kind of problem.

99% of CPU used does sound like you tried to follow any acceptable program design. If you try to stick with the CPU time you need and give the rest back to the system, some of the problems will disappear as well.
The simplest way to do so is doing event based programming.