diff --git a/Bot.md b/Bot.md index 9c04ca05..1d1d08ac 100644 --- a/Bot.md +++ b/Bot.md @@ -3,6 +3,13 @@ A bot in this bomberman is using a lua script as way to choose what to do So you can make your own with some helper functions given from C++ +## Update function + +Each frame, the game will call the "Update" function in the script. +This is the same lua state as the last call so this means you can set global variables to keep data between frames + +Update function should take no arguments. + ## Map Blocks ```lua @@ -54,4 +61,13 @@ function getClosestSafeSpace(); -- canPutBombSafe returns true if player can put a bomb and find a path to safe space if bomb is put function canPutBombSafe(); + +-- getRadius returns the explosion radius of the current player +function getRadius(); + +-- getEnemies returns a table with enemies position {{x = X, y = Y}, ...} +function getEnemies(); + +-- getEnemies returns a table with enemies position rounded {{x = X, y = Y}, ...} +function getEnemiesRound(); ``` \ No newline at end of file diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index a77ad6f0..f3a6522e 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -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")