M:TG Evolution part I

Carrying on with the M:TG sim project, here are some resources which I found on the subject through good ol’ Google….

http://mtgrares.blogspot.com/ the blog/homepage of the guy who wrote the Forge AI (a v. good M:TG game)

http://www.wizards.com/magic/magazine/article.aspx?x=mtg/daily/feature/43c Part 1 of 2 on the Duels engine (this one is engine details)

http://www.wizards.com/magic/magazine/article.aspx?x=mtg/daily/feature/44 Part 2 of 2 on the Duels engine (this one is on the AI)

http://magic.kevinleung.com/ This is the course page of some (college?) class ON M:TG and AI

… just thought I would save these in one place before I ran off and forgot all about them.

M:TG engine design concept

After thinking about this for a bit too long I settled on the idea that I should use signals rather than method calls to pass information between all the various agents. Basically, there is a “Game Manager” (GM) object which is in charge of dealing with turns, cost checking etc. Most importantly however, it has a list of EVERY CARD PLAYED TO DATE. Whenever something happens (a creature is placed, a land is played, a spell is cast, life is gained whatever) the card or pseudo-card (more on that later) which sourced the event sends a signal to the GM and the GM passes the same signal on to everything in that list of cards.

While slow, this keeps cards as special case classes trivial because there is no need to metaprogram methods like this.hasFlying() or this.onDamageDealt() or this.onBlocked(). Instead the Card superclass provides a signal handling function which does nothing by default but which is metaprogrammed by the card data to make the card react as desired. Default behavior for signals is to ignore them.

Example ~~~~~~~ I attack, and in doing so send a signal to the GM stating attacking creature(s) and target(s) (by creature)

ALL PLAYERS are notified of the move in its entirety even if they are not directly effected. Players have the opportunity to “throw down” instants or play unit abilities where possible.

Each target sends a signal either assigning blockers or “DONE”

I then get prompted for any instants or abilities of my own before damage is assigned and resolved. As blockers have been assigned this is the part where instants and abilities can have MAJOR effects.

I send any such signals and finally the “DONE” signal

The GM resolves the stack (if nonempty) and then damage, retargeting damage which would have been dealt to dead blockers to the dead creature’s controller then signals me for my end step.

As you can see, this is one metric SHIT TON of signals going EVERYWHERE. And this is just to impliment the standard card playing and effects mechanics. I really don’t want to think about how I would/will design an AI which can try to navigate this chaos and look ahead.

The good news however is that this basic design works for an arbitrary number of players and in theory teams although some little extra value will be needed to denote what “team” a given card or creature is on to allow for threat assessments by team not just by player.