+ 1

I need help solving my code problem

Hello there. I've recently written a program in which computer thinks and plays a game itself. When I run the code, it does a very good job, but after a few movements it stops working and python gives me an expression like"0x000078***" I've used recursive functions in my code.(I've maximized recursion depth) Could it be because of my old laptop system? Do you have any suggestions friends?

14th Mar 2023, 12:53 PM
Javad
5 odpowiedzi
+ 4
If you override the maximum recursion depth, and your function repeatedly calls itself, then it will keep consuming more and more memory until the system runs out of ram. The best suggestion without seeing your code: try to rewrite it using an iterative method, ie. a while loop. Or make sure to contain your recursion within sane limits.
14th Mar 2023, 6:32 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Did you check if the function itself works correctly? Sometimes reaching the max. recursion depth is a sign that there is an issue with the function.
14th Mar 2023, 7:44 PM
Lisa
Lisa - avatar
+ 2
Javad you can find a few ideas here https://stackoverflow.com/questions/46552499/convert-recursive-function-into-a-for-loop-and-while-loop But I can only really help you if I see the actual code.
14th Mar 2023, 8:42 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Lisa the thing is it works good for a few steps. So I don't think that there would be any problem with my function
14th Mar 2023, 8:23 PM
Javad
0
Would you tell me how to apply a while loop to rewrite it?
14th Mar 2023, 8:19 PM
Javad