September 11, 2012

King Bug Fix for Vulcan 3D Chess

While testing a prototype game save feature for Vulcan, I ran into a nasty little bug. I would move my king off of it's attack board, the program would start 'thinking', and then it would crash. The crash was at an assertion indicating that the program couldn't find my king anywhere on the board.

After much investigation, which among other things included rerunning the same move a zillion times and adding an ASCII print of the entire board at a couple of points just before the crash, the problem became apparent. I found that the program had 'imagined' that its queen had captured my king as part of it's 'thinking' process. From there, tracing back through a long chain of function calls turned up the bug. There seemed to be nothing to keep the program from considering moves where one of its pieces would capture the king. Adding an additional condition to an existing 'if' statement squashed the bug.

I've gotta say, I got lucky in the timing of finding this bug. It would have taken a lot longer to fix without having already implemented an ability to return to the game state just before the crash.

No comments:

Post a Comment