c++ - How to prevent blocking path? -



c++ - How to prevent blocking path? -

i'm trying build algorithm prevents "blocking path". draw random iteams , print on map: [...]

the "x" player. can move on map, cannot remain on "#" field. after draw path blocked ("x" cannot move to, example", (3,2):

someone have idea, concept or material how write algorithm prevent draw "#" when blocked path?

here piece of code:

void build_dungeon(map_grid& map, int chance, string object) { int i, j; (i = 0; < g_map_size; i++){ (j = 0; j < g_map_size; j++){ if (rand() % 100 >= (100 - chance) && map[i][j] == "[ ]" && anti_stuck(map, i, j)){ map[i][j] = object; print_map(map); } } } }

i'm trying write anti_stuck function.

you can perform flood fill determine squares reachable given starting location. see animation the wikipedia article:

alternatively, if want determine if can reach 1 square one, utilize pathfinding algorithm such a*. again, animation wikipedia:

c++

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -