February 27, 2015

Week of 02/22/15 - Python Part 21: Finding a Solution

    As we all know, alcohol is a solution. However that's not the kind of solution I'm looking for. What I think I can do to see what the problem is, is printing out the row and column variables after they are set, using the print(row) and print(column) functions. From doing this, I found out that the coordinates of the bottom-left to top-right are (0,2), (1,1), and (2,0). These are the expected values that were discussed in last week's post. So, in theory, this code:
    elif (row + column) == 2:
        if board[0][2] == board[1][1] == board[2][0]:
            if board[0][2] == " X ":
                return 1
            elif board[0][2] == " O ":
                return 2
should work. But, for some reason it doesn't. I don't see any problems with the syntax. But now that I've mulled it over, I see something that may cause me a headache down the line: what if both diagonals are completed at the same time? But then i realized that this was a non-issue because it would choose the one that was further up the elif statement tree. This is also the case with the normal edges. Maybe later I should congratulate the player if he gets a double. But that would take some rewriting of my checking function. But, I think re-writing my checking function would be a good idea anyway, because I have no idea why the other diagonal isn't working. Maybe it's because they share an entry, (1,1). In any case, this problem can probably be solved by rewriting the logic behind the checker.

    To fix the issue I'm having, what I think I'll do is related to something that I saw on reddit a few weeks ago. There was a bug in the game "Team Fortress 2", where sentry guns (automatic turrets) could be exploited to turn back on during a humiliation round, a gamemode after a normal round where the members of the losing team can't fight back, just move around. In the humiliation round the sentry guns of the losing team get disabled. However, the exploit is that if, before the humiliation round, the sentry begins upgrading (which disables the sentry) and when it's done upgrading, the sentry comes back on even though the humiliation round should have disabled them.
    The guy on reddit said "I suspect the sentry has a single flag which is set when it is disabled. For example, by a sapper, by humiliation period, by a building animation, or by soldier lasers. The problem is that these conditions can occur simultaneously." So when the sapper is removed, the game still uses the function to restore the sentry at the end, even though there's another condition which should have kept the sentry disabled. The guy on reddit said that you need to set a separate flag for each condition, so that's what I'm going to do; 1 flag for a horizontal or vertical win, and 1 flag for the diagonals. Unless I want to put in and easter egg for getting 2 wins at the same time. In which case, I would have to make a flag for each: vertical, horizontal, and 2 diagonals. I thought about writing a class for it, but that seems unnecessarily difficult. So what I'm going to do is write a new checker.

No comments: