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.