It is currently 20 Apr 2024, 00:21
   
Text Size

[fixed]AI suicide attacks - weird AI attack decisions

Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins

[fixed]AI suicide attacks - weird AI attack decisions

Postby Aswan jaguar » 19 Mar 2022, 12:16

Describe the Bug:
In dev I get weird AI attack decisions and suicide attacks from AI.
Example: put in play for you a Bear Cub and give AI (following the exact order) an Abattoir Ghoul and any creature that will be killed and not kill Bear Cub (just to make it more clear) let's say Elvish Hexhunter or Stone-Throwing Devils, AI will attack only with the card with the bigger in game ID so only with Elvish Hexhunter or Stone-Throwing Devils. AI will decide correctly and attack only with Abattoir Ghoul if you put Abattoir Ghoul in play after Elvish Hexhunter or Stone-Throwing Devils so Abattoir Ghoul has the bigger in game ID.

This doesn't happen in release no matter which creature has the bigger ID AI will choose correctly and not suicide attack.

Which update are you using? (date, name)Which type? (duel, gauntlet, sealed deck)
dev based on commit 2bfae / duel

What exactly should be the correct behavior/interaction?


Are any other cards possibly affected by this bug?
-
Last edited by Aswan jaguar on 14 May 2022, 13:48, edited 3 times in total.
Reason: fixed
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: AI suicide attacks - weird AI attack decisions

Postby drool66 » 19 Mar 2022, 16:54

Has to be something in 9c1c671 move ai_choose_attackers() into C
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

Re: AI suicide attacks - weird AI attack decisions

Postby Korath » 20 Mar 2022, 03:41

It seems likely. Bisection narrows it to something between 0748183f8 (which broke the build, thanks) and ed36b37a5.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: AI suicide attacks - weird AI attack decisions

Postby Aswan jaguar » 20 Mar 2022, 07:23

And with this report I finally found what was the pattern on Shandalar with AI weird attack suicide. On shandalar based on a commit at 26-12-2020. The exact opposite happens for shandalar. In the above example AI will attack only with the card with the lowest in game id.
Attachments
2022-03-20_092205.jpg
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: AI suicide attacks - weird AI attack decisions

Postby Korath » 20 Mar 2022, 09:58

I know why they're reversed, at least - the qsort comparator function in the Manalink version is just returning a bool. std::sort() expects a comparator that's equivalent to <, while qsort() expects one equivalent to <=>. The easy pattern if you don't care about overflow is rhs - lhs for a descending sort, which is what we want here.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: AI suicide attacks - weird AI attack decisions

Postby Korath » 24 Mar 2022, 02:30

I see what's causing this: ai_speculate_on_combat() stores its data sorted on card index, not on the order specified in attack_indices[], and so it disagrees with the data stored in ai_choose_attackers(). I have an ugly proof-of-concept fix in the Shandalar version - it builds the data twice - that needs some more thought.

Removing the qsort() call entirely should fix this if you want to release in the meantime, though it loses the improved alpha strikes and not letting creatures after the first sixteen to attack at all.

Two questions specific to the Manalink version:
  • Did you verify no cards have EA_ATTACK_LEGALITY_ALL set in ct_all.csv before repurposing it? Shandalar removes it at runtime.
  • When do you dispatch TRIGGER_ATTACKER_CHOSEN when the AI attacks, since it's not in ai_choose_attackers() anymore? Not that anything responds to it except Raging River.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: AI suicide attacks - weird AI attack decisions

Postby drool66 » 24 Mar 2022, 05:20

Did you verify no cards have EA_ATTACK_LEGALITY_ALL set in ct_all.csv before repurposing it? Shandalar removes it at runtime.
I'm not sure exactly which one it is. The flag was previously "EA_SHANDALAR_RAREST" so I checked the fields labeled "Flags: Unknown (Shandalar)" - these fields are all filled with zeroes.
When do you dispatch TRIGGER_ATTACKER_CHOSEN when the AI attacks, since it's not in ai_choose_attackers() anymore? Not that anything responds to it except Raging River.
I grepped for it and saw nothing in c responded to it, so I didn't worry about it. I forgot about cards in exe #-o

[EDIT]: EVENT_DECLARE_ATTACKERS was originally dispatched early in ai_choose_attackers(), but I see it's also dispatched in main_phase(). Any idea what's going on there? Should I put it back in ai_choose_attackers()?
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

Re: AI suicide attacks - weird AI attack decisions

Postby Aswan jaguar » 06 May 2022, 12:25

Your commit c885c7d ("Rebuild combat data", 2022-05-04) drool66 to solve this temporarily is not working the issue I posted is still there.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby Korath » 06 May 2022, 13:31

Current draft of the Shandalar version is in commit 9ea5597a3, branch wip/unassessed (mixed with other stuff that I did a week ago and haven't looked at since, hence the name).

Dunno on EVENT_DECLARE_ATTACKERS. main_phase() was clearly a huge mess even in the original, let alone what we're left with after reversing it. There's different codepaths for the AI, and for the human, and for the human during speculation, and there's gotos into the middles of all of them all over to deal with playing back recorded AI decisions.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby drool66 » 08 May 2022, 16:38

Your commit c885c7d ("Rebuild combat data", 2022-05-04) drool66 to solve this temporarily is not working the issue I posted is still there.
Bummer - I was testing the wrong case. I can adapt 9ea5597a3; Aswan jaguar, what do you think, should I commit & we can test from there?
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby Aswan jaguar » 08 May 2022, 20:17

drool66 wrote: I can adapt 9ea5597a3; Aswan jaguar, what do you think, should I commit & we can test from there?
Sure.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby drool66 » 13 May 2022, 00:58

Ok; 9d91447
Tested working for the case at the top of the thread (Bear Cub, Abatoir Ghoul, Elvish Hexhunter)
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby Korath » 13 May 2022, 01:35

The comparator function you're giving to qsort is still invalid as of that commit, and it would be well within its rights to crash instead of just giving you incorrect output (which it certainly will). man qsort, cppreference, some discussion and examples. Be aware the examples produce an ascending sort; you want a descending sort here.
User avatar
Korath
DEVELOPER
 
Posts: 3707
Joined: 02 Jun 2013, 05:57
Has thanked: 496 times
Been thanked: 1106 times

Re: [confirmed]AI suicide attacks - weird AI attack decision

Postby drool66 » 13 May 2022, 15:44

The comparator function you're giving to qsort is still invalid
a0f936c
User avatar
drool66
Programmer
 
Posts: 1163
Joined: 25 Nov 2010, 22:38
Has thanked: 186 times
Been thanked: 267 times

Re: [fixed]AI suicide attacks - weird AI attack decisions

Postby Aswan jaguar » 14 May 2022, 13:51

I tested about this issue and is fixed now. I tested few other scenarios and I didn't find any other issues so far.
---
Trying to squash some bugs and playtesting.
User avatar
Aswan jaguar
Super Tester Elite
 
Posts: 8078
Joined: 13 May 2010, 12:17
Has thanked: 730 times
Been thanked: 458 times

Next

Return to Archived Reports

Who is online

Users browsing this forum: No registered users and 58 guests


Who is online

In total there are 58 users online :: 0 registered, 0 hidden and 58 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 58 guests

Login Form