This past week, we finished assignment 2. Although we hadn't learned anything about algorithm efficiency yet for the assignment, I had already found myself trying to speed things up throughout the assignment, in any ways that I knew - often trying to implement the most clever strategy or failfast for a game. Overall, the assignment went quite smoothly, and though there was indeed some debugging to be done, I feel that the process of debugging taught me more about my program.
The sudoku game was quite simple to implement - most of the methods were already implemented, and there were very clear instructions on how to implement the last one.
The word ladder game was simple to implement - but we took quite a long time thinking of an effective failfast for the game - as we saw the the text file had almost 100k words, we were thinking of ways to optimize the game's searching so we wouldn't have to go through 100k words every time.
The grid peg solitaire game was actually quite difficult to implement - its implementation was mostly the same as the MN-puzzle's implementation, but we were caught off guard by the fact that our grids would be affected by each swap when creating extensions - so we would create far more extensions than desired. We fixed it with a deepcopy.
The MN puzzle's usage of tuples was quite annoying, as we wanted to change variables within the puzzle for the extensions, but had to go through a convoluted method of creating lists and then changing back into tuples - I feel like there should be a more clever way to solve the problem, but this was the implementation that we went with. Importantly, for the MN puzzle, I used some theory that I picked up on CSC240 and MAT495, proving that there's always an invariant for the puzzle, and thus we implemented an effective fail-fast which could tell immediately whether a puzzle was solvable or not.
Initially, we wanted to use recursion to implement the searches, but we couldn't figure out how to keep track of the visited configurations with recursion - so instead we used the deque and implemented both searches iteratively with a while loop.
Most of the puzzles run quite quickly - the longest would be the sudoku puzzle 2 - which can take up to 2 minutes if we're unlucky, but can take as little as 10 seconds. The other puzzles all take well under 1 minute, many in fractions of seconds.
No comments:
Post a Comment