Thursday, 5 March 2015

Submit -> Now what?

I am very pleased to say that I have finally finished Assignment 2. This accomplishment would not have felt remotely as awesome if there was no struggle involved in the process. Being a Varsity Athlete helps me understand that there is no reward without struggle, medals and accolades are meaningless with the effort that brought you to that point.

The effort I expended on Assignment 2 was far greater than that with Assignment 1. Starting to work on it weeks before it was due allowed me time to thoroughly think through the implementation. I'm very glad that I gave myself this much time because just this morning, 12 hours before it's due, I finally figured out why pep8 wasn't running correctly. This was the easiest bug to fix by far, but it's nice to reflect on all the points when I stumbled in order to truly appreciate finishing this Assignment.

My first real problem was with my method is_tippy() which checks if a board has a tippy on it. Up until that point, I was coding tippy_game_state and tippy_move while referencing subtract_square_state and subtract_square_move. Having code to reference is fantastic because as long as you have an idea of what you want to happen, the format exists and helps you formulate exactly how you want to implement a certain idea. Then I reached the first big catch, how do you tell when the game is over?

Subtract Square is easy, if current_total == 0... ta da, game over. Or even if there are no more possible moves. Tippy on the other hand, it could be over in the first 4 moves, even on a 10x10 board. After realizing the middle square of a 3x3 had to be used for a Tippy I generalized this for an nxn board, only checking the interior squares and their surrounding 3x3 neighbours. I then wrote code checking for each of the 8 possibilities on that smaller 3x3 board.

What I had in the end was a humongous block of unreadable code, if you didn't write it, you wouldn't understand what it did. After a while of staring at it I realized there was a lot of room for optimization. Taking out a line here, adding an if statement there, it slowly but surely reduced the number of lines needed. This process took a couple days as each time I thought I was finished with it, I'd put the project aside and then look at it tomorrow, only to realize that I had overlooked something. Eventually I got it down to it's current state and am quite satisfied as I proved to myself mathematically that it's impossible to optimize any further.

Another choke point to this assignment was mentioned in an earlier post, recursively changing the game state. To summarize when you popped back up a level in the recursive tree, the game state was still like it was in the leaf, so it returned an empty list error since there were no more possible moves. For more details see my post titled 'A Late Night With Recursion'.

My most recent error was dealing with pep8. For the longest time I couldn't figure out why it wasn't working, so I posted on Piazza.com. This morning someone replied with a cryptic remark about apostrophes. Instead of giving up hope I looked back through old questions on Piazza and eventually found exactly what I was looking for, the same question I had just asked, but this time with a much easier to understand answer. In essence the line of code to ask pep8 to check a file contained a weird stylized quotation mark which wasn't read by Wing101. So I deleted them and replaced them with my own quotation marks, and pep8 ran as expected.

So finally, after a long and arduous process, Assignment 2 is complete. I wouldn't have done it any other way. Which leaves me wondering... what should I do next?

No comments:

Post a Comment