Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Thursday, April 29, 2010

Coily AI

I've been working a bit on making the snake, "Coily," chase Q*bert around the pyramid. I came up with an algorithm for deciding on which way the snake should jump, based on where he is and where Q*bert (his prey) is:
Deciding whether Q*bert is above or below the snake is pretty easy - I just compared row numbers. But picking between the left and right was more of a challenge. Eventually, I came up with an expression:
leftRightCriteria = coilyRow-preyRow - 2*(coilyRowPos-preyRowPos)
I found that if this "leftRightCriteria" was less than zero, then Q*bert was to the left of Coily; if it was greater than zero, then Q*bert was to the right of Coily; if it was zero, Q*bert was directly above or below Coily. So now I could apply this to the decision tree.

                

No comments:

Post a Comment