It is currently 27 May 2019, 07:30
   
Text Size

I'm developing a rules enforcement system, need help

General Discussion of the Intricacies

Moderator: CCGHQ Admins

I'm developing a rules enforcement system, need help

Postby Jonix » 18 Aug 2009, 09:04

First of all, I am not a programmer. However, I've been working as a producer/game designer for a while, and I have some skills in developing algorithms and systems for games.

Right now, I am developing a rules enforcement system for Magic, that could be implemented to support something like 95% of all cards ever printed.

But, I have to admit that since my playing experience is limited, and I am not familiar with many blocks/sets, thus I need some help.

So far, all cards that I could pen'n'paper test with my system should be working just fine. But I am sure that there might be some tricky cards that I am simply not aware of.

All I am asking for are examples of cards that are extremely hard to implement with currently available engines, so that I can test my system on those. If my system is not any better that those available, it just might not be worth working on.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Snacko » 18 Aug 2009, 10:39

Most of the problems lie in the layer system an it's interaction with different triggered abilities. You should read Comprehensive Rules which describe game of magic in an algorithm like fashion, there's also Ruling Summaries, which can tell how the card behaves with other cards, however it might be no in sync with the current rules so you always have to check.

Some of the most abused examples of hard to implement card interactions are Conversion, Magus of the Moon, and Watery Grave at the same time which makes Watery Grave into Plains.

Other similar combo is Urborg, Tomb of Yawgmoth and either Blood Moon or Magus of the Moon. All nonbasic lands will be Mountains, not Swamps. Urborg, Tomb of Yawgmoth will be a Mountain as well. It will have "{T}: Add R to your mana pool" and no other abilities.


Yixlid Jailer + many cards example: Mistform Ultimus. If Mistform Ultimus is in the graveyard, the Ultimus will lose its ability that says "Mistform Ultimus is every creature type," but it will still *be* all creature types. The way continuous effects work, Mistform Ultimus's type-changing ability is applied before Yixlid Jailer's ability removes it.

Dryad Arbor + Teferi, Mage of Zhalfir completely useless, but interesting case. If a Dryad Arbor gains flash, or you have the ability to play Dryad Arbor as though it had flash, you can ignore the normal timing rules for playing a land, but not any other restrictions. You can't play Dryad Arbor during another player's turn, and you can't play Dryad Arbor if it's your turn and you've already played a land.

There are so many more, but if you have the layer system right you you can do 99% of cases.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 73 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 18 Aug 2009, 13:11

Thanks for the response, Snacko.

Well, I'm not sure why would Mistform Ultimus still be all creature types, since it is stated on a card that it is an Illusion type creature (and ability of being all creature types is temporarily cancelled by Yixlid Jailer's effect).

Dryad Arbor + Teferi, Mage of Zhalfir case is not a problem, since in my system playing lands is similar to playing a sorcery card (limited to main phases of your turn) and uses special L(land) mana (every turn one L mana is given to you, some cards' effects may give you additional L mana. At the end of the turn all unused L mana is burned).

Other two examples are really not a very big problem, but it should be strictly stated when effects are applied to cards (in what order). Problem with Watery Grave is that if its ability is activated before Magus of the Moon affects it or not. In my system changes to cards that make them other cards are done in 2 fashions - by temporarily exchanging these cards with specially created effect-tokens, and by adding extra invisible effects (read invisible enchantments) to existing cards.
Let me give an example:

Let's say we play Living Lands. All Forests should become 1/1 Creatures, but they should still be lands. What does that mean? This means that all Forests become Llanovar Elves - like creatures (that are still lands) and when Living Lands gets out of play, they should get back to being Forests. What I do with Living Lands is I change its main effect so that an invisible legacy enchantment (LLEnchantment) token is placed on each Forest making it a 1/1 creature in addition to being a land. Also, I add an invisible (not mentioned in card text) effect - "When Living Lands leaves play remove all LLEnchantment tokens from the game". Of course, it will remove only 1 example of the token from each Forest, which is a child of this particular entity of the Living Lands.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 18 Aug 2009, 13:37

I have checked with the comprehensive rules. Watery Grave will not be able to activate its ability since it enters the battlefield as Plains.

"610.3c Continuous effects that modify characteristics of permanents do so simultaneously with the permanent entering the battlefield. They don’t wait until the permanent is on the battlefield and then change it. Because such effects apply as the permanent enters the battlefield, they are applied before determining whether the permanent will cause an ability to trigger when it enters the battlefield.
Example: A permanent with the static ability “All white creatures get +1/+1” is on the
battlefield. A creature spell that would normally create a 1/1 white creature instead
creates a 2/2 white creature. The creature doesn’t enter the battlefield as 1/1 and then change to 2/2. "
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Snacko » 18 Aug 2009, 15:01

Mistform Ultimus + Yixlid Jailer shows how layers work:
Mistform Ultimus' continuous effect is layer 4, while Yixlid Jailer continuous effect is layer 5.
418.5a - The values of an object's characteristics are determined by starting with the actual object, then applying continuous effects in a series of layers in the following order: (1) copy effects (see Rule 503, "Copying Objects"); (2) control-changing effects; (3) text-changing effects; (4) type-changing effects (which includes effects that change an object's card type, subtype, and/or supertype); (5) all other continuous effects, except those that change power and/or toughness; and (6) power- and/or toughness-changing effects. CompRules 2007/10/01 Inside each layer from 1 through 5, apply effects from characteristic-defining abilities first, then all other effects in timestamp order. Inside layer 6, apply effects in a series of sublayers in the following order: (6a) effects from characteristic-defining abilities; (6b) all other effects not specifically applied in 6c, 6d, or 6e; (6c) changes from counters; (6d) effects from static abilities that modify power and/or toughness but don't set power and/or toughness to a specific number or value; and (6e) effects that switch a creature's power and toughness. Within each sublayer, apply effects in timestamp order. Note that dependency may alter the order in which effects are applied within a layer or sublayer. See also the rules for timestamp order and dependency (Rule 418.5b through Rule 418.5g). CompRules 2007/07/13
Other two examples are really not a very big problem, but it should be strictly stated when effects are applied to cards (in what order).
This should be somehow handled in the game engine as you should make card independent of each other, as in not needing to specify all cards it may interact with I can only think of multipass design within each layer that satisfies this condition, but that's slow with many cards.

The Mistform Ultimus and Magus of the Moon examples operate on the same layer rules so I don't see how you can get one working while the other one doesn't. This means you don't have a proper layer system in place.

Also as you wrote the example, will living lands trigger comes into play events for creatures in your system as 610.3c states the forests come into play as 1/1 creatures?
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 73 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 18 Aug 2009, 16:21

Mistform Ultimus + Yixlid Jailer shows how layers work:
Mistform Ultimus' continuous effect is layer 4, while Yixlid Jailer continuous effect is layer 5.
That is exactly why Mistform Ultimus should be an Illusion type, not all types. Layer 5 overrides level 4, since it is applied "later" (if later is a proper word for continuous effects :) ).

Also as you wrote the example, will living lands trigger comes into play events for creatures in your system as 610.3c states the forests come into play as 1/1 creatures?
Definetely. They will be Forests (basic lands) upon casting, but 1/1 creatures upon resolving, as all effects that have to be applied to casted spell will go on stack once you've cast that spell.

Thanks to our conversation I figured that I have to adapt all additional events and effects I use in the system to the current layer structure. I might need to add additional layers.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Snacko » 18 Aug 2009, 17:55

That is exactly why Mistform Ultimus should be an Illusion type, not all types. Layer 5 overrides level 4, since it is applied "later" (if later is a proper word for continuous effects :) ).
That's why people don't understand layers, once an effect is applied in one of the layers it stays unless overwritten. Layers can't interact with each other retroactively.

Another example:
Humility and 2x Opalescence in play at the same time.
Humility removes abilities in layer 5, change to 1/1 in layer 6, opalescence is layer 4.
So the Opalescences go first, changing all enchantments (including each other) into creatures of various sizes and with their original abilities. Then, in layer 5, all those abilities are removed. Finally, in layer 6, all creatures become 1/1 (rule 418.5b).

418.5b - If an effect should be applied in different layers, the parts of the effect each apply in their appropriate layers. If an effect starts to apply in one layer, it will continue to be applied to the same set of objects in each other applicable layer, even if the ability generating the effect is removed during this process.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 73 times

Re: I'm developing a rules enforcement system, need help

Postby Incantus » 19 Aug 2009, 01:26

Hey Jonix,

Good to see another rule-enforcement project. I look forward to seeing/hearing about the design you come up with. The comp rules are pretty good (they almost read like a programming specification document), but sometimes there are cases that aren't well explained (and sometimes, errata on cards is inconsistent with the comp rules, or at least inconsistent with a certain interpretation/implementation). If you ever have any questions about Incantus let me know.

Here's a good card interaction from the comp rules that covers a number of corner cases:

Code: Select all
607.3b. If a permanent spell resolves but its controller can't put it onto the battlefield, that player puts it into its owner's graveyard.

    Example: Worms of the Earth says "If a land would enter the battlefield, instead it doesn't." Clone says "You may have Clone enter the battlefield as a copy of any creature on the battlefield." If a player casts Clone and chooses to copy Dryad Arbor (a land creature) while Worms of the Earth is on the battlefield, Clone can't enter the battlefield from the stack. It's put into its owner's graveyard.
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: I'm developing a rules enforcement system, need help

Postby Marek14 » 19 Aug 2009, 06:35

I would guess that Piracy or Word of Command would be hard to implement. Harder than Mindslaver (which, after all, does nothing more than change which player gets to make the decisions)

Also:

Text-changing effects like Magical Hack, Sleight of Mind, Artificial Evolution and Volrath's Shapeshifter (though that's basically a hack). If you wish to include them, you'd better plan for it from the beginning, as they are very hard to add once your system works :)

Remember interaction between -1/-1 counters and Kinsbaile Borderguard (if Kinsbaile Borderguard is killed by -1/-1 counters and has some +1/+1 counters, they cancel each other at the same time KB dies, so last time it was in play it still has ALL the counters and gives out tokens according to that number).

Another hard thing might be "as though" abilities. See Wall of Diffusion, Masako the Humorless, Thousand-Year Elixir, various "as though it has flash" cards like Aluren, Animate Wall, Autumn Willow, Celestial Dawn, Crevasse, Street Savvy, Staff of the Ages, Deathcoil Wurm etc.
You should decide whether you want to make some general architecture that would be able to deal with them, or if you want to hard-code them as exceptions that are checked by the main rules. Both approaches have their advantages and disadvantages, the second if probably easier, but needs "grooming" as the new sets come out. For example, to check if tapped creatures can block, you currently only need to store this information once per player since the only card that can do this (Masako the Humorless) makes all creatures controlled by one player able to block when tapped. Similarly, you'd only need one flag to make creatures deal combat damage based on toughness, since both cards that allow this (Doran the Siege Tower and The Great Forest from Planechase) are global effects - but there is no guarantee that they won't print "Target creature assigns combat damage equal to its toughness rather than power" next set, so if you go the easier way, be on guard for nasty surprises like that.

Some mechanics might be hard to implement, especially suspend with its forced playing of suspended spell. Because any spell can be potentially suspended, thanks to Jhoira of the Ghitu and Delay, this forced playing may interact with various additional costs, sometimes with strange results. On the other hand, implementing phasing is easier than ever thanks to recent rules changes.

Morph and flip cards both use special statuses (face-down and flipped) which are defined in the game as such, and so they should be taken into account from the beginning.

Finally, there are some hard problems with complex interactions of forced attacking or (especially) forced blocking. I wrote a file on this, available on demand :)

