It is currently 19 Apr 2024, 00:11
   
Text Size

Bug: AI Mana Payment with Energy (SOLVED)

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Bug: AI Mana Payment with Energy (SOLVED)

Postby luke » 10 Mar 2018, 19:03

Currently using 1.6.7. Also testing with commit 9a3bc52 from March 8.

I do a lot of command line simulations and see a ton of messages like this:

Code: Select all
ComputerUtil : payManaCost() cost was not paid for Glorybringer. Didn't find what to pay for {R}
(Note this actually comes from the ComputerUtilMana class, not ComputerUtil)

I only found one reference to this here, but there was no follow-up (sorry, it won't let me post full link):

/forum/viewtopic.php?f=26&t=21186&p=220749#p220749

I spent some time researching this and it appears to happen when the AI is using cards like Aether Hub or Servant of the Conduit and runs out of energy. For example, 5 Aether Hubs (testing ;)) with 1 energy counter will result in the above message if the AI attempts to play Glorybringer. It successfully taps and pays the first R, but fails on the second because there is no more energy to pay additional costs.

This in itself isn't a big deal, but the problem is that costs aren't refunded:

  • The first Aether Hub is still tapped
  • Energy counter is not refunded
  • Glorybringer is in limbo somewhere -- it doesn't get put back in hand
I'm still looking at the code, but I believe there is a test phase prior to actual payment . I think the solution is to properly check additional costs (e.g. energy) while in this test phase so that the actual payment phase never happens when there is not enough energy.

This bug can be reliably reproduced by creating a deck with 30 Aether Hubs and 30 Glorybringers and having them play each other.
Last edited by luke on 12 Mar 2018, 19:21, edited 1 time in total.
luke
 
Posts: 3
Joined: 10 Mar 2018, 18:31
Has thanked: 0 time
Been thanked: 0 time

Re: Bug: AI Mana Payment with Energy

Postby luke » 10 Mar 2018, 21:37

I'm not sure if this is the best solution, but I think I might have found a fix.

In ComputerUtilMana.payManaCost (line 359), initialize energy at the top of the method:

Code: Select all
int testEnergyPool = ai.getCounters(CounterType.ENERGY);
Then in the test block after line 460:

Code: Select all
            if (test) {//<-- existing line 460

                // Check energy when testing
                CostPayEnergy energyCost = saPayment.getPayCosts().getCostEnergy();
                if(energyCost != null) {
                   testEnergyPool -= Integer.parseInt(energyCost.getAmount());
                   if(testEnergyPool < 0) {
                      // Can't pay energy cost
                      break;
                   }
                }
Since making this change, I have yet to encounter the "cost was not paid" message.

Edit: Reduced code slightly
luke
 
Posts: 3
Joined: 10 Mar 2018, 18:31
Has thanked: 0 time
Been thanked: 0 time

Re: Bug: AI Mana Payment with Energy

Postby friarsol » 11 Mar 2018, 02:02

luke wrote:I'm not sure if this is the best solution, but I think I might have found a fix.

In ComputerUtilMana.payManaCost (line 359), initialize energy at the top of the method:

Code: Select all
int testEnergyPool = ai.getCounters(CounterType.ENERGY);
Then in the test block after line 460:

Code: Select all
            if (test) {//<-- existing line 460

                // Check energy when testing
                CostPayEnergy energyCost = saPayment.getPayCosts().getCostEnergy();
                if(energyCost != null) {
                   testEnergyPool -= Integer.parseInt(energyCost.getAmount());
                   if(testEnergyPool < 0) {
                      // Can't pay energy cost
                      break;
                   }
                }
Since making this change, I have yet to encounter the "cost was not paid" message.

Edit: Reduced code slightly
Feel free to post a merge request on our Gitlab.
https://git.cardforge.org/dashboard/activity
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Bug: AI Mana Payment with Energy (SOLVED)

Postby luke » 12 Mar 2018, 19:20

Done. Sorry, won't let me post link. It's 284.

I also submit 285, 286, and 287 if you're interested.
luke
 
Posts: 3
Joined: 10 Mar 2018, 18:31
Has thanked: 0 time
Been thanked: 0 time


Return to Forge

Who is online

Users browsing this forum: No registered users and 71 guests


Who is online

In total there are 71 users online :: 0 registered, 0 hidden and 71 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 71 guests

Login Form