Page 1 of 1

Magic - Domain Specific Language

PostPosted: 23 Mar 2010, 20:05
by mtgrares
To everybody how doesn't understand what I'm saying, don't worry about it. I try not to be "too technical" but some of this stuff is "all technical". I always say, "The devil is in the (technical) details."
Recently I read an article about domain specific languages (DSL). The goal of DSLs is to allow you to write at the highest level of abstraction (which is your goal anyways since high level code is shorter and more straight to the point that low level mucking). A DSL can be "interal" writting in a programming language like Java, game.drawCard(). Parts of Forge like CardFactory is an internal DSL. A DSL can also be external, written using plain text and then your program has to read (parse) it, "player 1 draw a card".

Writing a super high level DSL for Magic sounds very interesting and I don't really have an idea of what it would look it. Obviously some actions happen concurrently (at the same time) so that has to be taken into account.

On my blog I've talked about different ways of encoding a Magic card. If you use plain text to encode a card, that is an external DSL. Obviously everybody is going have different ideas of how to do this but below are some of my thoughts.

Some people won't like my "text" labels but I think they would simplify the programming. On a separate issue, I don't know the pros and cons of putting each card in a separate file.

Shock
R
Instant

Spell
Text: Shock deals 2 damage to target creature or player.
Target: creature or player
Resolve: damage target creature or player, 2


Prodigal Pyromancer
2 R
Creature Human Wizard
1/1

Activated Ability
Text: tap: Prodigal Pyromancer deals 1 damage to target creature or player.
Cost: tap
Resolve: damage target creature or player, 1


Venerable Monk
2 W
Creature Monk
2/2

Triggered Ability
Text: When Venerable Monk enters the battlefield, you gain 2 life.
Trigger: enters the battlefield
Resolve: gain life – controller, 2


Holy Strength
W
Enchant Creature

Static Ability
Text: Enchanted creature gets +1/+2.
Effect: enchanted creature gets, +1/+2

Re: Magic - Domain Specific Language

PostPosted: 25 Mar 2010, 20:27
by mtgrares
I tend to get carried away also. Maybe just having a DSL for the cards is good enough. :D

Re: Magic - Domain Specific Language

PostPosted: 25 Mar 2010, 21:42
by Rob Cashwalker
Why not concentrate on getting DSL for your house? ;-)

Re: Magic - Domain Specific Language

PostPosted: 25 Mar 2010, 23:55
by telengard
Incantus and I have talked about a DSL for MtG type games many times. It is do-able but we'd probably do it in Lisp.

~telengard

Re: Magic - Domain Specific Language

PostPosted: 25 Mar 2010, 23:57
by MageKing17
Hell, Magic templating is so formulaic that the possibility of direct oracle parsing has come up more than once. It's still on our to-do list. ;)

Re: Magic - Domain Specific Language

PostPosted: 26 Mar 2010, 11:57
by Rob Cashwalker
The problem with directly parsing magic rules text is that they're constantly changing it.... And that would also mean that every time they revise the oracle wording of a card, the interpreter would need to be patched not to mention updating your equivalent cards.txt with all the new text.
For Forge, the card functionality is only half the battle. The AI needs to know what to do with it too.

Re: Magic - Domain Specific Language

PostPosted: 26 Mar 2010, 17:47
by MageKing17
Rob Cashwalker wrote:The problem with directly parsing magic rules text is that they're constantly changing it.... And that would also mean that every time they revise the oracle wording of a card, the interpreter would need to be patched not to mention updating your equivalent cards.txt with all the new text.
Yes, that is a problem, but you'd have to patch it every time a new set (with new functionality) came out anyway, and new set releases are the same times they release updated oracle wordings.

Re: Magic - Domain Specific Language

PostPosted: 26 Mar 2010, 18:52
by mtgrares
telengard wrote:Incantus and I have talked about a DSL for MtG type games many times. It is do-able but we'd probably do it in Lisp.
I've played around with Lisp a little and I understand that is very different from C and Java (since Lisp is functional versus declarative or something like that) but what would some of the Lisp Magic DSL look like?

Rob Cashwalker wrote:Why not concentrate on getting DSL for your house? ;-)
If I would get DSL at home, I would actually do even less programming. Computers can be addictive.

Re: Magic - Domain Specific Language

PostPosted: 07 Apr 2010, 19:22
by zerker2000
I definitely don't like the "Text" labels: I stand firm in opinion that a program claiming to understand a card must clearly explain to us how, exactly, it understands it. Also, why did you put "Target: creature or player" on Shock and not on Prodigal Pyromancer? I'd think objects(in the mtg rulebook sense) should be treated as similarly as possible...