Advertisement
Guest User

pathfind_testcase

a guest
Jul 31st, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. local modname = minetest.get_current_modname()
  2. local modpath = minetest.get_modpath(modname)
  3.  
  4. print("LOADING " .. modname .. " FROM " .. modpath)
  5.  
  6. pos0 = {x=0, y=0, z=0}
  7. pos1 = {x=1, y=0, z=0}
  8. pos2 = {x=0, y=1, z=0}
  9. pos3 = {x=0, y=0, z=1}
  10. pos4 = {x=8, y=16 , z=32}
  11. function imlazy (posa, posb)
  12.         print("First pos: " .. minetest.pos_to_string(posa) .. " Secound pos: " .. minetest.pos_to_string(posb))
  13.         searchdist = 100 -- arbitrary, but larger than any distance needed
  14.                         --Increasing it does make it slower, and uses more ram (learned the hard/fun way.)
  15.         max_jump = 100
  16.         max_drop = 100
  17.         algorithm = {"A*_noprefetch","A*","Dijkstra"    --Real
  18.                 ,"Pangus","Bacon"}                              --Not so real
  19.         for index,value in ipairs(algorithm) do
  20.                 print("Algorithm " .. value)
  21.                 print(dump(minetest.find_path(posa,posb,searchdist,max_jump,max_drop,value)))
  22.         end
  23. end
  24. minetest.register_on_joinplayer(function(player)
  25.         imlazy(pos0,pos1)
  26.         imlazy(pos0,pos2)
  27.         imlazy(pos0,pos3)
  28.         imlazy(pos0,pos4)
  29.         imlazy(pos1,pos2)
  30.         imlazy(pos1,pos3)
  31.         imlazy(pos1,pos4)
  32.         imlazy(pos2,pos3)
  33.         imlazy(pos2,pos4)
  34.         imlazy(pos3,pos4)
  35. end )
  36.  
  37. return true
  38.  
  39. --[[minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)
  40. ^ -> table containing path
  41. ^ returns a table of 3d points representing a path from pos1 to pos2 or nil
  42. ^ pos1: start position
  43. ^ pos2: end position
  44. ^ searchdistance: number of blocks to search in each direction
  45. ^ max_jump: maximum height difference to consider walkable
  46. ^ max_drop: maximum height difference to consider droppable
  47. ^ algorithm: A*_noprefetch(default), A*, Dijkstra
  48. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement