Advertisement
natie3

Maze

Aug 13th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. local function Define()
  2.   Maze = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
  3.   Maze[1] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
  4.   for i = 2, 15 do
  5.     Maze[i] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
  6.   end
  7.   Maze[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
  8. end
  9.  
  10. local function ChangeDir(dir, curdir)
  11.   if (curdir+1)%4 == dir
  12.     turtle.turnRight()
  13.   elseif (curdir-1)%4 == dir
  14.     turtle.turnLeft()
  15.   else
  16.     turtle.turnLeft()
  17.     turtle.turnLeft()
  18.   end
  19. end
  20.  
  21. local function CheckCoord()
  22.  
  23.  
  24. local openlist = {}
  25. local closedlist = {}
  26. local k = 1
  27. local tempH = 9*(math.abs(px-dx) + math.abs(py-dy))
  28. local tempG = 0
  29. table.insert(openlist, k, { x = dx, y = dy, g = tempG, h = tempH, f = tempG+tempH, par = 1})
  30.  
  31. while #openlist > 0 do
  32.   local lowestF = openlist[k].f
  33.   for i = 1, #openlist do
  34.     if openlist[i] < lowestF then
  35.       lowestF = openlist[i].f
  36.       k = i
  37.     end
  38.   end
  39.  
  40.   if not CheckCoord()
  41.     if not
  42.       table.insert(closedlist,openlist[k])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement