Sleeping and problem solving
Friday, December 10th, 2010
I went to bed ruminating on some of the bugs in my tic-tac-toe code and when I woke up this morning I had answers! Sleep, it is like magic. What I fixed…
- I couldn’t figure out why the game didn’t restart. It was just a matter of resetting the boolean that denoted a game had ended. Simple.
- I simplified the array code by using the push() method instead of a counter. Considering I was already using the pop() method, I’m shocked I didn’t do it before. I blame sleep deprivation.
After those fixes were implemented, more bugs popped up…
- The computer would overwrite a taken square. Turns out that my forking code had syntax errors: I wasn’t ending some methods with parentheses and so they weren’t behaving as they should have.
- The human player would win. Again, this went back to the fork code. The above fixes improved that situation.
Overall, I’m pretty excited about having written my first JavaScript game, simple as it may be. I think I will continue to work on it because I have a lot of ideas on how to make it more exciting, meaning more video game like. When I’m done, I’ll put it up as a sample on my personal website which sorely needs updating.