Richard the 7th Posted November 2, 2020 Share Posted November 2, 2020 Does anyone have example code for a minefield explosion or similar? IE you have one mine explode and if it is next to another mine then that one will explode which triggers any mines next to that one explode and so on. Here is another issue I have. Using negative numbers refuses to play ball no matter how many times I ask it. I have a set of numbers in a loop that goes something like. -33,-32,-31,-1,1,31,32,33 It works fine but when it gets to 1, 31,32,33 it goes bonkers. But if I get rid of the - signs it works but then the negative portion is jacked. Quote Link to comment Share on other sites More sharing options...
Bruce Tomlin Posted November 4, 2020 Share Posted November 4, 2020 (edited) Recursion is dangerous on a system with limited RAM, because it pushes more than the state you're keeping track of, so you could easily be using twice the RAM just from return addresses. What you need is to make a list of just the things you're keeping track of, add to it every time you have a new one to explore, then when you finish each one, pick the last one on the list and do that next. Technically it's a stack, it's just not the CPU stack. And it's easier to know when the list is full and abort. Something may get missed, but at least you won't crash. As for negative numbers, you do know how 2s-complement math works, right? Numbers can't be just anything, they're words, bytes, whatever, and you have to know how big they are. You don't just have "a set of" "numbers". It's meaningless without knowing how many bits they are. Edited November 4, 2020 by Bruce Tomlin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.