RafaelBarbosatec / a_star

Package that uses the A * algorithm to find a way to the destination through the barriers.
MIT License
18 stars 10 forks source link

Update a_star_algorithm.dart #9

Closed Horned-Nonsense closed 8 months ago

Horned-Nonsense commented 8 months ago

Both functions perform exactly the same thing; one is enough.

RafaelBarbosatec commented 8 months ago

Hi @Horned-Nonsense ! It's not the same. using byFreeSpaces creates a grid inverted, when all is barriers and adds some free spaces.

Horned-Nonsense commented 8 months ago

@RafaelBarbosatec Same. I'll explain now. Both methods create a completely filled n * m field, which consists of barriers and free cells. We don't gain anything from the fact that we reversed the method, because:

  1. The method is completely traversed through the matrix from element (0,0) to (n,m);
  2. At each step, it checks for the presence of the element and the isBarrier condition. Here the code is simply overloaded with extra lines.

But even if we only receive data on free cells, it is enough for us to use the first method (which uses barriers). We can implement formatting in the code segment that is directly responsible for receiving data and pass the already formatted sheet to the algorithm.

RafaelBarbosatec commented 8 months ago

Makes sense! Thanks for explanation.