March 24, 2015

Week of 03/08/15 - Python Part 23: Adding Nothing

    What I've done now is I have created a new file, a test file, to check if the checker works like it should, because I haven't tested it yet. I just made some variables, and used a board that was already filled in with a winning combination,row and board variables that made sense, and a player number. Now, the first problem I ran into when I ran the test for the first time was that for the diagonal checking functions, they had to have two conditions that were true in order for the function to return a 1, and if they weren't it would return a zero. The code read:
    def diag_bl_tr_checker(row, column, board):
        if row == column:
            if board[0][0] == board[1][1] == board[2][2]:
                return 1
            else:
                return 0

    The problem with the code is the first if statement, which checks if the row is equal to the column, and this was also a problem with the other function, which checked if the row added to the column equaled 2. If the first if statement evaluated to false, the code wouldn't return anything, and its addition into the flag_number variable wouldn't work because it was not a number, so it gave an error.
      flag_number =   column_checker(column, board)
                    + row_checker(row, board)
                    + diag_bl_tr_checker(row, column, board)
                    + diag_tl_br_checker(row, column, board)
    Now, the code has an else statement that returns zero at the end, so now it works.

    def diag_bl_tr_checker(row, column, board):
        if row == column:
            if board[0][0] == board[1][1] == board[2][2]:
                return 1
            else:
                return 0
        else:
            return 0

No comments: