This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

TI-Basic => TI-BASIC
Author Message
Phobia

Newbie

Joined: 06 Feb 2008
Posts: 20

 Posted: 07 Apr 2009 05:43:01 pm    Post subject: Hi, I wonder if anyone has a fast algorithm for a ghost's AI in pacman. Am I wrong or a pixel-test is faster than reading one value from a matrix? I had this one but it's pretty dumb the ghost walks randomly; does not chase the user: Assuming that: E=X coordinate of the ghost F=Y coordinate of the ghost when I say left;right;etc I mean the coordinate being tested (the [A] matrix stores the walls at each coordinate) #################################### :not([A](left))-not([A](right :E-Ans+not(Ans)not([A](left))(1-2randInt(0,1->E :"Test if it is eating my pacman..." :not([A](down))-not([A](up :F-Ans+not(Ans)not([A](down))(1-2(randInt(0,1->F :"Test again if it is eating my pacman #################################### This came from here: each ghost has it's list with boolean values: {left,up,right,down} at each turn I test the directions attainable by him (if there are walls or not) and refresh this list If he can go in a direction (no wall) the value is one Now I'm thinking of improving this in this way: If my absolute position in the game is to the ghost's left I will double the {left} direction (in X my coordinate is smaller - X-A<0), If i'm at it's right i will double the {right} value I can also keep track of the ghost's last direction taken so that he'll prefer going "forward"/not turning around though this is probably not necessary (I'm already the approach of the ghost with the last step) Then it goes in the direction of the biggest number in the list. If there are several, I'll use randInt (I could use the first too but probably if the maze is too convuluted the ghost will get stuck in the same zone) Any suggestions? 'Cause I want the game to be faster.. Thanks
woodswolf

Joined: 26 Feb 2009
Posts: 53

 Posted: 08 Apr 2009 10:19:17 am    Post subject: Although I don't have an AI somewhere, making an AI for a ghost is not that hard. Here is something you could try X. Direction of the ghost, this can be 1,-1,+i,-i x1+iy1->A. These are the coordinates of pacman x2+iy2->B. These are the coordinates of one of the ghosts If the ghost comes at an intersection: then A-B If abs(real(Ans)) => abs(imag(Ans Then real(Ans)/abs(real(Ans -> X Else i(imag(Ans)/abs(imag(Ans -> X end end If A=B Lose Or something like that, you could also do it with list L1 and L2, whereas pacman = L1(1) and L2(1) (coordinates and direction) and ghosts are L1(2,3,etc.etc.) and L2(2,3,etc.etc.)
Phobia

Newbie

Joined: 06 Feb 2008
Posts: 20

 Posted: 08 Apr 2009 11:10:33 am    Post subject: sorry I didn't understand this: Quote:X. Direction of the ghost, this can be 1,-1,+i,-i x1+iy1->A. These are the coordinates of pacman x2+iy2->B. These are the coordinates of one of the ghosts
woodswolf

Joined: 26 Feb 2009
Posts: 53

 Posted: 08 Apr 2009 02:04:21 pm    Post subject: in X (or any other variable), you can put the direction of the ghost. Pacman and ghosts can go up, down, left and right i is an imaginair number, a variable can store a number as x+yi. Go to mode and put a+bi, instead of REAL. 1 = up -1 = down i = up -i = down x1 + iy1 was just another way of writing x+yi, it can store the x coordinate and y coordinate.
 Display posts from previous: All Posts Oldest FirstNewest First
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
 Page 1 of 1 » All times are UTC - 5 Hours