Sunday, 8 March 2015

Week8: Assignment2 about recursion and class design

The due date of assignment 2 is this Thursday, so we worked on assignment 2 this week.

I learned two main contents in the assignment.

First, more about the class design. During the assignment 1, I learned something about class design. However, I even learned more by referring to instructor's code. First, I learned that we don't need to implement a method to play game under GameState, rather, we should implement the play method under the GameView to ensure this play method can work for more game. GameState is just a class to represent a state, we just use these states under the GameView. Second, I learned that most games should have similar methods like possible_next_moves, apply_move. This can help us to play a lot of games by just implementing one GameView. In the last assignment, I obviously didn't find out many share characteristics between one game and another one.

Then, I understand recursion more. I get to know two new essential rules to make my recursion work. The first one is that I should get to know what requires the recursion, in this assignment, the return of the state or move itself, in fact, doesn't require recursion. The thing which requires recursion is the calculation of the score. Knowing what really requires recursion makes our recursion much easier. The second thing is that drawing a picture is a really good way to help us to understand recursion. At first, I didn't care about the picture on the handout. And that makes me waste a lot of time as I didn't have a method to solve the problem and I just tried over and over again. After considering about the picture carefully, I got to under the instructor's method and then it just took a few time for me to work out the problem.


4 comments:

  1. Totally agree with the point about drawing pictures! I made the same mistake as you, not drawing them out in the beginning :P but now we all can learn from our mistakes right lol

    ReplyDelete
    Replies
    1. XD, yeah, for simple functions, it is ok to just think over it. However, when it comes to difficult ones, drawing a picture is really useful. Never be too lazy to draw a picture.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete