From 411d2f6d6a6e5370d33f0f54b2f2de7147a9d977 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Mon, 6 Sep 2021 20:11:36 +0200 Subject: started ai --- game/ground.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'game/ground.cpp') diff --git a/game/ground.cpp b/game/ground.cpp index 5f58717..cd67751 100644 --- a/game/ground.cpp +++ b/game/ground.cpp @@ -65,23 +65,25 @@ std::vector Ground::move_area (Gst &gst, Entity &ent) { int movecost = gst.inv->tiles[tiles[t]].move_cost; if (movecost > maxcost) movecost = maxcost; int walkedm = maxf.m - movecost; - bool obstructed = false; + bool obs_enemy = false, obs_friend = false; for (Entity &e : gst.entities) { - if (e.owner != ent.owner && at(e.x, e.y) == t) { - obstructed = true; + if (at(e.x, e.y) == t) { + if (e.owner != ent.owner) obs_enemy = true; + else obs_friend = true; break; } } - if (walkedm >= 0 && !obstructed) { + if (walkedm >= 0 && !obs_enemy) { frontier.emplace_back(t, walkedm); - moves.push_back(t); + if (!obs_friend) { + moves.push_back(t); + } } } } visited.push_back(maxf.pos); } - std::cout << "iters: " << iter; return moves; } -- cgit v1.2.3-54-g00ecf