Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Detect unjoined area algorithm

I need to detect if two coordinates in the map are joined (or two areas, same thing), meaning if there is a possible path from Point A to Point B. Any obstacle (event, impassable tile, etc) can prevent the existence of such a path (if the map is pretty cluttered).

The obvious thing to do first is make a sort of array that contains empty tiles and "walls".

But then what? How would I make a efficient algorithm that knows if there is a possible path (I don't need to find the actual path)?. Brute force is more or less an option. Suggestions or references?
 
Though about it more. I could preprocess the map to separate the biggest into nodes, add connections between nodes for every (narrow) path. Then whenever something passes by one of these narrow paths, I could check the immediate surroundings to check if that thing (event or whatever) blocks that path. So I could remove that connection between the two area (nodes). It's much easier to check if two nodes are not connected then two areas.

Still, it's quite error-prone (how do I know if my big area isn't split?). There must be some other way right?
 
You can put an edge between each tile and any of the 4 tiles next to it(left,right,up,down) which isn't blocked. Next it's just implementing one of the famous shortest-path algorithms.
If no path is found, the areas are unjoined.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top