java - How to find specific path patterns efficiently? -


Searching for a specific path on the grid is to find a pattern similar to the 2D grid of simple nodes: < / P>

  Public category tIllnode {Private Final IND; Public tile node leftNeighbour; Public TileNode Top Now; Public tile node right; Public tile node below; Private Tilestate OnTelGameState; }  

If a neighbor is not able to cross the current node then this state is set to outOfGame . I tried with the recursive DFS Algig to find all the paths but the complexity was terrible. I will try to search the path to search with those paths: Enter image details here < / P>

The red nodes are those where we start and end, the black lines are the paths, which should go to other nodes (neighbors), who are capable of passing.

We do not consider any other path other than those specified and certainly there is no limit to the length of those paths.

Edit: I would like to check that there is a way between two nodes that will follow the path on the image. It can be very simple that more than one of these may exist, it looks like those paths

I think your data structure does not lend you to find yourself, because you want the path, because you are not looking for any path, but for the path of a certain size

It may be better to work with a real grid of data, that is, a graph-like structure with two-dimensional array links should at least let you know your horizontal and vertical positions (X, Y) address needed.

Then you can treat your problem: Find the vertical path, the path where the middle section is vertical. The y coordinate of the two tiles (upwards) are the same when there are no vertical paths. Then find the horizontal path.

So if the y position of tile is different:

  • Left and the topmost position which is the start and end tile, [L1, R1] and [L2, R 2].
  • When both L1 and L2 are out of the left boundary of the grid or if both R1 and R2 are out of the right edge of the grid, you have a way.
  • Find the interval of two categories, [L, R] = [L1, R1] ∩ [L2, R2]. If that intersection is empty, then there is no (vertical) path.
  • For all X positions in [L, R], check whether (x, y1) to (x, y2).

Do this for a horizontal path if there is no vertical path.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -