It is currently 27 Apr 2024, 18:22
   
Text Size

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?

Postby 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?
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: how do other rules engines handle overriding core rules?

Postby 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?
Marek14
Tester
 
Posts: 2761
Joined: 07 Jun 2008, 07:54
Has thanked: 0 time
Been thanked: 297 times

Re: how do other rules engines handle overriding core rules?

Postby 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.
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?

Postby Incantus » 14 Jun 2008, 20:39

Marek14 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?
I don't know. I haven't tried to implement dependent effects yet. But once I can get one to work they should all work ;)
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: how do other rules engines handle overriding core rules?

Postby BlackMamba » 17 Sep 2008, 01:26

So.. did you implement it? :) How was it? Any advice on what not to do? :P

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?

Postby 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
This way of doing things isn't great but it will work for awhile until you figure out the best way for your program to handle it.
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?

Postby Incantus » 27 Jan 2009, 22:41

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
Oh, but what happens if Doran is targeted by a successful Snakeform? ;)
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: how do other rules engines handle overriding core rules?

Postby frwololo » 28 Jan 2009, 01:08

incantus1 wrote:
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
Oh, but what happens if Doran is targeted by a successful Snakeform? ;)
if you consider "Doran, the siege Tower" as the ability, and not the card name, it works.
frwololo
DEVELOPER
 
Posts: 265
Joined: 21 Jun 2008, 04:33
Has thanked: 0 time
Been thanked: 3 times

Re: how do other rules engines handle overriding core rules?

Postby MageKing17 » 28 Jan 2009, 02:47

It's still incredibly silly. ;P
User avatar
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?

Postby 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.

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
  }
Snakeform would just remove the ability string until EOT.

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


Return to Magic Rules Engine Programming

Who is online

Users browsing this forum: No registered users and 14 guests


Who is online

In total there are 14 users online :: 0 registered, 0 hidden and 14 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 14 guests

Login Form