Tuesday, 31 March 2015

Week 9: Impressions



My biggest frustration occurred when I ran the minimax unit test. Clearly, errors were returned, which wiped out my dignity as a programming student. Ha, ha, ha...


In A2, the minimax we wrote only worked for Subtract the Square, but not with Tippy.
I suspected that something was wrong with TippyGameState. Indeed, it was! 

I realized the mistake after debugging from GameView (the overall program for running the game):
       while not self.state.over:
            if self.state.next_player == 'p1':
                m = self.state.get_move()
                while not m in self.state.possible_next_moves:
                    # The move was illegal.
                    print('Illegal move: {}\nPlease try again.\n'.format(m))
                    print(self.state.instructions)
                    print(self.state)
                    m = self.state.get_move()
                print('You choose: {}'.format(m))
            else:
                # The computer makes a move.
                m = self.strategy.suggest_move(self.state)
                print(m)
                print('The computer chooses: {}'.format(m))
            self.state = self.state.apply_move(m)
            print('New game state: ', str(self.state))
            print()

When the game is played, the first round would work. Self.possible_next_moves would return a list of all the possible moves available initially in the game.
However, the problem occurs in apply_move, that it does not properly modify self.possible_next_moves. 
I tried to modify possible_next_moves every time apply_move is called. However, for some reason, possible_next_moves remain constant. 

Basically, the mistake made was keeping a list of possible moves as a variable within the object. Hence I'm mutating it as game states change. This is a very bad idea because the default when create in the object is the original game state( with all possible moves in the initial state). 

UPDATE: I think another mistake I made was not reading the code provided by the instructors first in Subtract the Square. In the exemplary file, possible_next_moves is actually a method! Ooops... In the future, I must take more precaution!

-----------------------------------------------EXOCOETIDAEE---I--AM--A--LINE----------------------------





Sunday, 15 March 2015

Reflections on Last Week



Sorry, readers! I put off this post off for a bit...
The force of procrastination induced me to stay in my bed...

What happened this week?

Well, term test 2 happened to me... 
How did it go?

                                                                      Je ne sais pas 
Say nothing
Think of nothing
               Ignorance is bliss    
          



I have lost my magical ball of grade prediction after completing 100000 midterms and 1000 quizzes since starting school. 
Hence I will write about anything but speculation on my test scores. 

Back on topic: course material
The most interesting concept we have learned so far is the binary tree, or specifically speaking, the binary search tree(BST). 

A binary search tree is an ordered version of the regular binary tree.
Its left child's value is smaller than the node's value, and the right child's value is greater than the node's value. 


I find this structure very intriguing! Every time I look at a BST, I think of holding the parent node and having other nodes dangling on the sides. Sometimes, the BST also reminds me of a christmas tree!


Overall, I think the implementations of functions that traverse through the BST are very challenging. 
Here is an example from the lab:
def list_between(node, start, end):
    ''' (BTNode, object, object) -> list

    Return a Python list of all values in the binary search tree
    rooted at node that are between start and end (inclusive).

    >>> b = BTNode(8)
    >>> b = insert(b, 4)
    >>> b = insert(b, 2)
    >>> b = insert(b, 6)
    >>> b = insert(b, 12)
    >>> b = insert(b, 14)
    >>> b = insert(b, 10)
    >>> list_between(None, 0, 15)
    []
    >>> list_between(b, 2, 3)
    [2]
    >>> L = list_between(b, 3, 11)
    >>> L.sort()
    >>> L
    [4, 6, 8, 10]
    '''
    if node is None:
        return []
    else:
        if is_leaf(node):
            return [node.data] if (start <= node.data <= end) else [] 
        else:
            if start <= node.data <= end:
                d = [node.data] 
            else:
                d = []
            left_list = node.left
            right_list = node.right
            return list_between(left_list, start,end) + list_between(right_list,start,end) + d

Functions involving more complex recursion, like the one above , really bring our progress one step further. Just earlier on in the semester, we were still implementing very simple recursive functions. 
However, as of now, I still find it a bit intimidating to implement complex recursive functions(especially on tests, when the code cannot be tested). To increase my confidence on recursive functions, more practice will do. I will have to do the labs again! 

Impressions on course logistics and student support:

As finals and A3 deadline approach in the vicinity, the TAs aren't helping us with the strike. We haven't had formal labs for more than two weeks. As a student in a course with tight deadlines, namely CSC148, I feel very nervous and anxious. 

Office hours are immensely helpful; however, time is a big issue because I often have other classes to attend during office hours. 

Let me end this blog post with optimism:

Despite all the turmoil we students have experienced, the end of the school year is still coming! May we find happiness even in the most stressful times! Let's hope for the best and keep working hard! 

After all, practice makes perfect. 

-----------------------------EXOCOETIDAEE.BLOGSPOT.CA-------------------------------------------------

Saturday, 7 March 2015

Impressions, Impressions, Impressions


So, you asked for my impression on the past week?



T'is another torturous week
The Tempest has arrived
Day and Night
Night and Day
Fingers dance on the keyboard
while elves with crooked wings battle on WING
Brains on flames for minimax 
exhaustion at maximum
Tic, tic, tic 
Time is slipping, slipping
Away with our self-confidence 
As the hand hits 12
When the horses turn into rats
When our program is uploaded to Markus
All is done
Nothing could be done
Do not weep for thy failures
Prepare for the next round 



Indeed, Assignment 2 was very challenging. In the end, our minimax works with Subtract the Square game, but is incompatible(somehow) with the TippyGameState after one round. 
Even though the deadline is long past, I will continue my search for bugs that impeded the program from running correctly. 
For this assignment, none of our group members sought help from instructors. In the future, I would like to manage time in a more efficient manner and make time for consulting.