Finding the fewest steps between two points?

I have a grid, the grid has two "materials" -

  • floor
  • Wall

For instance:

This is An Example Of a Grid In this grid, we have objects with size and location (the location of the object is the upper left point).

On each object we can do some action, for example -

  • Move up
  • Go down
  • Move left
  • Move right
  • Rotate the object (relative to the upper left point)

I need to create a function that returns me the Minimum number of actions that I need to do for an object to move it from one point to another ( I only need the number of actions ).

I solved this problem by using dijkstra algorithm , but without turning action .

- .

-

  • - enter image description here

enter image description here

, .

+4
4

, , BFS .

BFS , , :

1. Enqueue every point that is accessible (not a piece of wall, and not visited) and connected to the current point.
2. Dequeue current point and mark it as VISITED.

, BFS , .

, BFS , "":

-, , "". .

(, 1 * 2, ).

00: The point can't be accessed, neither the object is horizontal nor vertical. 
10: The point can be accessed if the object is horizontal
01: The point can be accessed if the object is vertical
11: The point can be accessed if the object is either horizontal or vertical

, :

img1

00,

enter image description here

, .

, , " " :

connected . :

---------
| 01| 10|
|---|---|
| 10|   |
---------    (Not Connected from top-left to either top-right or bottom-left)


---------
| 11| 10|
|---|---|
| 01|   |
---------    (Connected from top-left to both top-right and bottom-left)


---------
| 10| 10|
|---|---|
| 01|   |
---------    (Connected from top-left to top-right, but not connected to bottom-left)

, . BFS 2- . Dequeue, , connected , , BFS.

, , , . , .

enter image description here

+2

2 ( : ). , , , , .

BFS (.. ).

+5

, , , , , , .

  • , .
  • - ( 4 , /).
  • (i )
  • .
  • (do while) , 90 .
  • () , ( x/y, z)

, , , 90- . ~ 9 .

0

" " , , .

-2

All Articles