Page 1 of 2

Scry

PostPosted: 20 Jan 2010, 04:30
by Rob Cashwalker
One of the new spPumpTgt cards I want to add is Ferocious Charge. Simple, except for the Scry 2.

I have spent the evening devising a method which I think should work. I would like to propose that it shall be handled similarly to the "Draw a card." revision. There are a few cards that use Scry in an odd way, (damn Future Sight) but complex cards can always be hardcoded and still make use this generic scry method.

It uses a very simplistic AI to dig past basic lands and creatures if there are more than 5 of either of them in play.

I haven't put this into the SVN yet, I wanted to post it for review first.

GameAction.java
Code: Select all
  public void scry(String player, int numScry)
  {
     CardList topN = new CardList();
     PlayerZone library = AllZone.getZone(Constant.Zone.Library, player);
     for (int i = 0; i < numScry; i++)
     {
        topN.add(library.get(0));
        library.remove(0);
     }
    
     int N = topN.size();
    
     if (player.equals(Constant.Player.Human))
     {
        for (int i = 0; i < N; i++)
        {
           Object o;
           o = AllZone.Display.getChoiceOptional("Choose a card to put on the bottom of your library.", topN.toArray());
           if (o != null)
           {
              Card c = (Card)o;
              topN.remove(c);
              library.add(c);
           }
           else   // no card chosen for the bottom
              break;
        }
        N = topN.size();
        if (N > 0)
           for (int i = 0; i < N; i++)
           {
              Object o;
              o = AllZone.Display.getChoice("Choose a card to put on the top of your library.", topN.toArray());
              if (o != null)
              {
                 Card c = (Card)o;
                 topN.remove(c);
                 library.add(c, 0);
              }
              // no else - a card must have been chosen
           }

     }
     else // computer
     {
        for (int i = 0; i < N; i++)
        {
           boolean b = false;
           if (topN.get(i).getType().contains("Basic"))
           {
              CardList bl = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards());
              bl = bl.filter(new CardListFilter()
              {
                 public boolean addCard(Card c)
                 {
                    if (c.getType().contains("Basic"))
                       return true;

                    return false;
                 }
              });
             
              if (bl.size() > 5) // if control more than 5 Basic land, probably don't need more
                 b = true;
           }
           else if (topN.get(i).getType().contains("Creature"))
           {
              CardList cl = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards());
              cl = cl.filter(new CardListFilter()
              {
                 public boolean addCard(Card c)
                 {
                    if (c.getType().contains("Creature"))
                       return true;

                    return false;
                 }
              });
             
              if (cl.size() > 5) // if control more than 5 Creatures, probably don't need more
                 b = true;                
           }
           if (b == true)
           { 
              library.add(topN.get(i));
              topN.remove(i);
           }
        }
        N = topN.size();
        if (N > 0)
           for (int i=0; i<N; i++) // put the rest on top in random order
           {
              Random rndm = new Random();
              int r = rndm.nextInt(topN.size());
              library.add(topN.get(r), 0);
              topN.remove(r);
           }
     }
  }

Re: Scry

PostPosted: 20 Jan 2010, 20:05
by DennisBergkamp
I think it looks good, add it! It would also allow for a bunch of new cards that could be coded exclusively through keywords.

Re: Scry

PostPosted: 20 Jan 2010, 20:56
by Rob Cashwalker

Re: Scry

PostPosted: 20 Jan 2010, 20:58
by DennisBergkamp
That's it ? Aw. Well, at least I could use the keyword for hardcoding the others.

Re: Scry

PostPosted: 20 Jan 2010, 21:16
by Marek14
Maybe you could do fateseal as well when you're at it :)

Re: Scry

PostPosted: 20 Jan 2010, 21:24
by lord of 13
You guys forgot Lose Hope! And Forsee. The rest of the cards probably have to be hardcoded

Re: Scry

PostPosted: 21 Jan 2010, 00:14
by Rob Cashwalker
We'll get around to doing the -x/-y spells as a keyword at some point. Doing a discard keyword sometime soon is not out of the question.

But the one where the scry occurs before a keywordable effect would make it difficult.
And there's one that's like Scry 1, scry 2, and then scry 3...

On the other hand, with the return to Mirrodin, the keyword may have a comeback.

I'll add it into GameAction now. Then I'll work out adding it to the code where we put the Cantrip handler. It may be tricky - I don't want to clog up that section with parsing code to determine N in "Scry N".

Re: Scry

PostPosted: 26 Jan 2010, 14:52
by Chris H.
Rob Cashwalker wrote:It uses a very simplistic AI to dig past basic lands and creatures if there are more than 5 of either of them in play.
`
Looks interesting.

As far as digging past creatures if there are more than 5 of them in play ... would it be worth keeping the creature if it was one of the few big creatures in the deck. I am thinking that we could test for

Code: Select all
getNetAttack() + getNetDefense() >= 8
`
this might let the computer swing the balance at this stage if the computer and the human were at a stage of equilibrium.

Re: Scry

PostPosted: 26 Jan 2010, 23:53
by Rob Cashwalker
Yeah, there's probably a number of criteria to key off of....

Why not simply make it that if the creature is bigger than all those in play, then it leaves it on top. Again, avoiding hard-coded numbers.

Re: Scry

PostPosted: 27 Jan 2010, 00:47
by Chris H.
That is a better idea. You had mentioned that you were using a simplistic AI to dig and your suggestion should only require a few additional lines of code.

Re: Scry

PostPosted: 27 Jan 2010, 17:45
by Rob Cashwalker
on second thought....

that's not much better... if the creature is going to be too expensive to reliably cast given current mana in play plus any in hand. In that case it needs to keep the land on top too...

With the computer land-stacking, I know the top 7 cards are land, but are the rest of the lands re-distributed among the remainder of the library? (so if there's no hope of casting any big spells, then it should go on bottom)

Re: Scry

PostPosted: 28 Jan 2010, 04:23
by zerker2000
I think "remainder" is something along the lines of 3 more land over the consecutive 8 or so turns, with the rest of the land being moved to the bottom.
However, "no hope of casting any big spells" isn't really guaranteed: a) Land stacking isn't necessarily on and b) any number of cards shuffle a library. If you scry a big spell and have nearly the amount of mana needed to cast it(and I'm almost sure there is an AI util for that), you probably don't want to reject it, at least in the case that is the only big spell in your scry+hand, and/or you could put enough land on top of it to cast it when such opportunity is given. Opponent milling capabilities should also...sorry I'll try to stay within reasonable limits(though a Millstone or two under opponent control Is something to consider).

Re: Scry

PostPosted: 28 Jan 2010, 21:50
by DennisBergkamp
You could always take into account whether land has been stacked... (if (Constant.Smooth[0]) .. ). Then again, the deck might've been shuffled by some effect already, so scratch that.

Another possibility is to be evil :twisted: and just cheat: check what the next few cards will be. A lot of people are against this approach (mommy, the AI just cheated! ), but personally I'm all in favor of giving the severely crippled AI whatever help it can get.

Re: Scry

PostPosted: 29 Jan 2010, 02:28
by zerker2000
Son, get out of the debugger, you have better things to do :). I do agree that is not the way to go though.

Re: Scry

PostPosted: 29 Jan 2010, 03:49
by Rob Cashwalker
Making these abilities function is one thing.... Coming up with some logical rules to make educated plays is insanity.