A
A
alexeysikora2021-11-15 17:39:50
Programming
alexeysikora, 2021-11-15 17:39:50

How to build a graph from a matrix?

I have a matrix which is a game map. This matrix looks like this:

[
        '.....',
        '..WW.',
        '.....'
]

the essence of the matrix elements is quite simple:
'.' - accessible field
'W' -

non-visitable field select 2 vertices in the graph and find the shortest path between them (the player from point A must get to goal B along the shortest path). You can only move on the map horizontally and vertically.

I just can not understand what principle I should use to build such a graph.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-11-15
@alexeysikora

Why build a graph? Each cell has only top-bottom-left-right neighbors.
And most importantly, what can be the weight of the ribs? If only cells adjacent along the side are connected, then all edges have the same weight.
https://ru.wikipedia.org/wiki/A* - look at this thing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question