Wednesday, June 11, 2008

Programming Hybrid Mana 2

I could have gone the easy route and not programmed hybrid mana at all. I could have just let the user select which cost they would play. Like if the card cost (G/W) the user would select G or W and then tap the appriopriate land.

My previous pseudocode looks correct but there were a still a few errors I had to fix. First, you have to internally reverse the mana cost because otherwise the colorless part will “eat” the colored mana the rest of the cost needs.

For example, 2WW needs to be reversed to WW2. So when you add mana, the white mana part is checked first. In other words, when you pay W toward the cost 2WW the result should be 2W not 1WW. And when you display the cost to the user, the output has to be reversed again.

Below I will example how to use my Python code that handles mana costs. Some examples of valid mana costs are
2
1 W
X U
GW
RB RB
2/G 2/G 2/G

Each part is separated with a space, which just makes it easier to split up. GW means you can pay G or W and 2/G means that you can pay either 2 or G. The class ManaCost is the class that you will be using. ManaCost is low level and a graphical component is supposed to use ManaCost and allow the user to select the appropriate land or mana. The graphical component would also tap the land if the mana was needed. An example of how to use ManaCost is given below.

c = ManaCost()
c.setManaCost(“2 W W”)
c.isNeeded(“W”) #true
c.addMana(“W”)
print c.toString() #2 W
c.addMana(“W”)
c.addMana(“U”)
c.addMana(“U”)
print c.isPaid() #true

Feel free to use this in your own projects. This has been tested thoroughly comes with a wide variety of test cases: TestManaCost and TestManaPart.

Download Python Code

11 comments:

  1. I just spend 30 minutes trying to figure out why "input.getMessage()" is different than "input.getMesssage()". No wonder normal people don't like to program, they aren't obessive compulsive. :=)

    ReplyDelete
  2. Stumbled across your blog (thanks to a message on gamedev.net). Makes me want to resurrect my similar project for the old Descipher Star Wars CCG.

    ReplyDelete
  3. Cool, I don't remember posting anything to gamdev.net, but I try to advertise my blog and program a little.

    The Decipher Star Wars CCG would be cool. I've thought about writing a "generic card framework" that will let programmers easily get things up and working. The framework would be writtin in Java since that is what I know best.

    ReplyDelete
  4. Hey Forge, I've been thinking the same thing. Writing a generic CCG framework with a general card "mini programming language" - sort of like a DSL. I think most card games have the basic ideas of cards overriding rules.

    ReplyDelete
  5. The trick with that would be providing for different game mechanics, and then allowing individual cards to manipulate those mechanics. Then getting the AI to work within those customised mechanics. Could be an interesting project!

    ReplyDelete
  6. Oh, and here's the link to the GameDev thread I was talking about.

    ReplyDelete
  7. My program is open source. The program comes with the Java source code. Version 2 will be written in Python, because it seems like a cool language, and it will be open source also.

    ReplyDelete
  8. My idea of a "generic card framework" would just implement zones, phases, and a few standard actions like drawing a card and destroying a card. Basically writing the foundation, so someone else can just write the card code themself.

    ReplyDelete
  9. also, for static abilities (like nightmare and korlash), you could do it backwards like have a hidden ability on swamps that says khorlash and nightmare get +1/+1 or something like that

    if you hate this, you'll hate Eventide, its practically all hybrid... Personally i hate hybrid cards

    ReplyDelete
  10. o ya,be4 i 4get,programming aggro and white weenies would prolly be easiest 2 program since its basically 'he draws a card, plays it'. control is a little broader a subject

    ReplyDelete

Note: Only a member of this blog may post a comment.