update bot.md

This commit is contained in:
Bluub
2021-06-20 21:42:20 +02:00
parent 8f081e53ab
commit 605a795f33
2 changed files with 16 additions and 65 deletions
-65
View File
@@ -41,71 +41,6 @@ function PrintMap(map, MaxX, maxZ)
end
end
function getNeighborsDefend(node)
local neighbors = {}
for _, dir in ipairs(Dirs) do
local neighborX = node.x + dir.x
local neighborY = node.y + dir.y
if neighborY <= MaxY and neighborX <= MaxX then
if neighborY >= 0 and neighborX >= 0 then
if Map[neighborX][neighborY] == 0 and Danger[neighborX][neighborY] ~= 1 then
table.insert(neighbors, {x = neighborX, y = neighborY})
end
end
end
end
if #neighbors == 0 and Danger[node.x][node.y] <= 1 then
for _, dir in ipairs(Dirs) do
local neighborX = node.x + dir.x
local neighborY = node.y + dir.y
if neighborY <= MaxY and neighborX <= MaxX then
if neighborY >= 0 and neighborX >= 0 then
if Map[neighborX][neighborY] == 0 then
table.insert(neighbors, {x = neighborX, y = neighborY})
end
end
end
end
end
return neighbors
end
function dist(nodeA, nodeB)
return math.sqrt(math.pow(nodeB.x - nodeA.x, 2) + math.pow(nodeB.y - nodeA.y, 2))
end
function getNeighborAttack(node)
log("atta")
local neighbors = {}
for _, dir in ipairs(Dirs) do
local neighborX = node.x + dir.x
local neighborY = node.y + dir.y
if neighborY <= MaxY and neighborX <= MaxX then
if neighborY >= 0 and neighborX >= 0 then
if Map[neighborX][neighborY] <= 1 and Danger[neighborX][neighborY] ~= 1 then
table.insert(neighbors, {x = neighborX, y = neighborY})
end
end
end
end
return neighbors
end
function getPathToEnemy(player, enemies)
local minDist = 100000
local res = {}
for _, enemy in ipairs(enemies) do
local currDist = dist(player, enemy)
if currDist < minDist and enemy.x ~= player.x and enemy.y ~= player.y then
minDist, res = currDist, enemy
end
end
local path = pathfind(player, res, getNeighborAttack)
return path
end
function getPathToSafeSpace(player)
local res = getClosestSafeSpace()
log("run to")