Saturday, 28 March 2015

Week 11 (a look back to recursion)

My understanding of recursion in the first few weeks was very vague. I didn't understand how exactly recursion works, because I thought recursion was a complex algorithm. From my understanding before recursion was a function that calls itself, but everything else was hard to understand. When I had to understand a recursion I needed to trace it or make an guess.

My current understanding of recursion is a function that has a base case that does not use recursion and another case that use recursion to approach the base case (recursive case). The base case is case that has no more sub-cases. For example, leaf node in a tree would be base case (since it has no children) and internal node would be the recursive case (since it has children and its children might be the base case). To make recursion work the recursive case must be getting closer to the base case, for example internal node is getting close to leaf node because eventually internal node's children will be leaf node if the tree is not infinitely big. Otherwise recursion will result in error because it's going to recurse infinitely.

Friday, 20 March 2015

Week 10

A sample solution to minimax for assignment was posted in class on Wednesday. I am glad to say the sample solution is very similar to my code, because I also found all the game states that's one move away from the current game state, and then checked the result of that game state from the opponent's perspective. What I did differently was that I used several helper functions to get the tuple of moves and their score, instead of the only using function minimax in the sample solution.

A3 is now posted. We have two options in A3; we can either continue to improve minimax by making it more efficient or we could implement a few function for game state tree. I am more prone to improve minimax because it feels more satisfying to perfect my old code.

Thursday, 12 March 2015

Week 9

We had the second term test on Wednesday this week. I would say the term test is pretty fair judging from the lectures and labs, since all the questions on the test are very similar to the lectures or lab problems that we did. However, I feel like the strike had quite a bit of impact on this test, as we did not go through the LinkedList problems we did in the lab, nor did we have anyone to ask questions during the exam. But overall, I think I did pretty well since I understood all the materials in lecture and went over all the lab solutions.

I really find piazza helpful for this course since the profs and a lot of students are diligently answering questions on the website, and there are a lot of the questions are commonly asked questions that are relevant to the tests, lectures, assignments, or just computer science in general. I would suggest the profs to advertise piazza more.

Wednesday, 4 March 2015

Week 8

This week we learned linked list. To my understanding linked list is similar to normal list without the index value of each item. To make a linked list, we must have a start and an end, with each node linked with another node, from the start to the end. One thing I don't understand is why do we use linked list. I feel like linked list is outclassed by other data structures in every perspectives; in term of searching efficiency, linked list has a efficiency of n, whereas tree has log(n);  in term of sequence and index, list would instant return a value given an index, whereas linked list needs to go through the entire list to return a value; in term of storing data with less space, I believe sets and dictionaries are more efficient. I just can't find a situation where linked list would be the ideal structure.

Wednesday, 25 February 2015

Week 7

Check week 6 for Object-Oriented-Programming

We've started assignment 2 before reading week. At first, this assignment looked pretty overwhelming compare to the previous assignment, because not only we are making a harder game than Subtract Square, but also we are implementing a much smarter AI for the game.

I started by reading the assignment instruction and the starter code several times. I found out that out of the four python files we need to write, game_view should be just a matter of changing/adding a couple of lines, and tippy_move is pretty short and straight forward. The real challenge comes from tippy_game_state and minimax.  The game state just needs a lot of work, such as checking if a tippy is formed, and draw the ascii version of the game board. The starter code for the subtract square game state class differs a lot from my code in assignment one, especially in terms of the way to approach the question, thus I had to change my way of thinking.

Minimax is the method that requires a bit of thinking; before coming to this class, I thought it would be really hard to make an AI that plays a perfect game. Now that I think about it, if you are able to list all the possible variations of the game, then the computer would be able to find the winning strategy. The downside is that the computer will take too long to make a move since number of possible variations are enormous in most of the games.  Still, recursion is needed for finding all the variations, and finding the perfect winning strategy based on all the variations isn't all that straight forward.

Wednesday, 11 February 2015

Week 6 (Summary of Object-Oriented Programming Concept)

I've learned Object-Oriented Programming before coming to CSC148, not in python, but in java instead. So it's not really a new concept for me. To my knowledge, OOP is a concept that mainly uses classes and methods, instead of using functions. In Object-Oriented coding, codes are categorized into different classes, and each class represents something that has many different attributes. An class is an abstract idea, and when you make a specific class by giving all the attributes, you now have an instance. For example, if person is a class, with attribute of gender, height, weight, and age, an instance would be a 20 year-old male, 180cm tall, and weighs 70KG. Methods are similar to functions, but they belong to a class. For example, check if the person is male or female would be a method belong to the class Person.

If we have to make a simple program, for example our first assignment where we had to make "subtract square", then we would organize the code into various classes. We had a class for the game state for saving the current game data with attributes of "who's turn is it", "current number", etc, a class for strategy for the computer to choose a move, and a class for game view for interacting with the player. Each of the classes has an unique use, and all of them together will be sufficient to make "subtract square".

I have a difficulty time explaining Object-Oriented Programming concept even though I know exactly what it is, so I think we should've focused more on the basic definition in class.

Wednesday, 4 February 2015

Week 5 (tracing recursion)

Recursion is one of the hardest topic that I've learned so far. Functions that are using recursion are often very short, but the amount of complicated problems that they can solve is amazing. Sometimes recursion is really hard to understand by simply look at the code, that's why we have to trace recursion in order to understand it easier.
Most of the recursion examples we did in class are about nested list. I feel like tracing this kind of recursion is relatively simple because all it does is breaks down the nested list into smaller items until the item becomes a non-list object. We are also allowed to skip the process if we have traced a similar example before (if we traced a list with same depth), which reduced a lot of work load.
 I find tracing recursion really useful because it deepens my understanding of what the computer does. I've learned recursion in high school before (without tracing), and I found it impossible to understand, and most of the times I just used trail-on-error to write my recursion code.