January 23, 2015

Week of 01/18/15 - Python Part 17: I Guess it's Tic-Tac-Toe

     A week with two class days isn't nearly long enough to do very much with my project, but I did get a few things done. First thing I did on Wednesday was I changed the turn() function so that instead of blacklisting all of the inputs except for the ones that I wanted, I made a whitelist of the possible values. It made it easier, seeing as there were only three things to whitelist, but every other input to blacklist.

     Next, I tried executing my code, but I had a problem: when I input a 3, it would give me an out-of-range error. But I figured that I forgot to subtract 1 from the row and one from the column input, because in Python, lists start at the zeroth term.

     Then I created a function to check if the input coordinate was already occupied by a piece. Or, more accurately, I created a function that checks if the coordinate is not blank, reducing the amount of code I need to write. I also wrote the code which actually changes the board and print the changed board so that I'm not looking at a blank board every time.

     A problem with my code that I found while trying to run my turn() function was that the turn number didn't increment for some reason, and I'm still not sure why it does that. This is important because I use the turn number to calculate which player is currently playing. I might be able to instead increment the variable with a while loop, but I'm not sure.

No comments: