It is currently 23 Apr 2024, 16:06
   
Text Size

Using SVars for AI deck building

Post MTG Forge Related Programming Questions Here

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

Using SVars for AI deck building

Postby mcrawford620 » 08 Jul 2016, 16:52

I was adding some DeckHints for some recent cards based on this recent discussion. I started adding hints for the Allies in BFZ, and realized that every card I was adding it to already had "SVar:BuffedBy:Ally" in the card script. It seemed silly to add something extra when the information was already being coded into the cards.

So I was wondering if it would work to use that SVar (and possibly others) to more easily figure out what cards have synergy with each other when the AI is building the limited decks. The only problem I ran into is not my lack of understanding the different types of Card objects and where I can actually get the SVar information, and not fully understanding all of what SVars are used for. I ended up having to write something like this in LimitedDeckBuilder:

Code: Select all
Iterable<Map.Entry<String, String>> vars = cardToAdd.getRules().getMainPart().getVariables();
    for (Map.Entry<String, String> var : vars) {
        if (var.getKey().equals("BuffedBy")) {
Because cardToAdd is a PaperCard which doesn't have real easy access to the SVars. Is this the right approach? Or should I be doing something else to get that info?

Also, this idea of using BuffedBy works great for Ally because it's a creature type. But I found out that BuffedBy can contain lots of different things, like "Color.Colorless" or "Land" or "Creature". Some of those might be useful too for figuring out card synergies, but how do I tell what kind of thing the value is referring to? I.e., in the code, is there a way to know that "BuffedBy:Ally" is referring to a creature type, and "BuffedBy:Color.Colorless" is referring to a color?
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Using SVars for AI deck building

Postby Max mtg » 10 Jul 2016, 08:52

In my opinion, it would be best to keep deck-building strategies separate from the cards essence.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: Using SVars for AI deck building

Postby mcrawford620 » 10 Jul 2016, 15:46

Agreed. So does that mean you like or don't like the idea of using the information in the card scripts (like the SVars) for figuring out which cards work well with other cards? Couldn't quite tell which direction you were leading with your response. :-)

I think the whole DeckHints system kept the deck-building more intertwined with the card scripts, but (like the RemAIDecks) may be a necessarily evil for certain things. But the ultimate way would be to have the AI read the card scripts and figure out on its own which cards to use with other cards, which is what I was trying to get at.

I started a branch (LimitedCardRanker) with some work on it if you have time to check it out.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Using SVars for AI deck building

Postby mcrawford620 » 10 Jul 2016, 18:22

Well, the more I think about it the less I'm sure my way is right. Maybe adding more DeckHints to the card scripts is the way to go?

One problem I had was that many synergies are not able to be handled by the DeckHints system. Like anything that benefits from having +1/+1 counters on it -- there's no easy way to find cards that give out +1/+1 counters, so there's no easy way to use a DeckHints tag.

So either the AI needs to parse the rules of the card, and figure out that "this card wants counters, and these other cards give counters," or there needs to be tags for both sides. The first way (parsing the card) seems very difficult, but the second way requires more manual input.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Using SVars for AI deck building

Postby friarsol » 01 Aug 2016, 14:02

So is there any reason CardRanker isn't static?

It doesn't seem to actually have any member variables/functions, and it feels like it's just getting passed in all of the data points it needs to calculate each time. I have (slowly) been doing some work with drafting trying to get draft-matters Conspiracy cards working, and one of the things I'm considering is spinning BoosterDraftAI into 7 discrete objects.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Using SVars for AI deck building

Postby mcrawford620 » 01 Aug 2016, 16:07

No, you're right, there's no reason; it should be static. I just started out with it as a normal class and never went back and thought about making it static.

I'm on vacation so I can't get in and make the changes right now, but I could do it when I get some time next week. Or you can do it of course if you have time.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times

Re: Using SVars for AI deck building

Postby friarsol » 01 Aug 2016, 17:32

mcrawford620 wrote:No, you're right, there's no reason; it should be static. I just started out with it as a normal class and never went back and thought about making it static.

I'm on vacation so I can't get in and make the changes right now, but I could do it when I get some time next week. Or you can do it of course if you have time.
If I get to that part of the code first, I'll just roll it into my changes. Just wanted to make sure there wasn't anything going on before I just commandeered it.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Using SVars for AI deck building

Postby friarsol » 18 Aug 2016, 17:59

Hey mcrawford620

Were you done with your changes for draft deck building for now? I'm almost ready to disconnect BoosterDraftAI and spin it down. Everything is still using the CardDrafter stuff that you just fixed up, so mostly all I care about are if you are done touching BoosterDraftAI so it won't smash your changes.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Using SVars for AI deck building

Postby mcrawford620 » 18 Aug 2016, 18:42

Yep, I'm done. I did convert CardRanker to static, but that was all I was going to do.
mcrawford620
 
Posts: 112
Joined: 25 Jun 2012, 16:59
Has thanked: 55 times
Been thanked: 25 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 38 guests


Who is online

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

Login Form