Finally submitted A2. There were a few incredibly frustrating bugs I had to deal with for this assignment, one of which plagued me for upwards of 5 hours.
In trying to develop extensions for Grid Peg Solitaire I was accidentally making changes to the state of the puzzle, instead of creating new Puzzle objects and returning a list of said objects. I was puzzled (no pun intended), as I wasn't actively adjusting any of the attributes of self in any of my helper methods, but without fail in each iteration of one of my loops the board state would be altered. I eventually found out that when accessing nested lists, Python only supplies a copy of the first level of depth of the list, every subsequent sub-list is aliased (not copied) which is why I was altering the board state of self. Thankfully as soon as I made the necessary adjustments to my methods everything ran exactly as expected.
The second problem (it wasn't even really a bug) I encountered was slightly less frustrating, as it took a lot less time (and tracing) to correct. My solves were taking a very long time to run, especially for some of the larger puzzles available for testing. I took the advice of some of my peers on Piazza and switched the data structure used for storing already-visited board states to a set. I also realized what a potential use for __repr__ might be (comparing string representations of the current state and all the states stored in the aforementioned set) and so implemented that for my four puzzles. After making this switch my solves took SIGNIFICANTLY less time. A satisfying adjustment.
All in all the assignment took less time than I imagined it might (thankfully, as my being sick for two weeks leading up to it only allowed me about a day to really work on it). I'm expecting a very positive result. Hopefully I'm not disappointed.
No comments:
Post a Comment