I’ve found a bug in my program! A bug, in my program…! And I’m a pro hacker, how shameful…! 🙂
Scary, isn’t it… a simple bug, a single character among the thousands of characters in my program… that single character made all the difference between correct behavior and incorrect dito:
If you have been reading this blog, you know about my ‘Segration’ demo program, basically a simulation where a preference for a specific characteristic leads to clustering of agents with similar preferences…
After having implemented the program, and seen results from the simulation that ‘made sense’, i.e. the behavior of the program was more or less as expected, I started to notice some anomalies: for instance: the resulting matrix (location of agents) was not optimal, i.e. there were agents that clearly would have been better off in a different position, but for whatever reason, they didn’t move there, despite an ever increasing number of iterations. The graphical patterns made me uncomfortable, with a gut feeling that there was a problem somewhere….
Furthermore, what struck me as weird was that the top of the board was fairly static, i.e. with very few ‘moves’, while the bottom of the board was very active, with lots of moves..
It took me a few hours of debugging (without a debugger) to figure out what was going on: finally, I found the problem: in my original code, I had the the statement:
if newfoes < foes and newfoes < foemax:
that is, when trying to find a new, better location for an agent, I wanted to make sure that the new spot would provide fewer ‘foes’ than the current, AND that the number of foes would be less than the limit, foemax.
With this code, there was a lot of moves ‘back & forth’, i.e without any improvement of the overall situation.
It took me quite some time of debugging to realize that the problem was the < foemax: changing that to <=, that is, checking if the new position has ‘enemies’ less than, or equal, to the defined limit, made a world of difference, not least importantly, making the program to behave as intended….!
The bottom line: in the digital world, a simple one character mistake can make your entire world to behave erroneously!