Thursday, November 12, 2009

Traps in the rules system

I think you can divide the rules in several complexity stages:
  • The "dumb" parts, like damage assignment order. These are things that aren't too hard, but you have to do them. When assigning blockers, you have to store a collection of the blockers anyway, letting the user sort it is not much more work. Another thing is mulligan, this is a check at the beginning of the game, and you just do it or not.
  • The challenging parts. I consider the layering system of Magic is such thing. The layering system is quite complex: Effects that modify different characteristics are applied after each other, so you have to store the basic characteristics (as printed on the cards) and the effects that modify it. it's not enough to store the results, because of cases like:
    some 1/1 creature
    attach Bonesplitter (+2/+0) --> 3/1
    switch P/T --> 1/3
    unattach bonesplitter --> -1/3
    well, this is obviously wrong. you have to do a bunch of work (not dumb work, though) to get this right, but it's not undoable
  • The very hard parts. I think text-changing and replacement effects fall under this category. text changing effects require a very good structure for storing card text, that makes it possible to change any interesting part. well it may be simple to change "Goblin" into "Elf", but think about changes like "Choose one" into "Choose two", that don't only affect what the outcome of the effect is, but actually what happens.
    Replacement effects have a similar problem as Triggered ability. Both need an event system that makes it possible to track changes to the game, but replacement effect don't only listen to events, they also negate those events on the fly.
obviously, the second category is the most fun to program. i actually have a working layer system, it took me around 3,500 lines of code in about 40 classes.


nantuko84 said...

previous week while working on Gigantiform, I've reimplemented power\toughness stuff (previously I didn't know a lot about p\t layers a lot)

I also like another example that is similar to your but changed a little:

some 1/2 creature
switch P/T --> 2/1
attach Bonesplitter (+2/+0) --> 2/3

it is because switch is applied last, so Bonesplitter gives +0/+2

Bruno Cardoso said...

Very nice situation that of P/T switching and bonesplitter. I've played MTG at high competition level and I know how complex and detailed rules can be.

I remember a situation back in Mirrodin with the "Ravager Affinity" deck. I had less life than my opponent so normally I couldn't just sacrifice artifacts to drop his life to zero before mine went to zero. However, if I did that in my opponent's turn, I could sacrifice 20 artifacts give him 20 damage before I receive any damage at all, thus wining the game.
It was just a matter of knowing how stack effects works. If i remember it correctly it was like:
- sac. an artifact.
- his disciple effect goes to stack
- my disciple effect goes to stack
(because it's his turn, his disciple effect goes to stack first and resolves less)
- my disciple effect resolves and my opponent gets 1 damage.
- now, in response to his disciple effect I sac another artifact and the cycle repeats until he's dead and all his disciple's effect stay in the stack.

When he dies, the game ends and his effects never get to resolve.

Nice huh ? ;)

PS: I don't know if this rules still apply. I have been away from competition for several years.