Thursday, 26 March 2015

Week 11: Everyone had a mental breakdown. I am not the only one.

        After revisiting my week 8 slog, I felt ashamed to have blamed my inability to do assignment 2 on the professors. As a recap, in week 8, my group and I had trouble writing strategy minimax. And when we went to office hours, the professors told us to figure things out on our own. Out of frustration, I complained about the incident in my slog and declared office hours to be useless. Now that I look back, I had to disagree with my previous opinion. As a matter of fact, Danny and Diane did provide some hints regarding minimax, however, they couldn’t tell us the exact way to tackle the problem since that will be telling us the answer. Moreover, they even sent an email to the students describing the approach to the problem. Furthermore, minimax wasn’t as hard as I though it would be since my group managed to finish it in week 9. Although our approach to minimax differed completely from the standard answer, it ran perfectly nonetheless. Out of self interest, I also read over my other older slogs and discovered that I still agreed with the majority things I once wrote. For instance, in Week 4, I mentioned the CSC148 is significantly harder than CSC108, and that I was not used to this fast paced learning environment. Well, I still feel the same, especially when the strike is still continuing and no help centres are available for me to ask questions. Just when I got used to my new schedules and courses, the strike happened and messed up my pace. I now lose the opportunity to get extra help, and have to spend longer time struggling to understand new course materials on my own. Similar to my first three weeks, everything was a struggle as I tried to get used to another new environment. However, I also felt relieved to have solved many complicated topics in my slog. Each time I had some problem regarding recursion (in week 5), OOP (week 6), or inked lists (week 10), I always try to figure things out on my own. After I have fully mastered these concepts, I write them in my slog and explain them in a way that can help other readers’ of my slog master the material. Now that exams are imminent (a month go by really fast!), I realized that studying for CSC148 is so much easier since I already understood all the concepts taught in class. Hence, slog is useful for learning purposes since it reaffirms my comprehension after I tried to explain them in words. 

         Out of interest, I read over some other people’s slogs and discovered that they also had difficulties with assignment 2. For instance http://egq148.blogspot.ca/ mentioned in “The Seven Week Itch” that he/she also had some problems with minimax. Interestingly, one thing mentioned by the blogger caught my attention since it coincided with my previous thoughts: “How are we supposed to write a program that can never lose, if we ourselves are always capable of losing?” I remembered when I had problems with A2, I also felt like minimax is an impossible task. Furthermore, I also read Jingyu’s slog and discovered that we had the same problem regarding the method delete in linked list. (I mentioned that I had trouble understanding linked list in week 10. Similarly, Jingyu also expressed her frustration with delete in her week 10 slog). The difference between us is that I figured out how delete works on my own, whereas Jingyu didn’t. Hence I messaged Jingyu offering her my slog. Hopefully it will be helpful. 

        In conclusion, I want to thank Huan Ling, Jingyu and some other people for mentioning me in their slogs. At first, I disliked writing slogs and considered them to be a waste of time. However, slog is a great tool for learning since it helped me clear out my own misunderstanding regarding certain concepts. Furthermore, I felt accomplished that other readers also found my writing to be useful and helpful. Lastly, I want to mention Christian’s slog. His slog has helped me understand various complicated concepts. And one thing that I really liked about his slog is that he would relate the class materials to some other applications such as math. For instance, in week 7, he related recursion to the Fibonacci sequence. Because I am also in the math major, seeing a topic that is of my interest really helped my understanding. Moreover, his slogs are visually appealing and I liked his choice of pictures. Here is a screenshot of his beautifully done slog:





Saturday, 21 March 2015

Week 10: My impressions of week 9

         Like Week 8, Week 9 was also a busy week since I had multiple assignments and tests, including the second term test for CSC148. I mentioned in last week’s slog that I didn’t thoroughly study linked list, and that I hope nothing related to deleting nodes will be on the test. Unfortunately, according to Murphy’s Law, “anything that can go wrong, will go wrong.” On the third and last question of the term test, I had to incorporate the idea of deleting nodes. After the test, I discussed my answers with fellow classmates and not surprisingly, my answer for question 3 was wrong. The good thing was my answers for question 1 and 2 were correct. So hopefully, part marks can be given on my attempt at question 3.

        Because of my lack of understanding regarding linked lists, I decided to re-learn the class materials. With the help of my friend a person's slog, I finally learned the structure and implementation of linked list. One important tool that my friend taught me in order to understand linked list is to draw pictures. To begin, linked lists are lists made up of connecting nodes. It is shaped like a chain where each node is connect to only one node. In technical terms, linked list represents a sequence of a collection of objects (nodes) with a value and a reference to other similar objects. To understand its structure better, drawing pictures are really helpful. Here is a pictorial representation of linked list: 

To be more specific, linked list consists of two classes. The first one is called LLNode and it represents one single item (node) in the linked list. This object stores the value of a particular node, and the value of the next node connected to that particular node (represented by the ‘next’ attribute in the init method). The diagram above refers to three distinct nodes connected in the form of a linked list. The first node has the value 1, and its ‘next’ attribute refers to the second node with the value 2. The second class is called LinkedList, which represents the entire list with nodes connected in a particular order. It contains three main attributes, the first being the value of the frontmost node (stored by the variable ‘front’), the second being the value of the last node of the list (stored by the variable ‘back’), and the last being the number of nodes in the linked list (stored by the variable ‘size’). In the above diagram, ‘front’ refers to 1, and ‘back’ refers to the value 3, whereas size refers to 3 since there are three nodes in total. Furthermore, many other methods such as append, delete_front, prepend and __contains__ are also implemented in the class LinkedList. 

        The part that I had the most trouble with was deleting a node. Now that I learned to draw helpful diagrams, the concept of deletion doesn’t seem as hard. To delete a node with a designated value after its first occurrence involves assigning a variable called cur_node (current node), which keeps track of the value of the current node. Here is what the code looks like:


Basically, the code means if the first node exists and has a value, make the variable cur_node refer to that first node, represented by lnk.front. Then continue to traverse down the list looking for the node with the selected value. In case the entire list does not contain the value we are looking for, we have to accompany the while loop with the condition that cur_node always has to exist (not None). Furthermore, if we did not find the node with the value we are looking and the list still has unvisited nodes, assign cur_node to the next, upcoming node. Now, the while loop either terminates if we already searched through the entire list or if we found the node with the value we are looking. If after traversing the entire list, no node contains the value, the if statement determines what to do. If cur_node refers to the value None, it means that the entire linked list does not contain the value we are searching for, hence nothing happens. However, if cur_node exists, we either delete the node after it (if cur_node is not the last node of the linked list), or we do nothing since cur_node is already the last node of the list (the ‘back’ of the list). Here is a diagram:


If the value we are searching for is 55, cur_node will at first refer to 17. Since 17 does not equal to the value we are looking for and cur_node is not None, cur_node is now assigned to be the next node with the value 23. Just like 17, 23 also does not equal to 55, hence cur_node now refers to 55. Since cur_node == 55 == value, the while loop terminates. According to the if statement, cur_node and cur_node.nxt both exists. Hence, the body of the if statement is being executed. Since lnk.back is not cur_node.nxt (meaning node 72 is not the last node of the list), cur_node.nxt will be equal to cur_node.nxt.nxt. This means in the node with the value 55, its attribute ‘next’ will now refer to the node with the value of 14 instead of 72, hence deleting the node with the value 72. Moreover, the size will be decrease by the value 1. Now, if 14 is the value we are looking for, cur_node will end up referring to node with value 14. Since 14 is the last node of the list, cur_node.nxt is None, and nothing happens because the if statement never gets executed. Let’s say the value we are looking for is 25, which is not in the list. In the end after traversing through the entire linked list, cur_node will refer to None, since cur_node = 14 and cur_node.nxt will be None. Similar to the previous example, nothing will happen.

        In conclusion, drawing pictures are sometimes critical for understanding complex data structures. Despite the fact that I was occupied with tons of work last week, I am really satisfied with myself and my problem solving attitude.  In the end, I want to thank the person who wrote the slog http://egq148.blogspot.ca/ since it helped me understand linked list and how it works. 

Thursday, 12 March 2015

Week 9: My impressions of week 8

        Week 8 was both a happy and sad time for me due to three major incidents. The happy event was that my group and I successfully completed the code for strategy minimax two days before the deadline. And the sad parts of the week was that I handed in the wrong file during submission, and that I failed to fully prepare for a test.

        Now, I will begin with the happy part of my recount from last week. As a recap, during week 7, my group had trouble implementing strategy minimax. Fortunately, after discussing and thinking for multiple days, we were able to come up with a solution. During multiple group meetings, my group and I knew we had to use -1 as a multiplier to change the score after the player switch turns. However, we were unable to multiply the multiplier into the score list because it contains many lists of inner lists. After thinking about the solution for days, my partner had an interesting idea of using both the max and min function to calculate the score. We then created two functions, where one was called max and the other was called min. And we used the min function within the max function, and similarly, the max function within the min function. In this way, during a game between the player and the computer, the max would return the score of 1 when the computer is the next player, while the min would return the score of -1 to the computer when the opponent is the next player. The min function served a similar purpose as multiplying the opponent’s score by -1 in order to obtain the computer’s score. Proud of our creativity, we successfully completed the code and showed it to Danny and Diane, to which they both replied the word “interesting.” Although our code might deviate from the standard answer that the professors’ expect, my group and I were proud for our completion of assignment 2 nonetheless.

        Despite the above mentioned celebratory accomplishment, my group quickly ( and ironically) realized that we had submitted the wrong version of assignment 2 only after the submission deadline. We then quickly re-submitted the right files and regretted our loss of 5%. From this mistake, my group and I learned to submit the assignment at least an hour ahead, and run our submitted program before the submission deadline. Switching to another topic, Lab 7 was also a challenge. Because I skipped classes in order to have more time thinking about strategy minimax, I missed the lecture about linked list. Hence, when attempting to do the lab on my own, I failed to come up with the implementation for functions such as delete_front and prepend. Furthermore, I had no idea how to delete a middle node and then connect the front node to the back node. Because I had other tests and assignments due in the same week, I didn’t have the proper time to master linked list. And to my dismay, the third question of test 2 involved deleting nodes. 

Me during week 8


        To sum up, last week was like an emotional roller coaster ride. I went from being extremely happy to being disappointed of myself in the end. Although I was able to complete assignment 2, I failed to hand in the assignment on time due to my carelessness. Moreover, my failed time management skills left me unprepared for upcoming tests. Hence, from last week, I realized I had to change my study habits in order to catch up to the missing school work. When submitting assignment 3 in the future, I should submit at least an hour earlier.

Friday, 6 March 2015

Week 8: My impressions of week 7

        Truth be told, I was at the verge of a mental breakdown last week due to Assignment 2. Learning from the mistake of Assignment 1, my group and I decided to tackle the second assignment 10 days earlier, so that we can visit office hours more frequently. However, the office hours proved to be utterly useless as both professors responded to my group’s questions with ambiguity. To my frustration, whenever a question related to strategy minimax was asked, the professors would reply: “I will leave that for you to think about.”  Well, I wouldn’t have attended office hours if I hadn’t already thought about the assignment throughly and get stuck for days. I know my complaint might sound obnoxious and whiny, however, it was difficult to restrain my anger after wasting my class time going to helpless office hours that I had to sacrifice class time for. Now, TippyGameState, TippyMove and GameView were quite easy to write since they are similar to that of a Subtract Square game, and after a few hours, my group and I were able to finish the code. On the opposite, strategy minimax seemed impossible to derive an algorithm. My group and I spent two whole days discussing ideas and solutions to strategy minimax, and whenever we began implementing our ideas, we get stuck writing the code halfway. After multiple fruitless attempts, and after abandoning many ideas, my group decided to attend office hours, which later turned out to be time wasting and useless. 

        Despite facing an unprecedented obstacle, such an unhappy event did not deter me from showing an interest in binary search tree. Due to my fascination and curiosity with such a brilliantly structured tree, I decided to do a quick research on its origin and inventor. From Wikipedia (I know it might not be the most credible and reliable source, but it is the quickest way to research about materials), I learned that the binary search tree (BST) was invented in the 1960 by Windley, Booth, Colin and Hubbard. Each node in a BST contains a maximum of two children, whereby the left node contains a number smaller than the number on the parent node, whereas the right node contains a number larger than the parent node. This structure is very important because it shortens the time of search by half. Relating to the BST is the methods of traversing the nodes. There were three ways of traversal taught in class. The first one was preorder traversal:
Order of traversal: F,B,A,D,C,E,G,I,H
The second one was postorder traversal:
Order of traversal: A,C,E,D,B,H,I,G,F
And the last was inorder traversal:
Order of traversal: A,B,C,D,E,F,G,H,I
At first, the professor’s definition was a bit confusing to understand since it lacked a clear picture. However, after being shown pictorially how to traverse the binary tree in all three orders, my confusion was cleared.

        In conclusion, my impression of last week was horrible due to my inability to write code for strategy minimax. In order to remember the parts where my group and I had problem with, I summarized three major questions regarding strategy minimax:

1. How to derive the scores of the next possible game states using recursions?
2. After computing all the scores, how to select the best score?
3. Lastly, upon determining the best score, how do I associate the score with its corresponding move?


Hopefully, my group is able to solve these problems before the assignment is due.