It is currently 16 Apr 2021, 02:39
   
Text Size

Self - Regenerate Creatures

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

Self - Regenerate Creatures

Postby Rob Cashwalker » 27 Sep 2008, 13:52

This is a submission I made to mtgrares by email earlier this month, to a less than stellar reception. So just in case someone else is compiling submissions, here it is.

CardFactory:
Near the top, where the shouldPump keyword is checked for already:
Code: Select all
  //Check for self-regenerate ability
  private final int shouldRegenerateMe(Card c)
  {
      ArrayList a = c.getKeyword();
      for (int i = 0; i < a.size(); i++)
          if (a.get(i).toString().startsWith("RegenerateMe"))
              return i;

      return -1;
  }
In the main body of card definitions:
Code: Select all
      //Creatures with self-regenerate abilities
    //-1 means keyword "RegenerateMe" not found
    while (shouldRegenerateMe(card) != -1)
    {
        int n = shouldRegenerateMe(card);
        if (n != -1)
        {
            String parse = card.getKeyword().get(n).toString();
            card.removeKeyword(parse);

            String k[] = parse.split(":");
            final String manacost = k[1];

            final Command untilEOT = new Command() {
                public void execute()
                {
                    card.setShield(0);
                }
            };

            final SpellAbility a1 = new Ability(card, manacost) {
                public boolean canPlayAI()
                {
                  if (CardFactoryUtil.AI_isMainPhase())
                  {
                    if (CardFactoryUtil.AI_doesCreatureAttack(card))
                    {
                      //"Fuzzy logic" to determine if using a regenerate ability might be helpful because
                      //we can't wait to decide to play this ability during combat, like the human can
                      //weight[] is a set of probability percentages to be averaged later
                      int weight[] = new int[3];
                     
                      // cards with real keywords (flying, trample, etc) are probably more desireable
                      if (card.getKeyword().size() > 0)
                          weight[0] = 75;
                      else
                          weight[0] = 0;

                      // if there are many cards in hand, then maybe it's not such a great idea to waste mana                       
                      CardList HandList = new CardList(AllZone.getZone(Constant.Zone.Hand, Constant.Player.Computer).getCards());

                      if (HandList.size() >= 4)
                          weight[1] = 25;
                      else
                          weight[1] = 75;
                     
                      // compare the highest converted mana cost of cards in hand to the number of lands
                      // if there's spare mana, then regeneration might be viable
                      int hCMC = 0;
                      for (int i = 0; i < HandList.size(); i++)
                          if (HandList.getCard(i).getConvertedManaCost() > hCMC)
                              hCMC = HandList.getCard(i).getConvertedManaCost();

                      CardList LandList = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards());
                      LandList = LandList.getType("Land");

                      //most regenerate abilities cost 2 or less
                      if (hCMC + 2 >= LandList.size())
                          weight[2] = 50;
                      else
                          weight[2] = 0;
                     
                      // ultimately, it's random fate that dictates if this was the right play
                      int aw = (weight[0] + weight[1] + weight[2]) / 3;
                      Random r = new Random();
                      if (r.nextInt(100) <= aw)
                          return true;
                    }
                  }
                  return false;
                }

                public void resolve()
                {
                    card.addShield();
                    AllZone.EndOfTurn.addUntil(untilEOT);
                }
            }; //SpellAbility

            card.addSpellAbility(a1);

            String Desc = new String();
            Desc = "Regenerate " + cardName;

            a1.setDescription(manacost + " : " + Desc);
            a1.setStackDescription(Desc);

            a1.setBeforePayMana(new Input_PayManaCost(a1));
        } //if (should RegenerateMe)
    } //while - card has more RegenerateMe - Jungle Troll has two Regenerate keywords
The AI for this code attempts something not done previously - fuzzy logic of sorts.

There are a few cards here that are already implemented in pure code, and they'll have to be removed from the code.

Cards.txt:
Code: Select all
Ancient Silverback
4 G G
Creature Ape
no text
6/5
RegenerateMe:G

Carnassid
4 G G
Creature Beast
no text
5/4
Trample
RegenerateMe:1 G

Carrion Wall
1 B B
Creature Wall
no text
3/2
Defender
RegenerateMe:1 B

Charging Troll
2 W G
Creature Troll
no text
3/3
Vigilance
RegenerateMe:G

Clay Statue
4
Artifact Creature Golem
no text
3/1
RegenerateMe:2

Darkling Stalker
3 B
Creature Shade Spirit
no text
1/1
RegenerateMe:B
PTPump B:+1/+1

Diabolic Machine
7
Artifact Creature Construct
no text
4/4
RegenerateMe:3

Drowned
1 U
Creature Zombie
no text
1/1
RegenerateMe:B

Drudge Reavers
3 B
Creature Skeleton
no text
2/1
Flash
RegenerateMe:B

Drudge Skeletons
1 B
Creature Skeleton
no text
1/1
RegenerateMe:B

Eron the Relentless
3 R R
Legendary Creature Human Rogue
no text
5/2
Haste
RegenerateMe:R R R

Fog of Gnats
B B
Creature Insect
no text
1/1
Flying
RegenerateMe:B

Ghost Ship
2 U U
Creature Spirit
no text
2/4
Flying
RegenerateMe:U U U

Gorilla Chieftain
2 G G
Creature Ape
no text
3/3
RegenerateMe:1 G

Horned Troll
2 G
Creature Troll
no text
2/2
RegenerateMe:G

Jungle Troll
1 R G
Creature Troll
no text
2/1
RegenerateMe:R
RegenerateMe:G

Living Airship
3 U
Creature Metathran
no text
2/3
Flying
RegenerateMe:2 G

Living Wall
4
Artifact Creature Wall
no text
0/6
Defender
RegenerateMe:1

Malach of the Dawn
2 W W
Creature Angel
no text
2/4
Flying
RegenerateMe:W W W

Metathran Zombie
1 U
Creature Metathran Zombie
no text
1/1
RegenerateMe:B

Mire Boa
1 G
Creature Snake
no text
2/1
Swampwalk
RegenerateMe:G

Pewter Golem
5
Artifact Creature Golem
no text
4/2
RegenerateMe:1 B

Phyrexian Monitor
3 B
Creature Skeleton
no text
2/2
RegenerateMe:B

Restless Dead
1 B
Creature Skeleton
no text
1/1
RegenerateMe:B

Revered Dead
1 W
Creature Spirit Soldier
no text
1/1
RegenerateMe:W

River Boa
1 G
Creature Snake
no text
2/1
Islandwalk
RegenerateMe:G

Screeching Harpy
2 B B
Creature Harpy Beast
no text
2/2
Flying
RegenerateMe:1 B

Silvos, Rogue Elemental
3 G G G
Legendary Creature Elemental
no text
8/5
Trample
RegenerateMe:G

Skyshroud Troll
2 G G
Creature Troll Giant
no text
3/3
RegenerateMe:1 G

Tattered Drake
4 U
Creature Zombie Drake
no text
2/2
Flying
RegenerateMe:B

Tel-Jilad Exile
3 G
Creature Troll Warrior
no text
2/3
RegenerateMe:1 G

Unworthy Dead
1 B
Creature Skeleton
no text
1/1
RegenerateMe:B

Uthden Troll
2 R
Creature Troll
no text
2/2
RegenerateMe:R

Votary of the Conclave
W
Creature Human Soldier
no text
1/1
RegenerateMe:2 G

Walking Dead
1 B
Creature Zombie
no text
1/1
RegenerateMe:B

Wall of Bone
2 B
Creature Skeleton Wall
no text
1/4
Defender
RegenerateMe:B

Wall of Brambles
2 G
Creature Plant Wall
no text
2/3
Defender
RegenerateMe:G

Wall of Pine Needles
3 G
Creature Plant Wall
no text
3/3
Defender
RegenerateMe:G

Will-o'-the-Wisp
B
Creature Spirit
no text
0/1
Flying
RegenerateMe:B

Yavimaya Gnats
2 G
Creature Insect
no text
0/1
Flying
RegenerateMe:G
Common.txt:
Code: Select all
Clay Statue
Darkling Stalker
Drowned
Drudge Reavers
Fog of Gnats
Gorilla Chieftain
Horned Troll
Living Airship
Metathran Zombie
Mire Boa
Pewter Golem
Phyrexian Monitor
Restless Dead
Revered Dead
Skyshroud Troll
Tattered Drake
Tel-Jilad Exile
Unworthy Dead
Votary of the Conclave
Walking Dead
Uncommon.txt:
Code: Select all
Carrion Wall
Charging Troll
Diabolic Machine
Drudge Skeletons
Ghost Ship
Jungle Troll
Living Wall
Malach of the Dawn
River Boa
Screeching Harpy
Uthden Troll
Wall of Bone
Wall of Brambles
Wall of Pine Needles
Yavimaya Gnats
Rare.txt:
Code: Select all
Ancient Silverback
Carnassid
Silvos, Rogue Elemental
Will-o'-the-Wisp
Card-pics.txt:
Code: Select all
Ancient Silverback            http://resources.wizards.com/Magic/Cards/9ED/en-us/Card82950.jpg
Carnassid                  http://resources.wizards.com/Magic/Cards/ST/en-us/Card5217.jpg
Carrion Wall               http://resources.wizards.com/Magic/Cards/8ED/en-us/Card45306.jpg
Charging Troll               http://resources.wizards.com/Magic/Cards/IN/en-us/Card23162.jpg
Clay Statue               http://resources.wizards.com/Magic/Cards/5E/en-us/Card3767.jpg
Darkling Stalker               http://resources.wizards.com/Magic/Cards/TE/en-us/Card4647.jpg
Diabolic Machine            http://resources.wizards.com/Magic/Cards/5E/en-us/Card3775.jpg
Drowned                  http://resources.wizards.com/Magic/Cards/DK/en-us/Card1750.jpg
Drudge Reavers               http://resources.wizards.com/Magic/Cards/TSP/en-us/Card108850.jpg
Drudge Skeletons            http://resources.wizards.com/Magic/Cards/10E/EN/Card129529.jpg
Fog of Gnats               http://resources.wizards.com/Magic/Cards/GU/en-us/Card9699.jpg
Ghost Ship               http://resources.wizards.com/Magic/Cards/TSB/en-us/Card107294.jpg
Gorilla Chieftain            http://resources.wizards.com/Magic/Cards/7E/en-us/Card13047.jpg
Horned Troll               http://resources.wizards.com/Magic/Cards/8ED/en-us/Card45404.jpg
Jungle Troll               http://resources.wizards.com/Magic/Cards/MI/en-us/Card3540.jpg
Living Airship               http://resources.wizards.com/Magic/Cards/AP/en-us/Card26795.jpg
Living Wall               http://resources.wizards.com/Magic/Cards/3E/en-us/Card1123.jpg
Malach of the Dawn            http://resources.wizards.com/Magic/Cards/PLC/en-us/Card122481.jpg
Metathran Zombie            http://resources.wizards.com/Magic/Cards/IN/en-us/Card22973.jpg
Mire Boa                  http://resources.wizards.com/Magic/Cards/PLC/en-us/Card122420.jpg
Pewter Golem               http://resources.wizards.com/Magic/Cards/MRD/en-us/Card48054.jpg
Phyrexian Monitor            http://resources.wizards.com/Magic/Cards/CG/en-us/Card19113.jpg
Restless Dead               http://resources.wizards.com/Magic/Cards/MI/en-us/Card3307.jpg
Revered Dead               http://resources.wizards.com/Magic/Cards/PLC/en-us/Card122282.jpg
River Boa                  http://resources.wizards.com/Magic/Cards/6E/en-us/Card16457.jpg
Screeching Harpy            http://resources.wizards.com/Magic/Cards/TE/en-us/Card4684.jpg
Silvos, Rogue Elemental         http://resources.wizards.com/Magic/Cards/ONS/en-us/Card39860.jpg
Skyshroud Troll               http://resources.wizards.com/Magic/Cards/TE/en-us/Card4791.jpg
Tattered Drake               http://resources.wizards.com/Magic/Cards/RAV/en-us/Card87930.jpg
Tel-Jilad Exile               http://resources.wizards.com/Magic/Cards/MRD/en-us/Card49436.jpg
Unworthy Dead               http://resources.wizards.com/Magic/Cards/UZ/en-us/Card5780.jpg
Uthden Troll               http://resources.wizards.com/Magic/Cards/TSB/en-us/Card108806.jpg
Votary of the Conclave         http://resources.wizards.com/Magic/Cards/RAV/en-us/Card87948.jpg
Walking Dead               http://resources.wizards.com/Magic/Cards/LE/en-us/Card1466.jpg
Wall of Bone               http://resources.wizards.com/Magic/Cards/7E/en-us/Card25639.jpg
Wall of Brambles            http://resources.wizards.com/Magic/Cards/5E/en-us/Card4021.jpg
Wall of Pine Needles            http://resources.wizards.com/Magic/Cards/IA/en-us/Card2598.jpg
Will-o'-the-Wisp               http://resources.wizards.com/Magic/Cards/9ED/en-us/Card83411.jpg
Yavimaya Gnats               http://resources.wizards.com/Magic/Cards/IA/en-us/Card2604.jpg
This keyword could be added in code to make spells and "enchantments" (sorceries to MTGForge v1) which grant Regenerate abilities to creatures.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Self - Regenerate Creatures

Postby jpb » 27 Sep 2008, 22:47

What do you mean "a less than stellar reception"?
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Self - Regenerate Creatures

Postby GandoTheBard » 28 Sep 2008, 03:40

He means MtgRares does not want more code to add to Forge v1. He's too busy working out the kinks in V2. Or at least thats the feeling I've gotten. My recommendation is: if you have code to add, add it to your source, compile that and send it to Rares to put up or post it here in a thread for us to get. Otherwise I wouldn't hold my breath waiting. :D
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Self - Regenerate Creatures

Postby Rob Cashwalker » 29 Sep 2008, 02:47

Yeah, Gando pretty much hit it.

I'm getting a little confused, on one hand mtgrares told me that he probably wouldn't add it, because he's busy on v2. Cool. But then he posted here saying that he liked how we're all posting our work and that he would continue to release if someone would compile everything together....

I can't compile without drastic changes in the GUI API code that left the windows completely collapsed to the title bar. So I can't double check my code, so I can't step up as a coordinator.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Self - Regenerate Creatures

Postby DennisBergkamp » 29 Sep 2008, 17:02

On top of that, I've never been able to compile the latest Beta.
So all my card additions are on top of the previous version, which does not include a bunch of fixes that are in the latest Beta.

Other than that, I don't mind posting/submitting compiled code directly.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Self - Regenerate Creatures

Postby GandoTheBard » 29 Sep 2008, 21:43

Rather whomever is actually writing the code(Dennis, Rob and JPB it seems are the ones I am refering to) should pick one person who is competant with the current version and send them snippets of the code they want inserted and let the selected person handle that and the compilation and then they can post the results here on this forum under a special thread. Clearly such an update wont be an official one until Rares adds it to MTG Forge himself but at least we can play with the changes and see if there are bugs. (There are ALWAYS bugs :P)

This is sort of what Rares suggested already but modified a bit.
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Self - Regenerate Creatures

Postby jpb » 30 Sep 2008, 06:09

I won't be doing it.
jpb
 
Posts: 132
Joined: 05 Sep 2008, 13:12
Has thanked: 0 time
Been thanked: 0 time

Re: Self - Regenerate Creatures

Postby DennisBergkamp » 30 Sep 2008, 16:43

I wouldn't mind doing something like this, except for the fact that I don't have:

1) the latest beta's additions + fixes in a compilable form (in my version, putting creatures with flash into play through elvish piper makes them disappear, creatures don't tap when regenerating, no black vise/storm herd/dual lands/festival of trokin/etc., shadow creatures can block non-shadow creatures, etc. etc.). It just seems that when I would release my version, it would be far inferior to Forge's latest beta, which doesn't only include a bunch of cool new cards, it also includes some vital fixes. Releasing my version for testing purposes would not make a lot of sense either, since Forge fixed a bunch of things and we might just run into old errors that are already fixed.

2) any real understanding of classes/files other than CardFactory.java (yet).

I guess if Forge releases a compilable version of his Beta, I would not mind adding in my stuff, compiling it and releasing that as an unofficial test version.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time


Return to Forge

Who is online

Users browsing this forum: No registered users and 20 guests


Who is online

In total there are 20 users online :: 0 registered, 0 hidden and 20 guests (based on users active over the past 10 minutes)
Most users ever online was 1371 on 09 Feb 2020, 16:22

Users browsing this forum: No registered users and 20 guests

Login Form