From b8b8ee07feab7b0bc6c92aa82a8017417b16ce25 Mon Sep 17 00:00:00 2001 From: jeefo Date: Fri, 29 Mar 2024 00:21:26 +0300 Subject: [PATCH] fix: node selection when there's too less important nodes (fix #542) --- src/navigate.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/navigate.cpp b/src/navigate.cpp index 515949a..26f886e 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -383,19 +383,30 @@ void Bot::postprocessGoals (const IntArray &goals, int result[]) { } return isOccupiedNode (index); }; + static IntArray resulting {}; + resulting.clear (); - // too less to choice from just return all the goals + // too less to choice from, this is usually waypointer mistake, number of def/offensive points count should be minimum of 4 if (goals.length () < 4) { - for (size_t i = 0; i < goals.length (); ++i) { - result[i] = goals[i]; - } - return; + auto refill = [] (const IntArray &data) { + if (!data.empty ()) { + resulting.insert (0, data); + } + }; + + // combine defensive and offensive and goals together to give a chance to proceed + refill (graph.m_ctPoints); + refill (graph.m_terrorPoints); + refill (graph.m_goalPoints); + } + else { + resulting.insert (0, goals); } for (int index = 0; index < 4; ++index) { - const auto goal = goals.random (); + const auto goal = resulting.random (); - if (recurseCount <= cr::max (4, goals.length ()) && isRecentOrHistorical (goal)) { + if (recurseCount <= cr::max (4, resulting.length ()) && isRecentOrHistorical (goal)) { if (index > 0) { index--; }