magic

You are currently browsing the archive for the magic category.

Yeah. That’s right, grizzly bears are my favorite. Why you ask? Well because it’s a vanilla creature. They have a power and a toughness, that’s it. Not stupid abilities that will be a nightmare to code, no fancy casting cost involving sacrifices or X or hybrid mana or saying “Beetlejuice” 3 times. No token generation, or triggered effect, or “choose one”, or “when it’s the first Friday of the month and if your opponent is older than you, then you deal Y damage to Z creatures where X is the sum of your age plus the color of the eyes of your opponent divided by 2″. Nope. Just a plain good vanilla creature that will never make Wagic crash :) I love you, grizzly bears!

Seriously though, what’s your favorite card in Magic?



When creating a Magic the Gathering simulation (or any other collectible card game), one of the first decisions one has to make is how to store the Data for the cards. It is a decision that needs to be taken in early stages of the development, yet it has such a huge impact on the future of the game that it shouldn’t be taken lightly.
This information will of course tell the game what the card does, when it can be played, what it’s effects are, etc…, so it is obviously very important.

There are several MTG computer simulations out there, and we all went with different choices.

Firemox

Firemox’s cards are coded in XML. Firemox was designed to be extremely flexible and allow several kinds of games, but as far as I know it never supported anything else than Magic the gathering. Their XML files looks overly complex to me, especially since the “flexibility” is still limited by the possibilities of the engine behind.

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<card xmlns=”http://sourceforge.net/projects/firemox”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://sourceforge.net/projects/firemox ../../validator.xsd”
name=”Angel of Light”>
<rules-author-comment>riclas</rules-author-comment>
<init>
<registers>
<register index=”white” value=”1″/>
<register index=”colorless” value=”4″/>
<register index=”power” value=”3″/>
<register index=”toughness” value=”3″/>
</registers>
<colors>white</colors>
<idcards>creature</idcards>
<properties>vigilance flying angel</properties>
</init>
<abilities>
<ability ref=”cast-spell”/>
</abilities>
</card>

Incantus

Incantus is coded in Python, and the cards as well. Using a scripting language for the data is a pretty clever way of doing things, especially when it’s the exact same language you’re using for the engine. It’s not tood difficult to read (although not as easy as I would expect), and extremely flexible since it gives you control on the rest of the code.

name = ‘Mogg Fanatic’
cardnum = 219
expansion = ’10E’
type = characteristic(‘Creature’)
supertype = no_characteristic()
subtypes = characteristic(['Goblin'])
cost = ‘R’
color = characteristic(['R'])
text = ['Sacrifice Mogg Fanatic: Mogg Fanatic deals 1 damage to target creature or player.']

play_permanent(card, cost)

in_play_role = Permanent(card, Creature(1, 1))

@activated(card, txt=text[0])
def effects(source):
payment = yield SacrificeCost()
target = yield Target(target_types=isCreatureOrPlayer)
source.dealDamage(target, 1)
yield

MAGic MAchine

Magic Machine apparently uses an encoded string to represent the cards, but my attempts at retrieving any useful information on Magic Machine’s card format didn’t give anything. The game itself only works on windows and requires admin rights to be installed, the databases I could find where password protected, and the help forums are in italian and don’t give much info on their format. It seems quite flexible though, and MagMa is the freeware with the biggest card database around here (but Incantus will soon have more, and Wagic is getting closer). The fact that it requires an editor seems a bit problematic to me, but if it gives enough motivation for players to create cards, it might be good.

Duels of the Planeswalkers (XBOX360)

The recent XBOX360 game “duels of the Planeswalkers” also uses XML to represent their cards. Unlike the xml in firemox, it is very readable:

Of course, this is a commercial game, so it’s not like you could create your own cards, which sort of ruins the point of even talking about their representation…

MTGForge

MTGForge has a mix of hardcoded cards and cards using a small set of keywords (http://www.slightlymagic.net/forum/viewtopic.php?f=26&t=701). Recently the set of keywords recognized by MTGForge has been growing rapidly. Here is what Birds of Paradise look like in MTGForge:

Birds of Paradise
G
Creature Bird
0/1
tap: add W
tap: add B
tap: add U
tap: add R
tap: add G
Flying

Wagic

MTGForge was the initial inspiration for Wagic, so I initially went with hardcoded cards, and it was clear to me that at least the “data” part had to be stored outside of the code, as external data files, one for each expansion. They key in allowing people to add their own cards was that the format has to be easy to read and understand, so I went with simple text files. I think the first release only allowed some basic abilities (such as “vigilance, flying..) and maybe mana sources (“auto={T}:Add …”).
The possibility to add your own cards in Wagic is probably the feature that had the most success so far. Wagic was initially planned to handle around 300 cards and focus on the AI. But in the last months, more work has been made on adding new cards (and allowing people to add more) than on the rest of the game.
Here are the cards previously mentioned for other games, the way we represent them in Wagic:
Birds of Paradise

[card]
text=Flying (This creature can’t be blocked except by creatures with flying or reach.)  {T}: Add one mana of any color to your mana pool.
abilities=flying
auto={T}:Add{G}
auto={T}:Add{R}
auto={T}:Add{U}
auto={T}:Add{B}
auto={T}:Add{W}
id=129906
name=Birds of Paradise
rarity=R
color=Green
type=Creature
mana={G}
power=0
subtype=Bird
toughness=1
[/card]

Angel of Mercy

[card]
text=Flying (This creature can’t be blocked except by creatures with flying or reach.)  When Angel of Mercy comes into play, you gain 3 life.
abilities=flying
auto=life:3
id=129465
name=Angel of Mercy
rarity=U
color=White
type=Creature
mana={4}{W}
power=3
subtype=Angel
toughness=3
[/card]

Mogg Fanatic

[card]
text=Sacrifice Mogg Fanatic: Mogg Fanatic deals 1 damage to target creature or player.
auto={s}:Damage:1 target(creature,player)
id=134748
name=Mogg Fanatic
rarity=U
type=Creature
mana={R}
power=1
subtype=Goblin
toughness=1
[/card]

Angel of light

[card]
text=Vigilance,flying
name=Angel of Light
rarity=R
type=Creature
mana={4}{W}
power=3
subtype=Angel
toughness=3
[/card]

And here is a more complex card, that will work with the upcoming engine:

[card]
id=189909
name=Mold Adder
mana={G}
type=Creature
subtype=Fungus Snake
power=1
toughness=1
text=Whenever an opponent casts a blue or black spell, you may put a +1/+1 counter on Mold Adder.
auto=@movedTo(*[black;blue]|opponentStack):may counter(1/1)
rarity=U
[/card]

Overall I think it looks pretty simple, even for very complex effects.

All these methods have advantages and drawbacks. XML (firemox, duels of the planeswalkers) offers some structure and flexibility, but I think it fails in human readability, and flexibility could be achieved more easily with scripting languages such as python or lua. Magic Machine’s proprietary system looks flexible, but is clearly unreadable if you don’t have access to the card Editor, which to me would represent extra work that I am not ready to do. Plus it is always possible to have an editor yet a readable output. A scripting language (for example Python for Incantus) is probably the most flexible solution, and readability feels quite good to me.
The hybrid solution chosen by MTGForge and Wagic (some hardcoded cards, and a few keywords) is quite easy to code and easy to read in early stages. Newcomers can create basic cards in a few minutes with a text editor, while “experienced” coders can add cards in the code and recompile the game. Overall it works quite well, but after a while it shows its limits when you try to add new cards with more complex mechanisms. What were initially simple keywords become confusing strings that don’t always do what you want…

I’m happy with Wagic’s current system but I am not sure it can be extended infinitely. If I were to start again, I would highly consider a hybrid between a scripting language such as lua and parsed keywords.

sources

http://mtgrares.blogspot.com/2009/04/plaintext-creatures-and-cardstxt.html

http://mtgrares.blogspot.com/2008/01/magma.html

http://www.wizards.com/Magic/Magazine/Article.aspx?x=mtg/daily/feature/43c

http://www.firemox.org/mtg.html

http://www.slightlymagic.net/forum/viewtopic.php?f=27&t=557

This is a screenshoot I took yesterday while working on the code.

I think it’s very interesting because you can see several new and/or cool features at a glance:


(click on the picture to see the real size)

So now you can either try to guess what’s new or read on :)

The most obvious I think is the cool theme. As you may or may not know, it does not require any single line of programming to tweak Wagic’s graphics, and I’m actually surprised we had to wait 3 months before someone came up with such a cool mod. I myself suck at design, so I’m always impressed when people create cool graphics. Many thanks to u0127907 for this mod, I hope this will give motivation for other people to create and share their own mods. You can download it on the forum

The second thing, less obvious, is the picture quality of the big card. Of course, this is the windows version, and there’s no way to achieve that on the PSP version, but what this technically means is that I’m working on removing the size limitations on cards pictures. This will allow people using the PC versions (Windows, Linux or Mac) to play fullscreen without having blurry cards. It will also allow people on the PSP to reduce the size of the pictures if they think it takes too much space on their memory stick. Currently, I think the size of the cards is 285*something, and reducing it to 255*… should divide the textures size (in RAM) by 2 without losing much picture quality.

The last thing is probably the one that will interest you as Magic/Wagic players: The actual name of the big card you see on the screen. Yes, it’s a wasp token, which means I more or less got tokens working in Wagic’s current SVN revision (the Hive is hidden behind the big Wasp card, tapped. For the purpose of the test, I set the mana cost of the hive to 0 and the tokens cost to 1). Icing on the cake, tokens are partially scriptable in _cards.dat, this is the code for the Hive :

auto={5},{T}:token(Wasp,creature artifact insect, 1/1,flying artifact)

Internally, Token objects inherit from the MTGCardInstance class, and a few specific dirty tricks are performed by the code when the token changes zone, or when creating the image name. I think using tokens in the current svn version creates a memory leak, but this will be fixed eventually.

Typical. Coding while I should be packing for my holiday, yay me !

Tags:

Other Programs  

lord of the pit

bwahahaha

When I started working on Wagic a year ago, I thought there was absolutely no program that did what I wanted to do : a MTG game with rules enforcement.

After digging a little bit, I discovered that there are actually quite a lot of attempts at doing that.

MTG Forge Has quite a lot of cards (around 700 I think), is an open source Java application. Its author is working hard, so the application has in dynamism what it lacks in professional-looking-ism. When I tried it several months ago, I didn’t enjoy it because I thought the AI was crappy. I think differently now that I have to code my own :p . The creator’s blog is very interesting, updated regularly, and the main reason I started my own blog for this project !

Deckbot is not open source, but has quite a lot of cards from recent editions. It is text based, but uses a form of Minimax algorithm for the AI. Haven’t tried it yet but I read the AI is pretty damn good !

Incantus is the new hot Magic project these days. All is written in Python, and the GUI is brilliant, even better than the official “MTG Online” sold by Wizards of the Coast. I have difficulties to understand the “open source or not” status of this game… Adding cards seems to be easy as pie, it manages lots of complex rules, but it doesn’t have any AI (network play).

There are lots of other games, the site slightlymagic.net tries to give a complete list of them.

So why would we need yet another Magic game ? Well, none of these could run on the PSP, due to the size of the screen and the memory they use. So a new one is definitely needed for portable devices owners !

Note: There is also a PSP port of Magic WorkStation, but I found the installation process to be complex, especially since the game didn’t do much at that time (2 players hotseat, no rule enforcement…). MWS without network support is not that interesting…so I didn’t try that hard to install it.

Newer entries »