Wednesday, April 10, 2013

Exam time!

Exam is approaching soon... next week. This is just a mini update during the exam period. I have started going through the past annotated slides, and am done about 40% studying for the course. I have a chemistry exam the day before csc104 exam, so this week I am working double time trying to go through both courses work from the beginning. I will keep you guys updated on how the exam went, so don't stop reading just yet!

EDIT 17th April 2013: EXAM Time is today! (in a couple hours). I am currently reviewing everything and going through lecture notes, etc. Wish you all good luck :)

Wednesday, April 3, 2013

Closing Remarks

I found Project 1 to be one of the most challenging assignments in csc104, and so I figured i’d talk a bit about it here. Going around reading a few slogs from fellow students, I was relieved to know that I was not the only one who had struggled with the first project. There were many problems while trying to solve the code, but in the end when it all worked out without error it was a learning experience!

Let me take a problem me and my group had with the ball program. The key-press function was the reason of many confused looks from my group. The first thing we did was  ask ourselves what the function wants the program to do or accomplish? After understanding the problem, we devised a plan - that plan was to first take a look at the check expect for the up and down keypresses, which we had trouble with.


      (check-expect (key-press (make-ball 0 0 1 1) "down") (make-ball 0 0 1 2))
      (check-expect (key-press (make-ball 0 0 1 1) "up") (make-ball 0 0 1 0))
      (check-expect (key-press (make-ball 0 0 1 1) "left") (make-ball 0 0 0 1))
      (check-expect (key-press (make-ball 0 0 1 1) "right") (make-ball 0 0 2 1))

From the check expect, we got a little relief looking at how the program is supposed to function with an arbitrary input. From the check-expect we observed that pressing the "down" arrow key required adding 1 to the dy value of the function make-ball, and pressing "up" on the arrow key requires the decreasing of  1 in the dy value of the function. 
(meaning that make-ball changed its values from 0 0 1 1 to 0 0 1 0 when the up key was pressed). Key-press "left" and "right" were already given for the project.

The plan was to use the given "left" and "right" conditions as a template, and by doing that  along with the knowledge from check-expect to solve the problem. What was left now was to just carry out the plan and call it a success (or failure, in which case we would have to go backward and make/revise a new plan after seeing why the original didn’t work)

This is the code we wrote following the steps:

   (define (key-press b k)
     (make-ball
        (ball-x b)
        (ball-y b)
        (cond
            [(equal? k "left") (- (ball-dx b) 1)]
            [(equal? k "right") (+ (ball-dx b) 1)]
            [else (ball-dx b)])
        (cond
            [(equal? k "up") (- (ball-dy b) 1)]
            [(equal? k "down") (+ (ball-dy b) 1)]
            [else (ball-dy b)])))
   

This was the result, and the final step that was left was to look back and make sure that the function was... well, “functioning” properly (bad pun). We made sure of that by running the program many times and trying out different keypresses of the arrow keys, making sure they live up to their function/use.

We saw that the function was working properly and had solved the problem. Hooray!, and off to MarkUs the program went.

Tuesday, April 2, 2013

Getting Close

        Seems like the weather is playing april fools with us in Toronto, as we still need a jacket to go outside this week. CSC seems to be nearing its final classes, as with other courses it will be dearly missed. It was one of the very few courses which I enjoyed in my first year, partly because it was a computer course which taught me many basics of computing. Professor Heap is an amazing teacher, and it seldom felt boring being in his lectures.

        Reading other students' slogs, I heard that Anna (annaleecsc104.blogspot.ca) also feels the same about the second term test as me, that it was a bit unexpected of a mark, but the assignments made up for it, equaling them out.

        As I talked about in a past post, I am going to write about a slight photo manipulation problem I had in Dr. Racket. The problem was with how to swap the colour intensity in a image. I was trying to swap the red and green values of a picture of a chameleon, similar to the example Prof. Heap did in class, but then was multiplying the blue value to double, to test its effect on the overall picture. It turned out that the values for red, green, blue and alpha have a upper maximum of 255 or 256, and the doubling of the blue was sometimes causing the blue value to go over the maximum.