February 17, 2015

Week of 02/08/15 - Python Part 19: Lots of Work was Done

     Usually, I don't really do a lot of work in Independent Study. But this week is quite the exception. What I did was finish a game-checking script, so after every move, it checks the entire row, column, and if the move was on one of the diagonals, it would check the diagonals. I got this idea after reading some forums, and figured it would be a great alternative to checking each and every row, column, and diagonal every turn. The checker took a lot of work to write, with me having to define what should happen if player 1 wins or if player 2 wins. Also, instead of putting the checker() function inside of the turn() function, I decided to put the checker function as part of the for-loop instead, and made it so that the checker function only runs when the for-loop reaches 5 or more loops. To do this, I also had to move the variables row and column from the turn function, and made it go from:
def turn(i, playing):        
    Column=0                 
    Row=0                    
    (More code here)         

for i in range(1,10):        
    turn(i, playing)         

To:
for i in range(1,10):
    column = 0
    row = 0
    turn(i, playing, column, row)
    if i >= 5:
        checked = checker(i, playing, column, row, board)

    Next what I did was I combine the two files, main.py and definitions.py. I did this partially because I was having some issues with imported functions not working right, and because I thought it would be easier to debug than two separate files. This came with some renaming and restructuring of the combined file. I also accidentally saved the file to two different directories, but I used the unix command, diff, to figure out which was newer.

No comments: