wargus icon indicating copy to clipboard operation
wargus copied to clipboard

[macOS] AI players in multi-player game do not progress

Open jupera opened this issue 1 year ago • 1 comments

Describe the bug AI players in multi-player game do not progress. They mine a single gold, then sit around (do not build town hall, etc.)

To Reproduce Using two computers... Computer 1: create a (local) multiplayer game multi-player settings: Map: Classic/A continent to explore.pud.smp.gz (8 player map) The "dedicated AI server" option selected or not doesn't seem to make any difference. removed fog of war, and set terrain to explored so that I can see what AI is doing... race, units, resources all map default Add an AI player to the list.

On computer 2: Join local game, connect to auto-discovered ip, select ready

Computer 1: verify computer 2 has joined, player 2 ready, AI player appears on player list, start the game.

Expected Behavior AI player immediately builds a town hall, collects resources, continues building, engages other players.

Desktop I'm building Wargus on two Macs using the Stratagus MacOs build instructions

And @shinra-electric 's regression to #584 mentioned in issue #438 to fix the font issues.

Mac1: M1 running macOS 14.2.1 Mac2: Intel running macOS 11.7.10

Data extraction working well (except for the data extraction source code folder and font issues mentioned in #438)

jupera avatar Jan 23 '24 04:01 jupera

This happens in the windows version as well. I reproduced with 1 human and 2 AI players on the Plains of Snow map.

jlovitt avatar May 13 '24 13:05 jlovitt

Linux too. Singleplayer skirmish (modern or classic). AI doesn't seem to do anything outside of the campaign.

Git bisect says it's this commit (in Stratagus) that broke it

commit 936b1dc09c7360072b21544cc599756bba0fa906 Author: Jarod42 [email protected] Date: Sun Nov 12 10:53:43 2023 +0100

Fix regression in editor to place units.

src/action/action_build.cpp | 2 +- src/include/unit.h | 3 +- src/unit/build.cpp | 86 ++++++++++++++++++--------------------------- src/video/cursor.cpp | 11 +++--- 4 files changed, 42 insertions(+), 60 deletions(-)

MamiyaOtaru avatar Jul 26 '24 09:07 MamiyaOtaru

fix by changing line 467 of build.cpp from if (ranges::none_of(type.AiBuildingRules, [&](const auto &rule) { to if (!type.AiBuildingRules.empty() && ranges::none_of(type.AiBuildingRules, [&](const auto &rule) {

none_of returns true (and thus CanBuildHere returns nullopt) if no building rules match.
BUT an empty set of rules also returns true: https://cpp-lang.net/docs/std/algo/ranges/none_of/ "IMPORTANT Returns true if the range is empty."

This is not the same behavior as before the commit, which iterated through rules to see if one passed if and only if (!type.AiBuildingRules.empty()) {

If AiBuildingRules was empty, it would not iterate through them and thus aichecked was never set to false so it did not return nullopt Now, if it is empty, none_of returns true as per spec so nullopt is returned

tl;dr none_of should only be checked if AiBuildingRules is not empty (compiled and confirmed)

edit if (!ranges::any_of(type.AiBuildingRules, [&](const auto &rule) { would work too, as any_of also returns true if the range is empty. In other words it's true if any of the rules match or if there are no rules, negated then so the whole if statement is false and nullopt is not returned

MamiyaOtaru avatar Jul 26 '24 23:07 MamiyaOtaru