Here is a simple pathfinding algorithm, resembling Dijkstra's greedy algorithm. This is a fairly old document, slightly touched up. In pathfinding, we start at the origin, and try to find the shortest way to the destination. We do this by counting for each square how far it is from the origin, and once we've reached the target, we trace back through the lowest numbers. This may sound confusing, but consider this: 8767D9876 D is the destination 765678765 654567656 ##3####4# # is a wall (impassable) 4321S1234 S is the start (origin) The numbers represent the minimum amount of steps taken to get from the destination to the given square. If we now trace back through the lowest numbers: 67D 567 4 ##3#### # 21S We can derive a path: D ... . ##.#### # ..S which is what we want. We could also allow diagonal movement, hexagonal tiles, basically anything. You could also add higher step increments (10 for vertical and horizontal, and 14 for diagonal, or for instance higher cost for different terrain types) What follows is a way we could implement this algorithm. Add an element to mapsquare type. make it a short int, should be enough, and call it something like 'path'. 1: Origin is now the current square. 2: select an adjacent square who's still set to 0, or whose value is greater than the current square + 1. if there's none, goto 5. 3: give the selected square a value of the current square +1. if the selected square is the target, goto 7 4: push selected square onto a list of unfinished squares. goto 2. 5: pop the first value from the unfinished list, make it the current square. 6: goto 2. 7: Target is now the current square. 8: Select the adjecent square with the lowest value. 9:store the position of the current square relative to the selected square (Nort, East, South, West etc.) if it's the origin, goto 11 after that. 10:goto 8. 11:return list of directions pathfinder demo: ..........#.........#################################. ....XXXXXXX.........########################........+. ...X......#XXXXXXXXXXXXXXXXXXXO######################. ..X.......#.........#####################.###########. #X#########.........#####################.############ #X#########.........##########@XXXXXXXXXX.####...../.. #X##......+.........#####################X##########.. #X#############+######.......############.XXXXXXXXXX.. #X######.....+.......#.......############.##########X. #X############.......#.......#######################X. #X############......./.......#.......####.....XXXXXX.. +X############.......#.......#.......########X######.. #X############.......#.......#.......####...X.....#### #X####################.......#.......####..X......#### #X####.........###############.......####..X......#### #X####.........#.............#.......####..X......#### #X####.........#.............#.......####..X......#... +X####.........#.............#.......######X#######... #X####.........XXXXXXXXXXXXXXXXXX....###..X....####... #X####........X#.............####X######.X.....####... ..XXXXXXXXXXXX.#.............#....XXXXXXX......####... ######.........#.............###########.......#######