Метатабличный / Говнокод #21601 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
if closedk>0 then
	for k=1,closedk do
		if closedlist[k].x==curbase.x+1 and closedlist[k].y==curbase.y then
			rightOK=false
		end
		if closedlist[k].x==curbase.x-1 and closedlist[k].y==curbase.y then
			leftOK=false
		end
		if closedlist[k].x==curbase.x and closedlist[k].y==curbase.y+1 then
			downOK=false
		end
		if closedlist[k].x==curbase.x and closedlist[k].y==curbase.y-1 then
			upOK=false
		end
	end
end
		
		-- Check if next points are on the map and within moving distance
if curbase.x+1>xsize then
	rightOK=false
end
if curbase.x-1<1 then
	leftOK=false
end
if curbase.y+1>ysize then
	downOK=false
end
if curbase.y-1<1 then
	upOK=false
end

		-- If it IS on the map, check map for obstacles
		--(Lua returns an error if you try to access a table position that doesn't exist, so you can't combine it with above)
if curbase.x+1<=xsize and mapmat[curbase.y][curbase.x+1]~=0 then
	rightOK=false
end
if curbase.x-1>=1 and mapmat[curbase.y][curbase.x-1]~=0 then
	leftOK=false
end
if curbase.y+1<=ysize and mapmat[curbase.y+1][curbase.x]~=0 then
	downOK=false
end
if curbase.y-1>=1 and mapmat[curbase.y-1][curbase.x]~=0 then
	upOK=false
end

Кусок кода A* какого-то чувака, который не знает что такое elseif
К тому же с 19 по 30 строки можно выпилить, просто curbase.x+1<=xsize подобных условий заменить на проверку на существование нужного элемента таблицы.

Сам код тут: https://github.com/philnelson/A-Star-Pathfinding-For-Lua/blob/master/A-star%20algorithm%20release.lua

Запостил: _____ _____, (Updated )

Комментарии (2) RSS

Добавить комментарий

Переведи на "PHP", guest!

    А не использовать ли нам bbcode?


    8