Matrix based game: path finding

Hi,

I'm writing a simple PacMan clone, in which the monsters form some kind of neural network. When a monster spots PacMan, it sends PacMan's coordinates to the other monsters, which then move to that location. When there is no target set, the monsters alway return to their home base, where the current location of PacMan is alway available.

Anyway, I want to let the monsters move the shortest path from their current location to the target location. Suppose I have the following simple map (matrix bases):

1,1,1,1,1,1,1,1,1,1

1,0,0,0,0,0,0,0,0,1

1,0,1,1,1,0,1,1,B,1

1,0,1,0,0,0,0,1,*,1

1,0,1,1,1,1,*,*,*,1

1,*,*,*,1,0,*,1,0,1

1,A,1,*,*,*,*,1,0,1

1,0,1,1,0,1,1,1,0,1

1,0,0,0,0,0,0,0,0,1

1,1,1,1,1,1,1,1,1,1

The path (drawn by *) is the shortest path from A to B. Which algorithm should be used to solve this problem? How should it be implemented?

Thanks,

Jeroen

[962 byte] By [j_oosterlaar] at [2007-9-27 21:43:32]
# 1
Treat your matrix as a graph and use a shortest path algorithm such as dijkstra's algorithm.
alee1010 at 2007-7-7 3:42:11 > top of Java-index,Other Topics,Java Game Development...
# 2

> Treat your matrix as a graph and use a shortest path

> algorithm such as dijkstra's algorithm.

I looked it up, and i really liked that algorithm.

good thing you came along, because I needed to do a little pathfinding of my one for a game.

and jeroen, I hope you remember all those lessons from programming 2C.

they could come in handy now. ;)

robert.

suspision at 2007-7-7 3:42:11 > top of Java-index,Other Topics,Java Game Development...
# 3
hey jeroenga je ook een spelletje maken?heb je die van mij gezienkijk onder thread/topic Space Attack
EDNA at 2007-7-7 3:42:11 > top of Java-index,Other Topics,Java Game Development...
# 4
Didn't the monsters from the first pac-man work together?If i recall correctly they worked as a team each with special tasks, 1 was a scout who gave coordinates to 2 other ghosts, the other ghost stayed back and the idea was that you eventually get trapped.
EDNA at 2007-7-7 3:42:11 > top of Java-index,Other Topics,Java Game Development...