This week, we submitted our second assignment, and what a roller coaster it has been. I started off looking at the assignment and feeling like breaking down into tears by the sheer overwhelmingness I experienced. What is a tippy? What on earth is minimax? Not to mention we were given starter code that I was not at all familiar with, after having spent so much time lovingly developing my own code.
However, when I couldn't put it off any further, I tackled this assignment head-on. First I read the starter code that we were given, and when I fully understood it, I was able to appreciate why the instructors did things a certain way. For example, I wrote a specific game_view subclass in my first assignment that took care of playing Subtract Square, but now I can see how the apply_move method in the game state class enables one to play straight from a generic game_view that calls on the game state.
Afterwards, I decided to start from the most manageable class - TippyMove. This class was so simple that the parent class didn't have any code in it at all, and I think the fact that it serves only one purpose (creating a move a user could implement) made it easy to overlook in assignment 1. However, it definitely came in handy for apply_move later on.
Next, I took on the TippyGameState class, which was not as gargantuan of a task as I initially thought it would be. I think the most challenging part of that class was determining how to generate a rough_outcome, which I think I could have done a better job on. I didn't realize until after the assignment was over that rough_outcome should only look at the present state and not any possible future states. I don't think it is a necessary method for a tippy game though (especially on a 3x3 board, where there are only so many permutations), but I can definitely see how it could come in handy in a game of chess.
The biggest challenge on this assignment was probably implementing suggest_move in the StrategyMinimax class. First of all, I had trouble understanding how Minimax worked as a strategy, because of the multiplication by -1 each round. However, after I understood it, writing a recursive case was exactly like we had done in classes and labs -> write a base case, and then write a recursive function for cases that aren't so simple. I think the hardest part was pairing up each possible score with the move that produced that score, but I was able to manage that by writing a helper function that found the score, and using it in the suggest_move function which also had a recursive body.
Overall, now that the assignment is over, I feel a lot more confident about recursion and also in my ability to problem solve in general. It is definitely a great feeling to see how far I can come in a span of a couple of weeks - from desperation to having a intimate knowledge of the what and how of the assignment. It almost makes me excited to see what Assignment 3 will bring. Almost.
LINKED LISTS
One of the best parts of keeping these SLOGs is that I'm able to read what my peers are encountering in their CSC148 journey, and I'm able to learn from it. I found Humair's description of linked lists very apt and interesting. His entry can be found at:
https://humaircsc148slog.wordpress.com/2015/03/08/week-8-assignment-2-linked-lists/
In particular, this explanation helped enhance my own understanding of linked lists:
Now, what I find really fascinating about linked lists is how we can make them function just like regular lists. If we had a list say x = [1, 2, 3], and I wanted to find out the value at index 1, I would simply evaluate x[1], yes? Well we can do something similar with linked lists, we just have to implement a method called __getitem__. We were tasked with writing this method for our lab 7. Here was my implementation in python:
| 12345678910111213141516171819202122232425 |
|
Here we first make sure that the index that was given is within our bounds. If not we simply return an error. Otherwise we begin our search for the value. There is one minor thing to consider however, if a user wants to search something like x[-1] we have to adjust the index so that it’s searching for the last value, so we need to only perform a simple addition to adjust for the right index if it’s less than 0.
Having struggled with this problem myself in lab 7, it was very helpful to read his explanation about linked lists. Some things I hadn't considered were: what if the index was not within the range of the linked list and what if the given index was < 0. His code deals with this by raising an index error in the first case, and cleverly devising the corresponding index that is > 0 by simply adding the negative index value to the size of the list in the latter case. After setting the index up that way, the while loop becomes very intuitive, with an accumulator i keeping track of the index of the current node we are at, and having curr_node advance to curr_node.nxt each time i has not yet reached the indicated index. Once the while loop condition is broken, i will be equal to the index value passed in the argument, and we simply return the value of the current node at that index value.
This explanation definitely helped with the implementation of further methods including __setitem__. Overall, I found linked lists fascinating, because they make use of the recursion we have been learning about, and are a perfect example of object-oriented programming. They were a little bit difficult to grapple with at first, but after many diagrams and with the support of my peers' SLOGs, it became a very intuitive and interesting concept!
The post gave me great insight in tackling assignment 2. It is definitely to see such unique approach in doing assignment 2.
ReplyDeleteThe post gave me great insight in tackling assignment 2. It is definitely to see such unique approach in doing assignment 2.
ReplyDelete