Sunday, March 29, 2015

Week 11 - Revisiting Past SLOGs

Time passed by so fast, by this time I noticed this semester has almost came to an end. I have learned many new things and strengthened by knowledge of python this semester. I have learned many new python classes that each has a specific role in keep tracking different values, and also learned many different recursions for these classes that is very helpful for writing functions and methods. I loved the three assignments, where we made simple games from scratch. Tutorial was very fun, I am impressed that there are so many computers in BA, where my tutorial is at. Classes was very interesting, we learned many new concepts for programming and many new ideas were been introduced.

Now as I look back to my past SLOGs it made me feel very accomplished, as its like a diary were all the things I have learned and all my struggles is been recorded. I have also learned many new things that I didn't notice before over the past weeks as I study for term-test 2 and doing assignment 3. For example, as look back on my Week 7 SLOG, I was talking about recursion and how it works, at that time I did understand the concept, however as my experience grow after these weeks I noticed many small tricks that could be helpful when writing recursive functions that I would like to add to my previous post. These might seems very obvious, but after writing many recursive functions I have made countless mistakes around these small things that I have forgot, so I felt these are very important to check after writing a recursive function.
1. Check for parameters in recursive function, check if when calling the function itself inside the function body all the parameters has been given, and do they have the correct value.
2 . Check for children before using them. Example: When writing recursive functions with BTNode type of class don't forget to check for self.left and self.right before using them, otherwise there might be an error because they might not exits.


Sunday, March 22, 2015

Week 10 - MiniMax Testing

In this week's lecture professor Danny talked about how to write the best and most efficient test cases for testing programs like MiniMax. This was very interesting for me because I myself had done it in the previous assignment 2 while writing MiniMax. However hearing him teaching us about how to test MiniMax made me felt very uncomfortable, because it made me feel that my testing was not that well thought and my code might have some flaws.

Sunday, March 15, 2015

Week 9 - Exam Week

This week was very busy for me, with may assignments and a presentation due as well as a 2nd mid-term exam for this course. There are no tutorial for this week due to the strike and the class was cut short because of the exam so there is not much to talk about for this week's blog.

I basically studied and worked all week, I first looked up past exams to get a general idea of what to be expected in this mid-term, due to all the past exams were about writing functions of recursive codes I did not expect word questions on the test that test our knowledge of programming terms like different 'nodes' and technical terms for ways to count a tree. I did very bad on the first part because I got overconfident and overlooked materials that weren't covered in the past exams and didn't prepare for the definition part.

Sunday, March 8, 2015

Week 8 - LLNode and LinkedList

This week was also a busy week because we had to hand in assignment 2 on Thursday before 10 pm and I had to do a lot of final checking and check all my function files with pep8 and change all the format preference errors.

In this week's lecture we learned a quite interesting example of python class LinkedList which use another python class LLNode in itself. This was a very interesting concept as it is very hard and confusing to understand for me at first. Basically LLNode acts like a 'value' class for the LinkedList class, where LLNode only shows its current value (like BTNode) and 'nxt' which shows a recursion of LLNode inside it. (like BTNode could also be None) LinkedList is basically its like a 'list recorder' for LLNode that shows the last BTNode in the LinkedList and the whole chain of BTNode in the LinkedList.

There was no tutorial this week due to the TA strike, and I had to do tutorial at home. However although at first it was very challenging to understand the concept of writing function and method for BTNode and LinkedList, after a few fails I started to get the hang of it, and with the help of answer sheet I was able to quickly write all the functions in the tutorial handout.

Friday, February 27, 2015

Week 7 - Recursion and Assignment 2

This week is probably the most exhausting week for CSC148, not because of lecture nor test, but it's because of the coming due date of assignment 2. When I first started university, I had handed in many late assignments, not because of  I didn't complete the work in time, but it was because of that I completed just in time, and went on a break forgetting about handing the assignment in. Due to these bad incidents I have made a habit of starting assignment earlier than before, so same with this assignment I started right on the night of Friday of this week.

There were so many challenges with the assignment, first I had to read and understand completely the given game view and game state structure, and on top of that I had to follow the formula and make a harder game state with a more intelligent move chooser. The hardest part for me was writing the winner function for Tippy (a function that checks if either player had won the game) and suggest_move function for MiniMax strategy. The winner function for Tippy was hard in the sense that I had to write so many lines to check all the possibilities for each position on the game board and restrict places that were been checked on the board. The suggest_move function for MiniMax strategy was without a doubt the hardest part in this assignment for me, and as the title of this week's blog suggest it is related to recursion, and in fact I had to write two very hard helper function using recursion to make suggest_move work, and as you can imagine all the different bugs I had when writing suggest_move, where I spend most of the time tracing values in the recursion functions.

So... what is recursion? Basically to put into the simplest words recursion is preformed when a function calls it self in the program. Recursion can be useful when writing harder functions (like ones I mentioned in assignment 2). For example, there is a list that contains many list and integer, and those list inside also could potentially contain more lists and integer (nested list with integer), and we want to write a function that adds all the integer in the list up. By writing a function with a for loop looping each variables (whether a list or integer) and calls the itself (the function) with the variables we can simply accomplish this task, no matter how many list is nested inside the first list. 
(sample function by me)
Recursion is super important nowadays, everything function I write this week involves some sort of recursion, like assignment 2 and even what we learned in class and tutorial. This week's lecture we learned to write functions for a new class, BTnode, of course involving recursion. Basically BTnode is a class that similar to list and Tree, where it creates a variable, that can contain up to 2 variables, which can be either a number (int) or BTnode. Since this is similar to list and Tree, there are so many new functions that we learned to write using recursion.
(example of BTnode from week 7 lecture slide)

Thus to conclude my adventure for this week, I found understanding recursion and knows how to write it is very important for writing Python functions (or maybe as well for other programming language). Although it was very tiring this week trying to fix all the bugs in assignment 2 tracing recursions, but I found it very exciting to program those functions, and very rewarding when I found that my programmed AI can beat me most of the times. Especially when AI goes first on Tic Tac Toe (very similar to Tippy I made on spare time), the win rate for AI is really high!
(game of Tic Tac Toe and found it to be more fun than Tippy on 3x3, since 4x4 is impossible to run)



Sunday, February 15, 2015

Week 6 - Tree and Writing Recursion

This week's lecture was pretty challenging, we learned class Tree and how to write recursion for Tree. I have some knowledge on how Tree works as I have studied class Tree last week in preparation of the midterm, but it was still challenging to write recursion for Tree. Basically the class Tree works pretty much as a list with list value inside, except the current list or so called 'node' has a value to it. Also it is possible for a node to have no 'children' or no sub-list.
Visual representation of a Tree object. (Writing Recursion Exercise)

The tutorial for this week is very hard, probably the hardest tutorial I have had so far, and this is the first time where I have not able to finish all method example on lab handout. Similar to lecture this week's lab is about writing recursion for class Tree, and it is very tricky. Methods that we were asked to write like return all the value in Tree object where it has at least one children are extremely complicated and requires a lot of thinking. The quiz in the end was also very tricky, where we were asked to write a  function that returns the maximum depth in the Tree object, and I had little confidence on the correctness of my answer.

  

Week 5 - Midterm Review

We have a midterm exam in this week's lecture... although I am writing this blog a week late but I can still recall what happened during that week. I started reviewing past exams few days before the exam, and studied many questions even ones with tree and exceptions. The exam was pretty easy however, with just questions about writing hidden methods, tracing recursion calls and inherit sub-class methods. Surprisingly there is no question about stack in the exam, which I thought its a must have question form observation though past exams.

The tutorial was very interesting, we learned a new class similar to stack which is called queue. The main difference with queue and stack is that when use the method .pop() on stack it delete and returns the object the top of the list while use the method .pop() on queue it delete and returns the first object in the list.