SHOW:
|
|
- or go back to the newest paste.
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 | ||
26 | imlazy(pos0,pos0) | |
27 | imlazy(pos0,pos1) | |
28 | imlazy(pos0,pos2) | |
29 | imlazy(pos0,pos3) | |
30 | imlazy(pos0,pos4) | |
31 | imlazy(pos1,pos0) | |
32 | imlazy(pos1,pos1) | |
33 | imlazy(pos1,pos2) | |
34 | imlazy(pos1,pos3) | |
35 | - | end ) |
35 | + | |
36 | imlazy(pos2,pos0) | |
37 | imlazy(pos2,pos1) | |
38 | imlazy(pos2,pos2) | |
39 | imlazy(pos2,pos3) | |
40 | imlazy(pos2,pos4) | |
41 | imlazy(pos3,pos0) | |
42 | imlazy(pos3,pos1) | |
43 | imlazy(pos3,pos2) | |
44 | imlazy(pos3,pos3) | |
45 | imlazy(pos3,pos4) | |
46 | imlazy(pos4,pos0) | |
47 | imlazy(pos4,pos1) | |
48 | imlazy(pos4,pos2) | |
49 | imlazy(pos4,pos3) | |
50 | imlazy(pos4,pos4) | |
51 | ||
52 | return true | |
53 | ||
54 | --[[minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm) | |
55 | ^ -> table containing path | |
56 | ^ returns a table of 3d points representing a path from pos1 to pos2 or nil | |
57 | ^ pos1: start position | |
58 | ^ pos2: end position | |
59 | ^ searchdistance: number of blocks to search in each direction | |
60 | ^ max_jump: maximum height difference to consider walkable | |
61 | ^ max_drop: maximum height difference to consider droppable | |
62 | ^ algorithm: A*_noprefetch(default), A*, Dijkstra | |
63 | ]] |