18 votes

A peek into the MTG Arena rules engine: "On Whiteboards, Naps, and Living Breakthrough"

4 comments

  1. riQQ
    Link

    So first, a quick summary of how the rules engine works. When a game of Magic is in progress on MTG Arena, the program that is tracking the state of the game and enforcing all the rules-correct card interactions is called the Game Rules Engine (GRE). It's one of the two main programs that we work on. It's written in a combination of C++ and a language called CLIPS, which is a variant of LISP.

    What does the GRE do? Well, for the most part, it just knows the basic rules of Magic:

    • It knows which player gets priority and when.
    • It knows that creatures die when they have lethal damage.
    • It knows how to move between the phases of a turn.
    • It knows the steps of casting a spell.

    What it does not know is what any of the thousands of individual Magic cards do.

    6 votes
  2. [3]
    JRandomHacker
    Link
    It has its quirks, sure, but I'm continuously so impressed by the Arena dev team and the work they do. As both a software developer and a Magic judge, I've got a pretty reasonable grasp on the...

    It has its quirks, sure, but I'm continuously so impressed by the Arena dev team and the work they do. As both a software developer and a Magic judge, I've got a pretty reasonable grasp on the problem at hand and it's really incredible what they've managed to do.

    I've also had a decent amount of chats with one of the Arena team leads (Ian Adams, or WotC_Ian) in a Magic-related Discord I'm in. He's a great guy and is always responsive and curious when we find some utterly bizarre corner-case rules bug.

    5 votes
    1. [2]
      NonoAdomo
      Link Parent
      They get lots of flak for the management of formats, but the actual functional side of the client is a beauty. It is incredibly rare for a card to be functionally broken in the game at any point...

      They get lots of flak for the management of formats, but the actual functional side of the client is a beauty. It is incredibly rare for a card to be functionally broken in the game at any point in time, which speaks volumes about their automated regression testing. Compare that to MTGO, which has had cards broken for years on end in the past, and it's like night and day.

      3 votes
      1. AnderExelion
        Link Parent
        I think Magic Arena does a great job with card interactions and the GRE. Very rarely are card interactions broken or incorrect and they seem to fix issues quickly. The only issues I have are with...

        I think Magic Arena does a great job with card interactions and the GRE. Very rarely are card interactions broken or incorrect and they seem to fix issues quickly.

        The only issues I have are with it's netcode if your internet connection isn't completely stable or if your game crashes. On PC I am fine 99 percent of the time but if mobile freezes, which is a not uncommon event on my pixel 7a, attempting to rejoin a match in progress is a very bad experience. It doesn't seem that the clients/server communicate game state frequently. Waiting to rejoin seems to wait until a ttl on your previous turn hits and then let's you rejoin after losing a turn or timeout.

        2 votes