Skip to main content
added 1 character in body
Source Link
munificent
  • 12.1k
  • 4
  • 36
  • 35

One option would be to calculate a second grid that takes the object's size into account by "painting" it onto the grid, like so. Here's the original grid:

#########
#..b....#
#.#.....#
#.####..#
#.......#
#.......#
#..#.#..#
#a.#.#..#
#########

We want to see if a 2x2 object can get from a to b. We calculate a second grid where everytimeevery time we have a wall (#), we add walls above and to the left of it (x), turning each single wall segment into a 2x2 one. Now it looks like:

xxxxxxxxxx
x#########
x#xxb...x#
x#x#xxx.x#
x#x####.x#
x#......x#
x#.xxxx.x#
x#.x#x#.x#
x#ax#x#xx#
x#########

We can then pathfind on this grid by treating the object as 1x1 since the grid itself takes their size into account.

One option would be to calculate a second grid that takes the object's size into account by "painting" it onto the grid, like so. Here's the original grid:

#########
#..b....#
#.#.....#
#.####..#
#.......#
#.......#
#..#.#..#
#a.#.#..#
#########

We want to see if a 2x2 object can get from a to b. We calculate a second grid where everytime we have a wall (#), we add walls above and to the left of it (x), turning each single wall segment into a 2x2 one. Now it looks like:

xxxxxxxxxx
x#########
x#xxb...x#
x#x#xxx.x#
x#x####.x#
x#......x#
x#.xxxx.x#
x#.x#x#.x#
x#ax#x#xx#
x#########

We can then pathfind on this grid by treating the object as 1x1 since the grid itself takes their size into account.

One option would be to calculate a second grid that takes the object's size into account by "painting" it onto the grid, like so. Here's the original grid:

#########
#..b....#
#.#.....#
#.####..#
#.......#
#.......#
#..#.#..#
#a.#.#..#
#########

We want to see if a 2x2 object can get from a to b. We calculate a second grid where every time we have a wall (#), we add walls above and to the left of it (x), turning each single wall segment into a 2x2 one. Now it looks like:

xxxxxxxxxx
x#########
x#xxb...x#
x#x#xxx.x#
x#x####.x#
x#......x#
x#.xxxx.x#
x#.x#x#.x#
x#ax#x#xx#
x#########

We can then pathfind on this grid by treating the object as 1x1 since the grid itself takes their size into account.

Source Link
munificent
  • 12.1k
  • 4
  • 36
  • 35

One option would be to calculate a second grid that takes the object's size into account by "painting" it onto the grid, like so. Here's the original grid:

#########
#..b....#
#.#.....#
#.####..#
#.......#
#.......#
#..#.#..#
#a.#.#..#
#########

We want to see if a 2x2 object can get from a to b. We calculate a second grid where everytime we have a wall (#), we add walls above and to the left of it (x), turning each single wall segment into a 2x2 one. Now it looks like:

xxxxxxxxxx
x#########
x#xxb...x#
x#x#xxx.x#
x#x####.x#
x#......x#
x#.xxxx.x#
x#.x#x#.x#
x#ax#x#xx#
x#########

We can then pathfind on this grid by treating the object as 1x1 since the grid itself takes their size into account.