Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jupera opened this issue Jan 23, 2024 · 3 comments · Fixed by Wargus/stratagus#700 or Wargus/stratagus#709
Closed
Assignees

Comments

@jupera
Copy link

jupera commented Jan 23, 2024

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)

@jlovitt
Copy link

jlovitt commented May 13, 2024

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

@MamiyaOtaru
Copy link

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(-)

@Jarod42 Jarod42 self-assigned this Jul 26, 2024
@MamiyaOtaru
Copy link

MamiyaOtaru commented Jul 26, 2024

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

Jarod42 added a commit to Wargus/stratagus that referenced this issue Jul 27, 2024
…editor to place units.)

#closes Wargus/wargus#449
Thanks to MamiyaOtaru for investigation and fix.
Other `none_of` should be ok.
Jarod42 added a commit to Wargus/stratagus that referenced this issue Aug 5, 2024
…gression in editor to place units.) (and not fixed by 59d30da)

#closes Wargus/wargus#449
Allow AI to build building.
Thanks to MamiyaOtaru for investigation and fix.
Jarod42 added a commit to Wargus/stratagus that referenced this issue Aug 5, 2024
…gression in editor to place units.) (and not fixed by 59d30da)

#closes Wargus/wargus#449
Allow AI to build building.
Thanks to MamiyaOtaru for investigation and fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants