Register  |  FAQ  |  Search  |  Memberlist  |  Usergroups  |  Log in 
Reply to topic
 Lua A* AStar pathfinding 
hde


Joined: 08 Oct 2007
Posts: 46
Reply with quote
I have programmed a A* AStar Lua Pathfinding routine. Not perfect but you can try for yourself. Free download on my web site (blog) http://hm3drt.blogspot.com

Example use the code:

Code:

--LUA pathfinding A* AStar algorithm EXAMPLE
--based on a articly by Patrick Lester
--http://www.gamedev.net/reference/articles/article2003.asp
--- wip ver 0.07 12.09.08 hm3drt.blogspot.com ---
-- ONLY FOR EXPERIMENTAL USE, NOT INTEND FOR COMMERCIAL USE
-- USE AT YOUR OWN RISK ! I'M NOT RESPONSIBLE FOR ANY DAMAGE !

dofile("pathfinding.lua")


      -- ------my world grid------------------
      -- sometimes the world could be much greater ;-)
      -- columns = y, rows = x
      -- 1 -> walls
      -- 0 -> accessable nodes
      -- access with grid[y][x]
      
function initGrid()
      grid1 = {};
      --example grid
      --         x->
      --y          1  2 3   4  5  6  7  8  9 10 11 12 13 14 15 16 17 18
      grid1[0] = {1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1 ,1 ,1, 1, 1 ,1, 1, 1};
      grid1[1] = {1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1 ,1 ,1, 1, 1 ,1, 1, 1};                  
      grid1[2] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ,0 ,0, 0, 0 ,0, 0, 1};
      grid1[3] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ,0 ,0, 1, 0 ,0, 0, 1};
      grid1[4] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ,0 ,0, 1, 0 ,0, 0, 1};
      grid1[5] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 1, 0 ,0, 0, 1};
      grid1[6] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ,1 ,1, 1, 1 ,0, 1, 1};
      grid1[7] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0, 0 ,0, 0, 1};
      grid1[8] = {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ,0 ,0, 0, 0 ,1, 1, 1};
      grid1[9] = {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ,0 ,0, 0, 0 ,1, 1, 1};                  
      grid1[10]= {1, 1, 1, 1, 1, 1, 1, 1, 1 ,1, 1 ,1 ,1, 1, 1 ,1, 0, 1};
      
      return grid1                  
end

-- path in table path
pt = find_path(5,2,2,8, initGrid());

if pt ~= nil then
  print("found path");
  print("path in table pt");
else
  print("no path");
end
View user's profile Send private message
  
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Good work! If you are willing, you can show something about your project in AwWiki.
View user's profile Send private message
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic