From b9dbfebdc3c47ef4f5a60c15822f512f4330e934 Mon Sep 17 00:00:00 2001 From: Bluub Date: Thu, 17 Jun 2021 11:21:11 +0200 Subject: [PATCH] john is running even better --- assets/ai_scripts/john.lua | 28 ++++++++++++++++++- .../IAControllable/IAControllableSystem.cpp | 16 ++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index 571d0caf..ad41de5b 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -98,7 +98,7 @@ end function not_in(set, node) for _,value in pairs(set) do - if value == node then + if value.x == node.x and value.y == node.y then return false end end @@ -119,6 +119,19 @@ function getNeighbors(node) end end end + if #neighbors == 0 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 @@ -157,7 +170,10 @@ function pathfind(root, target) f_score[root] = dist(root, target) while #open > 0 do + log(#open) local curr = getLowestFromSet(open, f_score) --get lowest node of openset + log(curr.x) + log(curr.y) log("f") if curr.x == target.x and curr.y == target.y then local path = fill_path({}, came_from, target) -- fill the path with came from @@ -167,6 +183,12 @@ function pathfind(root, target) end setRemove(open, curr) -- remove curr from open setAdd(closed, curr)-- add node to closed + log("closed set") + for i, c in ipairs(closed) do + log("member") + log(c.x) + log(c.y) + end log("g") local neighbors = getNeighbors(curr) -- get neighbors of current log("h") @@ -187,6 +209,7 @@ function pathfind(root, target) end end end + return {} end function dist(nodeA, nodeB) @@ -272,6 +295,9 @@ function Update(mapinfo) log(p.x) log(p.y) end + if #pathToSafeSpace == 0 then + return 0, 0, false, false + end local f = pathToSafeSpace[1] log("first way of the path") log(f.x) diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 65a45c3a..26432c1f 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -80,6 +80,21 @@ namespace BBM state.setTable(); state.setTable(); } + for (auto &bomb : _bombs) { + Vector3f bombPos = std::get<0>(bomb); + state.push(index++); + state.newTable(); + state.push("x"); + state.push(bombPos.x); + state.setTable(); + state.push("y"); + state.push(bombPos.z); + state.setTable(); + state.push("type"); + state.push(10); + state.setTable(); + state.setTable(); + } state.setTable(); } @@ -111,7 +126,6 @@ namespace BBM int dangerLevel = std::chrono::duration_cast(timeleft).count(); if (dangerLevel == 0) dangerLevel = 1; - std::cout << "bombpos: " << bombPos.x << ", " << bombPos.z << std::endl; pushInfoDangerPos(state, index, bombPos.x, bombPos.z, dangerLevel); pushInfoDangerPos(state, index, bombPos.x, bombPos.z, dangerLevel); for (int i = 1; i < bombRadius; i++) {