2015年2月26日星期四

Summary of Object-Oriented Programming concepts

In fact, this topic is mentioned in the beginning of the slog since the idea of object-oriented programming is one of the first concepts introduced in CSC148 and can concludes the difference between CSC148 and CSC108.

In CSC148, the detailed code is never emphasized. Recall what we have learnt so fat, the class (how to build a class, the subclass, inheritance, exception, etc.) and recursion and tree. These are all general ideas telling you the big ways to achieve one thing. CSC108, on the other hand, focus on the basic codes and concepts like list, dictionary and some statement like for, while , if, etc.

No wonder these basic elements are extremely important as you cannot make a move without knowing these thing, but only knowing these thing would limit your sight. You may simply lost your way in a large program. The idea of Object-Oriented Programming helps you to stand higher and see further.

However, the disadvantage of this concept is that, students may feel difficult to actually write the code of sth. especially for those whose skill of coding is not really solid. I think more basic exercises is still needed in CSC148, rather than just focus on the big idea.

2015年2月22日星期日

Reading week === Some idea about assignment 2

Since it is reading week and no class is in progress, I do spend some time working on assignment 2. Personally I think the biggest difference between assignment 1 and 2 is that subtract square is a text-base game while tippy is a graphic-base game. Of course the computer cannot understand the graph of board or how those circle and cross on the board form shapes. Then that means we need to work to "translate" the graph to the text.

My idea of that is to use number representing each block. For example, a 3 x 3 block may looks like this:
 and the program may interpret each block as a number:

so when the player want to choose a block to occupy, he or she actually choose a number from 1 to 9 to represent the block.

Then mechanism of deciding winner goes a little bit more complicate. There are generally four patterns of winning situation:

OOX    n, n+1
XOO    n+size+1, n+size+2
XXX    

OXX    n
OOX    n+size, n+size+1
XOX    n+2*size+1

XOX    n
OOX    n+size-1, n+size
OXX    n+2size-1

XOO    n, n+1
OOX    n+size-1, n+size

XXX

* size is a variable means the length of each row.

Imagine this, player 1 choose a move for four times, all his or her moves are recorded in a list, we sort the list and see if the four numbers match the pattern of the four numbers I listed above. However, we need to avoid the situation which like this:

XOO   
XXO

OXX   

It also follows the pattern (first block = n, second block = n+1, third block = n+size+1, fourth block = n+size+2), and from this we see that the first block cannot not be larger than n*size-2, in other words:
a//size or (a+1)//size would return a False.

These things are just conceptual level, but I think it is practical and is able to change to code.


2015年2月8日星期日

About week 5

Trace Recursion, write recursion.

The term test 1 has ended. Some potential problems that I have not paid enough attention is showed in the test.

Firstly, although I know what does exception means and how to use it, I do not realize when using it appropriately. I still let my intuition goes like

print('This does not work')
rather than
raise Exception('This does not work')

Also, I sometimes forget to write code “raise” before Exception or NotImplementError .


I have somehow be more familiar with the idea of recursion, specifically where to  put the function in the code. So far I managed to do all the assignments and labs relate to recursion, and I want more questions for exercise.