I've finally managed to finish A1 over the course of the last week. Everything seems to be working smoothly and there don't appear to be any bugs (fingers crossed!), so I'm happy with the end result of my program. It's pretty amazing how three weeks ago I had very little idea of where to even begin--this huge pile of code was just basically sitting there, waiting to be sorted out. Even now, I still don't quite understand the details of GUIController (what exactly does lambda do, and how does Python create a graphical version of the game?), which I hope to solve by learning about graphic interfaces and more of Python's built-in functions and keywords.
Perhaps the greatest challenge I encountered during the course of A1 was writing the Tour.py module. We had previously been shown a function for solving (impressively, in three lines) the Tower of Hanoi problem, and I initially planned to base my tour_of_four_stools method on that solution with minor adjustments. My first draft was almost identical to the original solution (i.e. three recursive calls to tour_of_four_stools with a base case of move(source, dest), the only difference being the addition of an extra stool in the parameter and setting a value i as equal to the ceiling of n/2), but I found out to my surprise that it would only work properly with four or fewer cheeses. I went back to the assignment sheet and realized that if I replaced the second line of my method with that of the code for three stools, the entire method would work. I ended up with two separate methods (one for three stools and one for four stools, which called the former method) just to come up with a solution for Tour, but it worked perfectly and returned the optimal number of moves. As it turns out, my first implementation of tour_of_four_stools would eventually force a bigger cheese to stack onto a smaller cheese, causing the program to raise an IllegalMoveError.
Looking at others' Piazza posts and SLOGs, I got the sense that I wasn't alone in finding Tour difficult to code, so that's reassuring. As a side note, I did have trouble with my time.sleep() function which very few people seemed to have. I tried importing the sys module and using write(), but I just could not get time.sleep() to work properly on my computer.
Besides A1, I was introduced to binary trees in class this week. The premise seems simple enough: a tree is comprised of a parent node with(out) several other child nodes that may or may not have their own child nodes. This concept is very closely related to recursion, as seen in its preorder, postorder, and inorder traversal methods. Its structure made me wonder if trees could possibly play a role in creating lighting effects in video games or CGI, as each node could point to a different shade or color. Either way, I hope to read more about the use and purpose of trees in computer science.
Sunday, February 16, 2014
Sunday, February 9, 2014
Week 5: A1, continued...
Finally finished the entire TOAHModel module and managed to get the GUI version of the game working (how it works, though, is beyond me). Going back to my previous question about number_of_moves, I decided to resolve that problem by simply passing in an empty list when initializing MoveSequence. The first time I played the game, I noticed that it would allow you to stack a bigger cheese on a smaller cheese, which wasn't right; as it turns out, I forgot to raise an IllegalMoveError in the event of an illegal move, and once that was fixed, the game was 100% functional.
As for new developments...I've began work on ConsoleController and I'm sort of confident that everything is working as intended. The main thing that stumped me was user input--that is, in what form move commands were to be entered. Initially, I experimented with commas and lists (which really did not work out!) but found it too confusing and annoying to figure out, so I opted with just numbers separated by a space (something along the lines of 2 3, 4 1, 5 8....and so on) which was then split to create a list. Once that was out of the way, everything in ConsoleController fell into place: I quickly finished play_loop and by then, the only thing I really had left was Tour.py (which I still refrained from thinking about).
I haven't really been looking at others' SLOGs at this point, but from what I can see on Piazza, a lot of people have technical questions about A1 and not many are stuck with actual programming.
As a last note, I did some digging into this four-stool problem and found a Wikipedia page on the Tower of Hanoi (http://en.wikipedia.org/wiki/Tower_of_Hanoi). The four-stool variant is called Reve's puzzle, and unlike TOH, researchers are still working toward discovering an optimal solution to the number of steps. I just thought it was pretty interesting how Reve's solution included a portion of the TOH solution.
As for new developments...I've began work on ConsoleController and I'm sort of confident that everything is working as intended. The main thing that stumped me was user input--that is, in what form move commands were to be entered. Initially, I experimented with commas and lists (which really did not work out!) but found it too confusing and annoying to figure out, so I opted with just numbers separated by a space (something along the lines of 2 3, 4 1, 5 8....and so on) which was then split to create a list. Once that was out of the way, everything in ConsoleController fell into place: I quickly finished play_loop and by then, the only thing I really had left was Tour.py (which I still refrained from thinking about).
I haven't really been looking at others' SLOGs at this point, but from what I can see on Piazza, a lot of people have technical questions about A1 and not many are stuck with actual programming.
As a last note, I did some digging into this four-stool problem and found a Wikipedia page on the Tower of Hanoi (http://en.wikipedia.org/wiki/Tower_of_Hanoi). The four-stool variant is called Reve's puzzle, and unlike TOH, researchers are still working toward discovering an optimal solution to the number of steps. I just thought it was pretty interesting how Reve's solution included a portion of the TOH solution.
Subscribe to:
Posts (Atom)