Sunday, March 8, 2015

CSC148 March 8th 2015

Much of the focus of this week was on assignment 2, and i must say, the process of writing recursion became a lot more clear to me after figuring out how to implement minimax.  In my last post, i said that to me, writing recursion is just like induction.  First, find the base case, or cases, and then apply the inductive step.  Generally, the recursive step in writing functions is harder than identifying the base cases, but i think have finally discovered a way of thinking that will allow me to arrive at the correct recursive step.  When i worked on recursive functions in previous labs, after identifying the base case, i was often stuck thinking about what steps i need to repeat, and in what order.  Determining where place the recursive call was also difficult, as i end up thinking about too many factors all at once.  However as i worked on minimax, i began drawing my own trees, branching out from a root gamestate.  I knew what the base case of the function was, but i had trouble bringing the base case results from the leaves of the tree all the way back to the root.  After spending hours staring at the tree that i had drawn, i suddenly realized that recursion is much simpler than what i had thought.  Instead of looking at the tree and trying to think of a process that passes information from each of the leaves all the way back to the root, all i needed to do was look at how the information is manipulated between each level of nodes.  I started by looking at only the root and its children.  The root will ask each of its children a question, and then process all the answers into a single answer.  This is basically the recursive step that i was always over thinking about.  As long as i can figure out what the parent should ask its children, and how the parent can process all the answers into one, i can repeat this question on the children of the children, and so on, until the base case us reached.  This way of thinking really made the process of recursion seem much less daunting, and i am sure it will help me in the upcoming midterm.

No comments:

Post a Comment