It is currently 29 Oct 2025, 00:50
   
Text Size

CardUtil.getCardTypes and related functions

Post MTG Forge Related Programming Questions Here

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

CardUtil.getCardTypes and related functions

Postby Rob Cashwalker » 13 May 2011, 16:29

I just pulled down r.8605 and have an error listed trying to resolve CardUtil.getCardTypes().

Well isn't this interesting... the reason I was opening the code was to find a place to insert the Mistform Ultimus list Wizards posted yesterday. So that whenever we would prompt for a creature type, it could be selected from a list instead of free-form.

I had been planning to throw it into the Constants object, but CardUtil could work too. I think those is__Type functions could be more elegant and faster, if the types were defined in arrays, and the function iterated through the type lists returning true as soon as it matched.

Since CardUtil will be updated soon, I hope, here's my revision to the isCreatureType method:
Code: Select all
    public static String creatureTypes[] = {"Advisor", "Ally", "Angel", "Anteater", "Antelope",
                                  "Ape", "Archer", "Archon", "Artificer", "Assassin",
                                  "Assembly-Worker", "Atog", "Aurochs", "Avatar",
                                  "Badger", "Barbarian", "Basilisk", "Bat", "Bear",
                                  "Beast", "Beeble", "Berserker", "Bird", "Blinkmoth",
                                  "Boar", "Bringer", "Brushwagg", "Camarid", "Camel",
                                  "Caribou", "Carrier", "Cat", "Centaur", "Cephalid",
                                  "Chimera", "Citizen", "Cleric", "Cockatrice", "Construct",
                                  "Coward", "Crab", "Crocodile", "Cyclops", "Dauthi",
                                  "Demon", "Deserter", "Devil", "Djinn", "Dragon", "Drake",
                                  "Dreadnought", "Drone", "Druid", "Dryad", "Dwarf",
                                  "Efreet", "Elder", "Eldrazi", "Elemental", "Elephant",
                                  "Elf", "Elk", "Eye",
                                  "Faerie", "Ferret", "Fish", "Flagbearer", "Fox", "Frog",
                                  "Fungus",
                                  "Gargoyle", "Germ", "Giant", "Gnome", "Goat", "Goblin",
                                  "Golem", "Gorgon", "Graveborn", "Gremlin", "Griffin",
                                  "Hag", "Harpy", "Hellion", "Hippo", "Hippogriff",
                                  "Homarid", "Homunculus", "Horror", "Horse", "Hound",
                                  "Human", "Hydra", "Hyena",
                                  "Illusion", "Imp", "Incarnation", "Insect",
                                  "Jellyfish", "Juggernaut",
                                  "Kavu", "Kirin", "Kithkin", "Knight", "Kobold", "Kor",
                                  "Kraken",
                                  "Lammasu", "Leech", "Leviathan", "Lhurgoyf", "Licid",
                                  "Lizard",
                                  "Manticore", "Masticore", "Mercenary", "Merfolk",
                                  "Metathran", "Minion", "Minotaur", "Monger", "Mongoose",
                                  "Monk", "Moonfolk", "Mutant", "Myr", "Mystic",
                                  "Nautilus", "Nephilim", "Nightmare", "Nightstalker", "Ninja",
                                  "Noggle", "Nomad",
                                  "Octopus", "Ogre", "Ooze", "Orb", "Orc", "Orgg", "Ouphe",
                                  "Ox", "Oyster",
                                  "Pegasus", "Pentavite", "Pest", "Phelddagrif", "Phoenix",
                                  "Pincher", "Pirate", "Plant", "Praetor", "Prism",
                                  "Rabbit", "Rat", "Rebel", "Reflection", "Rhino", "Rigger",
                                  "Rogue",
                                  "Salamander", "Samurai", "Sand", "Saproling", "Satyr",
                                  "Scarecrow", "Scorpion", "Scout", "Serf", "Serpent", "Shade",
                                  "Shaman", "Shapeshifter", "Sheep", "Siren", "Skeleton",
                                  "Slith", "Sliver", "Slug", "Snake", "Soldier", "Soltari",
                                  "Spawn", "Specter", "Spellshaper", "Sphinx", "Spider",
                                  "Spike", "Spirit", "Splinter", "Sponge", "Squid", "Squirrel",
                                  "Starfish", "Surrakar", "Survivor",
                                  "Tetravite", "Thalakos", "Thopter", "Thrull", "Treefolk",
                                  "Triskelavite", "Troll", "Turtle",
                                  "Unicorn",
                                  "Vampire", "Vedalken", "Viashino", "Volver",
                                  "Wall", "Warrior", "Weird", "Whale", "Wizard", "Wolf",
                                  "Wolverine", "Wombat", "Worm", "Wraith", "Wurm",
                                  "Yeti",
                                  "Zombie", "Zubera"};
    // Check if a Type is a Creature Type (by excluding all other types)
    public static boolean isACreatureType(String cardType) {
       //return (!isACardType(cardType) && !isASuperType(cardType) && !isALandType(cardType)
        //        && !cardType.equals("Arcane") && !cardType.equals("Trap")
        //        && !cardType.equals("Aura") && !cardType.equals("Shrine")
        //        && !cardType.equals("Equipment") && !cardType.equals("Fortification"));
       for (int i=0; i<creatureTypes.length; i++)
          if (creatureTypes[i].equals(cardType))
             return true;
       
       return false;
    }
Similar method should be applied to the others. This would also lead to the eventual dynamic reading of the type lists, to enable adding new/custom types easier later.
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: CardUtil.getCardTypes and related functions

Postby friarsol » 13 May 2011, 16:38

Rob Cashwalker wrote:I just pulled down r.8605 and have an error listed trying to resolve CardUtil.getCardTypes().

Well isn't this interesting... the reason I was opening the code was to find a place to insert the Mistform Ultimus list Wizards posted yesterday. So that whenever we would prompt for a creature type, it could be selected from a list instead of free-form.

I had been planning to throw it into the Constants object, but CardUtil could work too. I think those is__Type functions could be more elegant and faster, if the types were defined in arrays, and the function iterated through the type lists returning true as soon as it matched.
I like it. This will simplify cards like Engineered Plague, that currently forces you to type in the name, and would reduce Human Error of typoing a type.

Instead of being in an array, why not put them in a set or a keyValue pair? This would guarantee uniqueness, and also wouldn't require us to iterate through an array.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: CardUtil.getCardTypes and related functions

Postby Rob Cashwalker » 13 May 2011, 16:47

I know a hashmap would be simpler, but how do you create one in code without iterating through an array like this? Once we put in the effort to read it at runtime, then sure, it makes sense. Also, as an array, it can be used directly by the GUI Select prompt.

BTW, nice creative use of a typo to make the point about human error... ;-)
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: CardUtil.getCardTypes and related functions

Postby friarsol » 13 May 2011, 17:00

Rob Cashwalker wrote:I know a hashmap would be simpler, but how do you create one in code without iterating through an array like this? Once we put in the effort to read it at runtime, then sure, it makes sense. Also, as an array, it can be used directly by the GUI Select prompt.

BTW, nice creative use of a typo to make the point about human error... ;-)
Hmm.. Java might not let you do it the way I was thinking. I've been doing a lot of Javascript at work and it's much more flexible in what it lets you get away with.

The Array size probably won't make that much difference. If we really cared about performance, we could run a Binary Search on it. It may be a good idea to have the types be in a file so they can be maintained on the fly without having to look through the code for wherever this is each time a new SubType is created.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: CardUtil.getCardTypes and related functions

Postby slapshot5 » 13 May 2011, 17:03

Rob Cashwalker wrote:I just pulled down r.8605 and have an error listed trying to resolve CardUtil.getCardTypes().
r8607 fixes that. I missed a file on checkin.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: CardUtil.getCardTypes and related functions

Postby Rob Cashwalker » 13 May 2011, 17:47

Thanks slapshot. I know it always seems to happen...

224 types, to be precise. I think I'll just go and make it read from a file at startup, into a hashmap that lives in Constants or AllZone somewhere. In fact, I think there are a bunch of places in the code where hard-coded lists and arrays are used willy-nilly... I know I specifically did the deed in my draft code.
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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 24 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 24 users online :: 0 registered, 0 hidden and 24 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 24 guests

Login Form