IceYGO / windbot

A C# bot for ygopro, compatible with the ygosharp server.
MIT License
81 stars 106 forks source link

Wrong SynchroMaterialSelection #206

Open TheSwerik opened 2 weeks ago

TheSwerik commented 2 weeks ago

I noticed that OnSelectSum has a bug:

If a mandatory card has an effect that allows it to optionally change its level, this effect does not get used in OnSelectSum. Example Card: Yamatako Orochi

LuckyBot tried to Synchro summon a Level 9 Monster with Yamatoko Orochi and two Level 1 non-tuners on the Field and could not do it, because the code (in general, not only for LuckyBot) never considers Yamatoko Orochi to be Level 8:

for (int k = 0; k < mandatoryCards.Count; ++k)
{
        sumval -= mandatoryCards[k].OpParam1;
}

IList<ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max, _select_hint, mode);

(Yamatoko Orochi has OpParam1 = 1 and OpParam2 = 8)

I cannot quickly think of a good way to check for all combinations of mandatory cards and OpParams. Something like this but there is probably a non-recursive way:

// ...
IList<ClientCard> selected = SelectSumRecursive(0, sumval);

IList<ClientCard> SelectSumRecursive(int cardIndex, int sumVal)
{
    if (cardIndex >= mandatoryCards.Count) return _ai.OnSelectSum(cards, sumVal, min, max, _select_hint, mode);

    ClientCard card = mandatoryCards[cardIndex];
    for (int opParam = 0; opParam < 2; opParam++)
    {
        int opParamValue = opParam == 0 ? card.OpParam1 : card.OpParam2;
        int tempSumVal = sumVal - opParamValue;

        IList<ClientCard> tempResult = SelectSumRecursive(cardIndex + 1, tempSumVal);
        if (tempResult.Count >= min) return tempResult;
    }

    return new List<ClientCard>();
}
// ...

I opened a PR with this code to better understand what that code is supposed to do: #207