EDIT: I forgot one thing: state triggers, like Endangered Armodon. They are probably harder than regular triggered abilities.

Also, extended mana system required for things like:

Mishra's Workshop
Primal Beyond (think also about what happens when hit with Artificial Evolution!)
Boseiju, Who Shelters All
Adarkar Unicorn
Rosheen Meanderer
Imperiosaur
Snow mana from Coldsnap
Marek14
Tester
 
Posts: 2644
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 260 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 19 Aug 2009, 08:27

Another example:
Humility and 2x Opalescence in play at the same time.
Humility removes abilities in layer 5, change to 1/1 in layer 6, opalescence is layer 4.
So the Opalescences go first, changing all enchantments (including each other) into creatures of various sizes and with their original abilities. Then, in layer 5, all those abilities are removed. Finally, in layer 6, all creatures become 1/1 (rule 418.5b).
Opalescence is not pure layer 4, it is both layer 4 and layer 7 (7c to be more specific). Change into 1/1 from Humility is Layer 7b.

Therefore, it should go like this:

- Opalescence changes all enchantments into creatures (including each other) in Layer 4;
- Humility removes all abilities in Layer 6;
- Humility changes P/T of all creatures to 1/1 in Layer 7b;
- Opalescence changes P/T of all creatures to manacost/manacost in Layer 7c.

Correct me if I am wrong.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Marek14 » 19 Aug 2009, 09:10

Jonix wrote:
Another example:
Humility and 2x Opalescence in play at the same time.
Humility removes abilities in layer 5, change to 1/1 in layer 6, opalescence is layer 4.
So the Opalescences go first, changing all enchantments (including each other) into creatures of various sizes and with their original abilities. Then, in layer 5, all those abilities are removed. Finally, in layer 6, all creatures become 1/1 (rule 418.5b).
Opalescence is not pure layer 4, it is both layer 4 and layer 7 (7c to be more specific). Change into 1/1 from Humility is Layer 7b.

Therefore, it should go like this:

- Opalescence changes all enchantments into creatures (including each other) in Layer 4;
- Humility removes all abilities in Layer 6;
- Humility changes P/T of all creatures to 1/1 in Layer 7b;
- Opalescence changes P/T of all creatures to manacost/manacost in Layer 7c.

Correct me if I am wrong.
You are wrong. Opalescense is 7b as well (it sets power/toughness to a well-defined value, as opposed to modifying it). Since both effects are Layer 7b (and there's never any dependency in Layer 7), they should be applied in timestamp order and the enchantments end up with P/T equal to CMC if Humility didn't enter the battlefield last, or as 1/1 if Humility entered the battlefield last.
Marek14
Tester
 
Posts: 2644
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 260 times

Re: I'm developing a rules enforcement system, need help

Postby Snacko » 19 Aug 2009, 09:33

Have to agree with Marek14 as I did use the pre M10 rules and forgot to update the comprehensive rules.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 73 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 19 Aug 2009, 09:35

Thank you, Marek14, you have provided some very good examples of tricky cards and combos. I will have to think them over.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Re: I'm developing a rules enforcement system, need help

Postby Marek14 » 19 Aug 2009, 09:38

Another potentially hard part of the rules might be linked abilities, especially with connection to copies (for example, Voice of All Mirrorweaved into another Voice of All will have no protection) and activated ability copying (if Quicksilver Elemental copies Sisters of Stone Death twice, it gets two separate groups of abilities, with cards removed by each one invisible to the other group).
Marek14
Tester
 
Posts: 2644
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 260 times

Re: I'm developing a rules enforcement system, need help

Postby Jonix » 19 Aug 2009, 09:39

Opalescense is 7b as well
My bad, i can see the difference now.

It seems that understanding layers is my number 1 priority.
Jonix
 
Posts: 43
Joined: 27 May 2009, 17:27
Has thanked: 2 times
Been thanked: 2 times

Next

Return to Magic Rules Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest


Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 287 on 31 Mar 2019, 04:11

Users browsing this forum: No registered users and 1 guest

Login Form