How to generate Array-Adjacent of a BFS from a txt file? C ++

3

I'm using CodeBlocks.

I have a .txt file that represents a maze, everything that is after : are rooms:

Thefirstlineofthefileshowsthestartcoordinate,whichinthiscaseisAS.Everyletterwrepresentsawall.SomyBFShasastheinitialnode(orinitialroot)theAS.

Torepresentthislabyrinthinagraphwouldlooklikethis:

I have to represent this graph in an adjacency matrix. And I caught in that part, that I have to generate this matrix, because to do BFS the code must know the graph. I could not think of a way to represent this adjacent array by reading this file, please any suggestions, ideas, material, would help me a lot.

Note: My code can already get and store the labyrinth in an array, without the letters before the : and without the initial coordinate. I have the complete maze in an array. To say who is the neighbor of whom and generate the graph is what I can not do.

    
asked by anonymous 10.01.2016 / 15:43

1 answer

1

My tip is to create your adjacency array as a 150x150 size array and use the ASCII value of the characters as positions in the array.

Taking the A: B W W V line of your file as an example, your first step is to ignore W , after all it does not add any information to the graph. Then you convert the letters to their respective values in the ASCII table . A 65 , B 66 and V 86 . So you use these values as indexes in your adjacency array: the 65 line of the array would have all its values as 0 (indicating no connection to other nodes) except for the 66 and 86 columns, where the value would be 1 , indicating connection to the% nodes B and V , respectively.

And to handle the special cases where the "name" of the node is the set of two letters, just add the ASCII value of both. Example: AS turns 148 ( 65 + 83 ).

    
21.02.2016 / 02:45