March 9, 2015

Week of 03/01/15 - Python Part 22: Rewrite

    To fix the issue outlined in last week's post, what I first did was remove each checker from the if statement, and put each checker into it's own function. I also made the function return zero if there are no wins on the board. Then, I removed their ability to distinguish between player, because this checker checks the board after the player places their piece, so the player_number variable should be sufficient for the new checker function. Now what the individual checking functions do is they each return whether or not they evaluate to true, and if so, they return a 1. If it's not, the function will evaluate to 0. I could have used a true or false, but those wouldn't be able to be manipulated in the way I need to.
    def column_checker(column, board):
        if board[0][column] == board[1][column] == board[2][column]:
            return 1
        else:
            return 0

    Now, all of the functions that were written look like the one shown above. Then, for the actual checking function, I add them all up and see if the resulting number is greater than or equal to 1, at which point the game will say congratulations and then it will end. I have also decided to make a little easter egg where if the player gets more than 1 three-in-a-row at the same time, it would print ASCII art to the terminal. I wouldn't make it myself because I don't know how, so I'll find some on the internet.

No comments: