Page 1 of 1

CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 16:29
by Rob Cashwalker
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.

Re: CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 16:38
by friarsol
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.

Re: CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 16:47
by Rob Cashwalker
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... ;-)

Re: CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 17:00
by friarsol
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.

Re: CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 17:03
by slapshot5
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

Re: CardUtil.getCardTypes and related functions

PostPosted: 13 May 2011, 17:47
by Rob Cashwalker
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.