how do other rules engines handle overriding core rules?
General Discussion of the Intricacies
Moderator: CCGHQ Admins
how do other rules engines handle overriding core rules?
by Incantus » 13 Jun 2008, 19:13
Well, I asked for this forum, so I should start it off.
I was wondering how people handle special abilities that override core game rules? In python it's pretty easy, since everything is an object. I basically use a variant of Aspect Oriented Programming (see wikipedia's page http://en.wikipedia.org/wiki/Aspect-ori ... rogramming for a completely obtuse description), where the card will basically inject new code into the part of the rules code that it affects. When the card is removed from play, it removes the code it injected. The nice part about this is the core rules engine follows the comp rules and is completely oblivious to possible changes by cards.
How about you? What do programs like Deckbot (C++) and Firemox (Java) do?
I was wondering how people handle special abilities that override core game rules? In python it's pretty easy, since everything is an object. I basically use a variant of Aspect Oriented Programming (see wikipedia's page http://en.wikipedia.org/wiki/Aspect-ori ... rogramming for a completely obtuse description), where the card will basically inject new code into the part of the rules code that it affects. When the card is removed from play, it removes the code it injected. The nice part about this is the core rules engine follows the comp rules and is completely oblivious to possible changes by cards.
How about you? What do programs like Deckbot (C++) and Firemox (Java) do?
Re: how do other rules engines handle overriding core rules?
by Marek14 » 14 Jun 2008, 08:21
A minor problem I see with this approach is that I'm not sure if it would handle layers and dependencies correctly.
I.e. imagine you have Conversion, Magus of the Moon, and Watery Grave in play together. Dependencies mean that Watery Grave should be always Plains, regardless on the order in which the cards came into play. Does this work?
I.e. imagine you have Conversion, Magus of the Moon, and Watery Grave in play together. Dependencies mean that Watery Grave should be always Plains, regardless on the order in which the cards came into play. Does this work?
Re: how do other rules engines handle overriding core rules?
by HarryPitfall » 14 Jun 2008, 16:53
I'll tell how is working on my "early-beta" code... (I'm building a Magic Game vs Computer too, very early).
Currently, all is done in SBE processing, the game "sends" sbe messages to all cards in game, and the cards replying with "how many cards is affected", the SBE loops while cards are affected.
example:
2 lands, 1 urborg and 1 blood moon...
sbe loop #1
the lands sets itself it's type, and say 1 card affect each (+2)
urborg set itself, and 2 lands with new types (+3)
blood moon changes urborg to mountain (+1)
sbe loops again since 6 cards are affected
the lands dont do nothing, since, they already do it's work
urborg DONT have any ability (aka, disabled), and rollback, removing the swamp type of affected lands on last loop. (+3)
blood moon dont have another cards to affect
sbe loops again since 3 cards are affected
the lands do nothing
urborg do nothing
blood moon do nothin
end of sbe!
This approach take care of some dependencies of the cards, but needs lots of "array" data to remeber what the cards/abilities affects.
The SBE loops using incremental commands, SBE_INIT, SBE_LAYER_1, SBE_LAYER_2... SBE_END... so, each card/ability will be called in layer order and timestamp order after.
Currently, all is done in SBE processing, the game "sends" sbe messages to all cards in game, and the cards replying with "how many cards is affected", the SBE loops while cards are affected.
example:
2 lands, 1 urborg and 1 blood moon...
sbe loop #1
the lands sets itself it's type, and say 1 card affect each (+2)
urborg set itself, and 2 lands with new types (+3)
blood moon changes urborg to mountain (+1)
sbe loops again since 6 cards are affected
the lands dont do nothing, since, they already do it's work
urborg DONT have any ability (aka, disabled), and rollback, removing the swamp type of affected lands on last loop. (+3)
blood moon dont have another cards to affect
sbe loops again since 3 cards are affected
the lands do nothing
urborg do nothing
blood moon do nothin
end of sbe!
This approach take care of some dependencies of the cards, but needs lots of "array" data to remeber what the cards/abilities affects.
The SBE loops using incremental commands, SBE_INIT, SBE_LAYER_1, SBE_LAYER_2... SBE_END... so, each card/ability will be called in layer order and timestamp order after.
- HarryPitfall
- AI Programmer
- Posts: 175
- Joined: 31 May 2008, 00:14
- Has thanked: 1 time
- Been thanked: 3 times
Re: how do other rules engines handle overriding core rules?
by Incantus » 14 Jun 2008, 20:39
I don't know. I haven't tried to implement dependent effects yet. But once I can get one to work they should all workMarek14 wrote:A minor problem I see with this approach is that I'm not sure if it would handle layers and dependencies correctly.
I.e. imagine you have Conversion, Magus of the Moon, and Watery Grave in play together. Dependencies mean that Watery Grave should be always Plains, regardless on the order in which the cards came into play. Does this work?
Re: how do other rules engines handle overriding core rules?
by BlackMamba » 17 Sep 2008, 01:26
So.. did you implement it? How was it? Any advice on what not to do?
I'm curious...
I'm curious...
- BlackMamba
- Posts: 23
- Joined: 17 Sep 2008, 01:24
- Has thanked: 0 time
- Been thanked: 0 time
Re: how do other rules engines handle overriding core rules?
by mtgrares » 27 Jan 2009, 20:39
A simple way of overrding the core rules is to have core rules themself check for the abnormality.
- Code: Select all
doCombatDamage()
if(Doran, the Siege Tower)
do combat damage differently
else
do normal combat damage
- Code: Select all
getMana()
if(Mana Flare in play)
return double mana
else
return mana
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: how do other rules engines handle overriding core rules?
by Incantus » 27 Jan 2009, 22:41
Oh, but what happens if Doran is targeted by a successful Snakeform?mtgrares wrote:A simple way of overrding the core rules is to have core rules themself check for the abnormality.
- Code: Select all
doCombatDamage()
if(Doran, the Siege Tower)
do combat damage differently
else
do normal combat damage
Re: how do other rules engines handle overriding core rules?
by frwololo » 28 Jan 2009, 01:08
if you consider "Doran, the siege Tower" as the ability, and not the card name, it works.incantus1 wrote:Oh, but what happens if Doran is targeted by a successful Snakeform?mtgrares wrote:A simple way of overrding the core rules is to have core rules themself check for the abnormality.
- Code: Select all
doCombatDamage()
if(Doran, the Siege Tower)
do combat damage differently
else
do normal combat damage
Re: how do other rules engines handle overriding core rules?
by MageKing17 » 28 Jan 2009, 02:47
It's still incredibly silly. ;P
-
MageKing17 - Programmer
- Posts: 473
- Joined: 12 Jun 2008, 20:40
- Has thanked: 5 times
- Been thanked: 9 times
Re: how do other rules engines handle overriding core rules?
by mtgrares » 28 Jan 2009, 19:48
Well, I was just considering Doran, the Siege Tower the card. It would be better if the card representing Doran had something representing the ability, even if it is just a string. So the Doran card would have getAbility():String[] which would return an array of Strings representing all of Doran's abilities.
And ideal solution is a whole event system, or just a generic blackboard, but you might not know what sort of event system you need until you add a few cards.
(Blackboard is just a generic global "messaging system" where messages are posted and searched. A simple Blackboard would just be strings.)
Blackboard
post(message)
contains(message) : boolean
I haven't used a blackboard but I think about it. Global variables and objects are useful but they can make the programming very confusing if you have an error anywhere.
Blackboard could be more complicated
post(message, other_data)
get(message) - returns other_data
contains(message)
- Code: Select all
doCombatDamage()
if(Doran, the Siege Tower is in play and
has the ability "assign toughness in combat")
{
do combat damage differently
}
else
{
do normal combat damage
}
And ideal solution is a whole event system, or just a generic blackboard, but you might not know what sort of event system you need until you add a few cards.
(Blackboard is just a generic global "messaging system" where messages are posted and searched. A simple Blackboard would just be strings.)
Blackboard
post(message)
contains(message) : boolean
I haven't used a blackboard but I think about it. Global variables and objects are useful but they can make the programming very confusing if you have an error anywhere.
Blackboard could be more complicated
post(message, other_data)
get(message) - returns other_data
contains(message)
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
10 posts
• Page 1 of 1
Return to Magic Rules Engine Programming
Who is online
Users browsing this forum: No registered users and 12 guests