Wednesday, December 31, 2008

Wizards is Trying to Kill Me

(This was written awhile ago, but it is still true. New sets scare me to dead because they usually involve some weird mechanic like "When this card goes to the graveyard and you tapped an Island this turn, you may draw up to 2 cards.")

Yes, the tagline is totally outrageous and false, like all good taglines. :) Checkout Beseech the Queen, a new Shadamoor card. That is some funky mana. I assume it means “You can pay BBB or 2BB or 4B or 6”. This has to be correct or very close since Mark Rosewater (head Wizard card designer) mentioned that the converted mana cost is 6. What this means to me, is more programming and more headaches, aka Wizards is trying to kill me. (By the way that sounds like a bad Dungeons and Dragons dream.)

A few weeks ago, while waiting for a job interview I sketched out an idea to program hybrid mana costs, introduced in Ravnica. And while I didn’t get the job, I did come up with a pretty nifty solution. Thankfully with a little bit of tweaking, it worked. I’m not sure exactly how to implement this new mana cost, but maybe something will come to me. If not, I’ll just code, test, debug, and repeat until finished. Hopefully it will only take me 1 hour, but maybe I’m just blowing my own horn.

Currently the mana cost is just a string. A string is a sequence of letters like “I am a string”. All text that you see on the screen is a string. This new mana, along with split cards, make any operations like finding the converted mana cost more difficult. The solution is to replace the string mana cost with a class that represents the mana cost.

A class is a collection of operations, called methods, that act on the same data. A number class would have methods add and subtract. The mana cost class should have methods like getConvertedCost and getCardColor. The card’s color is important and is usually determined by the mana cost, some exceptions are Pact of Negation and Ancestral Vision. The mana class could also have the methods addToCost and reduceCost for cards like Thorn of Amethyst (Noncreature spells cost 1 more to play) and Cloud Key (Spells you play of the chosen type [Creature, Instant, etc...] cost 1 less to play).

Screenshots of MTG Forge




9 comments:

DennisBergkamp said...

Hmm, haven't I read this post somewhere before :) ?

Anyway, I can relate to this post very well. These days when I see a card, I automatically start thinking about how to code it.

Some cards just seem impossible :(

MageKing17 said...

I do the exact same thing. Due to things we just plain haven't gotten around to implementing, this means about half of the cards I look at, I immediately go "That can't be coded." The other half, I go "I could code this in less than thirty seconds." I am, of course, referring to my personal card collection. Going by the entire total of Magic, we could probably do way more than half... there are just so many simple effects out there, you know. It's finding them all and implementing them all (and testing them all) that takes so freaking long. :P

Hybrid mana actually turned out to be a lot easier than we thought it would be. At first, we were just "Arg... we'll do it later. Way later." Then, eventually, when I really wanted to test some hybrid card, I hacked the cost with a ChoiceCost object (basically a list of costs, and the game asks you which one you want to pay when you try to play the card (actually when you try to pay the cost... which is when you try to play the card :P)). When I realized that this was basically rules-accurate and that we just needed the engine to generate the choices for you, Incantus (the person this time, not the program) immediately whipped up some code. That code has, as far as I know, remained unchanged to this day (I think the only thing we changed was making CMC work with hybrid, which was also much easier than expected (just pick the choice with the most colorless mana!)).

Anonymous said...

do you need a pathches for MtG Forge v1? i did a "summoning sickness" patch (the spiral), and attack/defence/damage patch. tothe are not in your coding style, but they works. write ketmar@ketmar.no-ip.org -- i'd like to give the modified sources.

Forge said...

I've been "Internet Challenged" so for 3 weeks I've been running old articles, maybe it was also nice to take a little break. New stuff coming Monday ;)

I have used Incantus and the hybrid mana selection works very well. I guess I understood the hybrid mana rules text and a little incorrectly so my hybrid mana code doesn't make the user select which cost to play, it just pays for the code normally. For example, if the mana cost is 1(G/W), and you tapped a Forest, the mana cost would now be just 1.

Just making the user choose the mana cost that they want to pay would have been MUCH easier, lol.

"there are just so many simple effects out there, you know. It's finding them all and implementing them all (and testing them all) that takes so freaking long. "

When effects change how other effects work, that is the tough code to check because you have to know the correct answer in case the program does it incorrectly. The effect interaction problem becomes n squared, I think, ha.

Anonymous said...

One slight problem with automatically determining what mana cost the user is intending on paying is that if the card is a card that has 2/r 2/r 2/r, where 2/r means 2 colorless or one red mana, there could be times when the user wants to use red mana for the colorless. For instance to avoid mana burn or when a card which punishes you for untapped mana is in play (ie. Power Surge).

Forge said...

Anonymous,

Yes that is very true, that is why I try to stay as close as I can to the rules, because the rules are created for a reason.

In my (odd) opinion hopefully the odds are against having Power Surge in play AND playing a hybrid mana card.

Forge said...

I probably should have an option somewhere so the user can select whether he wants to select the hybrid mana cost or just have the computer automatically do it for him.

Forge said...

Many people have asked for the option that lets the computer automatically play a card, the computer would tap the land.

sticker said...

gucci
gucci bag
gucci handbag
buy gucci
gucci wallet