Guidance for path-finding with ATL and ATC

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
ac3raven
Citizen
Posts: 60
Joined: Tue May 19, 2009 1:14 am

Re: Guidance for path-finding with ATL and ATC

Post by ac3raven »

Code: Select all

local map = {
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 0, 0, 84, 84, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	}

	
local Grid = require "jumper.grid"
local Pathfinder = require "jumper.pathfinder"

local processOnDemand = true
local grid = Grid(map,processOnDemand)
local walkable = 0
local myFinder = Pathfinder(Grid(map),'JPS', walkable)

local startx,starty = enemy.x,enemy.y
local endx,endy = player.x,player.y

local path, length = myFinder:getPath(startx, starty, endx, endy)
if path then
  print(('Path found! Length: %.2f'):format(length))
    for node, count in path:iter() do
      print(('Step: %d - x: %d - y: %d'):format(count, node.x, node.y))
    end
end
So, theoretically, this would allow each individual enemy to find a path toward the player and move along the found path. My questions are:

1. Which parts of this go in the love.update function? Which parts go in love.load?
2. How do I make it so that each individual enemy can find a path to the ever-changing player position and move along it?


Attached is my .love file. In map.lua, I have the code for jumper. In atl.lua, I have the code for the player and ATL. In enemy.lua, I have the code for the enemies.

I have no idea what to do beyond what I have already done, and I don't know if what I have already done is correct.
Attachments
shootstuff8.love
(261.7 KiB) Downloaded 86 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Guidance for path-finding with ATL and ATC

Post by Roland_Yonaba »

First of all, let me bring some fixes to the code you posted.

Using Jumper requires some basic setup. You require the library, actually the Grid and the Pathfinder modules, at the top of your code,
along with any other library you will need in your code.

Code: Select all

local Grid = require "jumper.grid"
local Pathfinder = require "jumper.pathfinder"
Then you define your collision map data, and then you create a grid object to feed the pathfinder.
Those operations are supposed to be done once. Unless you want to create a new different collision map (with new dimensions),
there is no need to recreate a grid object, nor a pathfinder instance, as they wil handle perfectly all dynamic changes in the actual world.
The following can go in love.load, for instance.

Code: Select all

function love.load()
  map = {
    -- snip --
  }
  walkable = 0 -- meaning all 0's are walkable tiles
  grid = Grid(map) -- creates a grid object from the collision map
  pathfinder = Pathfinder(grid,'JPS', walkable) -- creates a pathfinder, pass it the grid, then algorithm to be used, then the walkable.
end
From now on, you are ready to make pathfinding requests. Suppose you have an update function, where a moving agent wants to pathfind to
some location:

Code: Select all

function love.update(dt)
  -- maybe some code
  if agent.fuel_is_low then
    if not agent.moving and not agent.path then
      local path = pathfinder:getPath(agent.tile_x, agent.tile_y, station.tile_x, gas_station.tile_y)
      if path then
        agent.path = path
        agent.moving = true
      end
  end
  -- ret of the code
end
To make the agent move along the path, you just need to know that the path returned by Jumper, when found, consist of an array of {x,y} nodes.
Like this:

Code: Select all

path = {
  {x = 1, y = 1},
  {x = 2, y = 2},
  {x = 3, y = 3},
  {x = 4, y = 4},
}
You will have to write by yourself the code to render/draw the entity moving along that path, this is not the job of the library.

In case the target is constantly changin its position, you will basically have to recaculate the path to the new location. Basically.
Depending on your game, it can be cheap and fast enough; or it can also be an intensive computing process. But in most case, using some
clever tricks can help tackle this problem, but once again, all those tricks go out of the scope of this library.

Also, you might want to use Jumper to pathfind with multiple agents at the same time. Although it is feasible, the problem mentionned above can occur here as well, but once again, some clever coding tricks can help "solving" the issue.

Provided all those informations, try for yourself implementing this, it is always better.
I would not recommend to implement this in your project. Start a new one, and try to play around with Jumper, until you feel comfortable with it.
At that time, you will be able to fit it in your project.
For guidance, there's an old demo available here. It used an old version of the library, but you can take a look at the code for guidance.

Hope this helps.
User avatar
ac3raven
Citizen
Posts: 60
Joined: Tue May 19, 2009 1:14 am

Re: Guidance for path-finding with ATL and ATC

Post by ac3raven »

I've made some progress implementing jumper in a fresh game (I think), but I'm running into a problem where when I launch the game, and it errors out with "invalid location".

I'm not sure why. I based much of the code off the demo that Roland linked to.
Attachments
jumpertest.love
(173.1 KiB) Downloaded 96 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Guidance for path-finding with ATL and ATC

Post by Roland_Yonaba »

It should be related to the way you define your map data, which is wrong.
Try this instead:

Code: Select all

map = {
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 5, 6, 0, 0, 5, 6, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0},
  {0, 0, 17, 18, 0, 0, 17, 18, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 5, 6, 0},
  {0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 17, 18, 0},
  {0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 5, 6, 0, 0, 0, 5, 6, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 17, 18, 0, 0, 0, 17, 18, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}
And remember that, if you are going to define your map data like this, then it means the upper-leftmost tile is at coordinates (1,1). So do not try to path from cell(0,0) or to cell(0,0) , or the pathfinder will complain, saying the location (0,0) cannot be found on the grid.
User avatar
ac3raven
Citizen
Posts: 60
Joined: Tue May 19, 2009 1:14 am

Re: Guidance for path-finding with ATL and ATC

Post by ac3raven »

Thanks Roland. People on the IRC channel helped me figure this out. I'm making progress!

Nothing truly works yet, but I got an enemy to spawn and move toward the player in a very buggy way that makes little sense. But that's much better than whee I was a few days ago.
Attachments
jumpertest.love
(173.24 KiB) Downloaded 98 times
User avatar
ac3raven
Citizen
Posts: 60
Joined: Tue May 19, 2009 1:14 am

Re: Guidance for path-finding with ATL and ATC

Post by ac3raven »

I have reached an impasse. I can't seem to figure out how to draw the path that is being calculated, and I also don't know why the enemy's movement is so wonky.

I suspect it's because I'm doing the pathfinding incorrectly as well as the movement, but I don't know what I'm doing wrong. the previously attached .love file is my most recent one, which can be ran in 0.9. to run it in 0.8, just change line 163 in TileLayer.lua to "addq" instead of "add".

Help?
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Guidance for path-finding with ATL and ATC

Post by Zeliarden »

Yo!
Some old function that draws jumpers path
needs path as global variable

Code: Select all

	function drawp(tile_size)
		local half_tile_size = tile_size/2
		if path then
			for i=2,#path do
			local x,y = path[i].x ,path[i].y
			local x2,y2 = path[i-1].x ,path[i-1].y
		
			love.graphics.line((x2*tile_size)-half_tile_size,(y2*tile_size)-half_tile_size,(x*tile_size)-half_tile_size,(y*tile_size)-half_tile_size)			
			local r,g,b,a = love.graphics.getColor()
			love.graphics.setColor(0, 0, 255, 64)
			love.graphics.rectangle( "fill", x*tile_size-tile_size, y*tile_size-tile_size, tile_size, tile_size )
			love.graphics.setColor(r, g, b, a)
			love.graphics.print( x .. "," .. y, x*tile_size-tile_size, y*tile_size-tile_size)
			end
		end
	end
Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests