The Complexity of Deciding Legality of A Single Step of Magic The Gathering
The Complexity of Deciding Legality of A Single Step of Magic The Gathering
Abstract. Magic: the Gathering is a game about magical combat 2. The cards in a hand of a player consists of the cards drawn from
for any number of players. Formally it is a zero-sum, imperfect in- the library but not yet played. Cards in a hand can be played for
formation stochastic game that consists of a potentially unbounded some cost. The cards in a hand is only visible to that player.
number of steps. We consider the problem of deciding if a move is
3. The stack consists of cards and effects that have been played or
legal in a given single step of Magic. We show that the problem is
triggered but are waiting to take effect. Whenever a card or ef-
(a) coNP-complete in general; and (b) in P if either of two small sets
fect is put on the stack, each player has, in turn, the opportunity
of cards are not used. Our lower bound holds even for single-player
to play more cards or effects. Whenever no player wants to add
Magic games. The significant aspects of our results are as follows:
more to the stack, the top card or effect on the stack takes effect.
First, in most real-life game problems, the task of deciding whether a
Alternately, if the stack is empty, the next phase or turn starts. The
given move is legal in a single step is trivial, and the computationally
content of the stack is visible to all players.
hard task is to find the best sequence of legal moves in the presence
of multiple players. In contrast, quite uniquely our hardness result 4. The cards on the battlefield consists of the cards that have a direct
holds for single step and with only one-player. Second, we establish influence on the game currently and are visible to all players.
efficient algorithms for important special cases of Magic.
5. The cards in the graveyard consists of cards that have been used
and are visible to all players.
Each card also has a card type. The important card types are:
1 Introduction
1. Instant/sorcery which, when taking effect, has some immedi-
ate or short-term effect on the game and immediately goes to the
Magic: the Gathering (henceforth, Magic) is a collectible card game graveyard.
where each player has the role of a mighty wizard that can cast spells
like fireballs or summon for instance dragons, angels, or demons. To 2. Artifact/enchantment which, when taking effect, enters the bat-
do so the wizards uses mana they get from lands or in other ways. The tlefield and have some long-term effect.
objective of each player is to win over the other wizards by killing 3. Planeswalker which, when taking effect, enters the battlefield,
them. with some amount of loyalty. On each of their turns, the controller
of the planeswalker can pick an effect, which typically includes
Legality of a move in a single step. We are interested in establishing an increase or decrease (but not below 0) of loyalty. Planeswalk-
complexity bounds for deciding whether a move is legal in a single ers can also be attacked to decrease their loyalty. Whenever the
step of a Magic game. Formally, Magic is a stochastic, imperfect in- loyalty of a planeswalker falls below 1, they go to the graveyard.
formation, zero-sum game over an unbounded number of turns. Each
4. Creature which, when taking effect, enters the battlefield. Most
turn is divided into some number of phases and each phase consists
creatures can attack and block in the combat phase and all crea-
of some number of steps, in which typically only one player has a
tures have a power x and a toughness y, denoted x/y on the cards.
choice. The only exception to the turn-based nature is that some cards
The power is the amount of damage the creature would do and the
require all players to perform some action at the same time.
toughness is how much damage a typical creature can take before
dying and going to the graveyard. Especially, a creature with 0
Cards. Each card in the game represents a specific spell, creature,
toughness dies immediately.
or land, and has in general very different properties. We describe
the typical properties of Magic relevant for this work, and there are 5. Land which does not use the stack, but can only be played when
many slight deviations which we omit. Each card has a name, a color the stack is empty. Each player can only play lands in his own turn
or colors (or is colorless) and consists of a drawing, illustrating the and only one land on each turn. Most lands are used to generate
effect of the card, and a text box stating what the card does. Whenever mana which is often used in the cost of the other card types.
we mention a card in the text we will write its name in bold font and
include a figure with the card. Each card can be in different zones. Trivia. Magic is a card game initially published in 1993, played by
The zones important for this paper are: around twenty million players worldwide and there exist 15.919 dif-
ferent Magic cards currently. Magic has the fourth largest real-life
1. Nearly all cards start in some library from which cards can be tournament, and other than Poker variants, it has the largest tourna-
drawn. The cards in any library are not visible to any player. ment. Magic is the first collectible card game, a category including
quite a few different games nowadays. While Magic is a single game,
1 IST Austria, Austria, email: {Krishnendu.Chatterjee,RIbsen}@ist.ac.at there exists many variants of the game, called formats, with currently
22 different formats receiving some official support. Different for- even in goldfish games (the single-player variant) measured in the
mats differs in which cards are legal, basic rules, number of players number of objects.
and their relations (i.e. adversarial or team) and even how the decks
3. Efficient algorithms for special cases. For two relatively small and
of cards played with are constructed. The value of cards can vary
nearly disjoint sets of cards rarely used in tournaments, consisting
greatly from basically nothing to $27.302 for a single card in regular
of 0.5% and 0.3% of all cards respectively, we show that finding
print.
a legal move in a single step in Magic games not using those cards
One player variant: Goldfish. None of the official formats in Magic are in DL (deterministic log-space) and P (PTIME) respectively.
are single-player, because the main purpose is real-world tourna- It follows from our results that in these cases deciding the legality
ments with multiple players. However, the relevance of one-player of a move in a single step also has the same complexity.
version is that any lower bound on this simple version represents Technical contributions. The key technical aspects are:
a stronger hardness result. We consider the most well-known one-
player variant:
• Goldfish. In goldfish, the lone player is playing against a “player”
that starts with no cards, never makes any choice and generally
never does anything unless forced to – a so called goldfish. Along
with the relevance mentioned above, the variant is used to provide
a benchmark on how fast a deck can win against a player that does
nothing relevant.
Result of this paper. We present three main results. 2. Relationship with classical graph algorithm. A key technical con-
tribution is that we establish a close relationship between the prob-
1. Classification of requirements and restrictions. We classify the lem we consider and the classical graph algorithm of min-cost-flow.
requirements and restrictions on Magic cards into a few classes. While the min-cost-flow problem can be solved in P, we show that
(Blockers must be declared such that all restrictions are satisfied the problem we consider requires a natural generalization: along with
and as few requirements as possible are broken, see Section 2). the standard capacity constraints (which specify that the flow is at
most the capacity), we require new constraints that specify that the
2. Complexity in general. We show that the legality of a move in a
flow is either 0 or at least a given threshold. Our result shows that
single step can be decided in coNP in general and is coNP-hard
this natural generalization makes the problem coNP-complete. On
2 The construction has later been improved, see [6, 7, 8], however these texts the other hand, if certain cards are not used, we present a many-to-
are posts on forums and less polished one reduction from our problem to the min-cost-flow problem.
Significance. The main significant implications are: is a flow from s to t and for other vertices the incoming flow matches
1. Magic-specific result. There exists an online tool for playing P flow). A flow f is feasible if (1) for all v ∈ (V \ {s, t})
the outgoing
we have (u,v)∈E f (u, v) ≤ c(v); and (2) for all e ∈ E we have
Magic, Magic Online ([20]), that checks the legality of a step. P
f (e) ≤ c(e). The value of a flow f is val(f ) = e∈E f (e) · w(e).
However, the tool considers a special case of Magic where at
The solution to a min-cost flow problem is a feasible flow with max-
most 200 tokens are allowed per player (i.e., it gives an algo-
imum value among all feasible flows. This problem is in P ([9]).
rithm for the special case when the size of the input problem is
small). In contrast, we first establish complexity of the general The declaration of blockers step. The declaration of blockers step
problem, showing that it is coNP-hard (even for single-player) is a part of the combat phase of a turn. In the combat phase of a turn
and no efficient (polynomial-time) algorithm exists in general (un- first a set of creatures A, controlled by P , is declared as attacking P 0
less coNP = P = NP). Second, we present efficient (polynomial- by P (in general with more players each of the creatures can attack
time) algorithms for two special cases, where a small number of different players other than P ). For the goldfish format, the player P
cards are not used, but there is no restriction on the number of is the goldfish player (in our lower bound), and there exist cards that
tokens. Thus we present efficient solution to orthogonal special ensure that all creatures must be declared attacking (this is the only
cases as compared to the online tool. option for the goldfish player). The creatures controlled by P 0 is the
2. Uniqueness of complexity. We consider games with a constant set B. After this step, if A is not empty, the defending player P 0 (in
number of players where each has a fixed and finite deck. More- general, a player is defending if he is attacked by some creature) can,
over, we consider the legality of a single step. In most real-life for each creature a ∈ A that attacks him, declare that some, perhaps
a A
games, either of the above restrictions would lead to trivial com- S subset B ⊆ B is going to block a. We will let B be the
empty,
putational complexity. The first restriction typically means that the set a∈A B a of blocking creatures. For any b ∈ B, we also define
problem size is constant. The second restriction implies that we do bA as {a | b ∈ B a }, i.e. the creatures b blocks. The complexity of
not consider strategic choices over multiple steps. In most real-life finding a legal declaration of blockers comes from rule 509.1c ([19]),
games the complexity comes from strategic choices (i.e., that max- which states, paraphrased, that a declaration of blockers is legal if it
imizes the probability to win over several steps). Quite uniquely satisfies all restrictions, while maximizing the number of satisfied
our lower bound is for legality of a single-step in a single-player requirements.
variant of Magic, and the complexity we obtain is neither from the
fact that the game is stochastic or imperfect information. The base case: No restrictions or requirements. If there are no
requirements or restrictions involved, each creature in A can be
3. General graph algorithm. Our technical contribution considers blocked by any number of creatures in B, but each creature in B
a generalization of the classic min-cost-flow problem on graphs can only block one creature of A and any such choice of blockers is
with additional constraints that either the flow is zero or at least legal. Using terminology from min-cost flow, the graph G is a bipar-
a threshold value. We show that such problem is coNP-complete, tite graph, with the source on the right side and the sink on the left.
and show that for real-life game problems (such as special cases Each state (besides the sink) on the left side corresponds to a creature
of Magic) the classical min-cost-flow algorithm can be used. in B and each state (besides the source) on the right side corresponds
to a creature in A, and the states on the left side has capacity 1 (be-
sides the sink, which has infinite capacity) while the states on the
2 The complexity of a single step right have infinite capacity. The source has an outgoing edge to each
state in B, each state in B has an outgoing edge to each state in A and
In this section we consider the complexity of a single step of a Magic each state in A has an outgoing edge to the sink. The edges between
game. Concretely we consider the complexity of deciding if in a A and B each have capacity 1 and the edges to/from the sink/source
given step, a given choice is legal. For most types of steps, besides have each infinite capacity. Also, each edge has weight 0.
the declare blockers step of the combat phase, this can easily be done
in log-space (hence in polynomial time). The reason for the log-space Restrictions and requirements. The complexity of the problem
complexity is that the legality of a choice (other than declaration of comes from the requirements and restrictions. We will explain re-
blockers) is local, in the sense that legality can be decided by only quirements and restrictions in how they modify the min-cost flow
considering pairs of objects (i.e. a card c might target another card c0 instance from the base case.
and is legal iff c0 can be targeted by c) and counts (i.e. a card c might
target k cards, which would be legal if c can have k targets). This Restrictions. Rule 509.1b ([19]) states that for a declaration of
can all be done in DL (deterministic log-space). We will thus focus blockers to be legal, every restriction must be satisfied. A restric-
on the declaration of blockers and argue that it is coNP-complete to tion is statement that says that a specific creature cannot block/be
find a legal declaration of blockers. We describe the problem using blocked unless some condition is met. This, in itself, does not cause
the min-cost-flow terminology (since min-cost flow is in P, see [9], any complexity, since for a fixed declaration of blockers, checking if
and our problem is not, some parts require generalization of min-cost a fixed restriction is satisfied is easy. We now consider the following
flow). five types of restrictions3 :
1. Local restrictions. Local restrictions are restrictions of the form:
Min-cost flow. The min-cost flow problem consists of a directed
a ∈ A cannot be blocked by b ∈ B (i.e. a local restriction is satis-
graph G = (V, E), a capacity function c : V ∪ E → N and a weight
fied if it is satisfied for each pair of affected creatures). Concretely,
function w : E → Z. Also, there is a designated source state s and
a could have flying and b could have neither reach or flying. A lo-
Pstate t. For a map MP: E → N, let ∆M : V → Z
a designated sink
cal restriction between a ∈ A and b ∈ B can be modeled in our
be ∆M (v) = (u,v)∈E M (u, v) − (v,u)∈E M (v, u). A flow is min-cost flow instance by removing the edge (a, b). For instance,
a map f : E → N such that (1) ∆f (s) ≥ 0; (2) ∆f (t) ≤ 0; and
3
(3) for all v ∈ (V \ {s, t}) the number ∆f (v) is 0 (intuitively, there To our knowledge, all restrictions fit into precisely one type
Figure 2. The cards are sorted from left to right. First row - cards with various types of non-capacity restrictions:
(1) Local restriction: Razortooth Rats
2016c Wizards of the Coast LLC in the USA & other countries. Illustration by Carl
Critchlow. Image used with permission;
(2) Local counting restriction k = 2: Boggart Brute
2016 c Wizards of the Coast LLC in the USA & other countries.
Illustration by Igor Kieryluk. Image used with permission;
(3) Local counting restriction k = 3: Guile
2016c Wizards of the Coast LLC in the USA & other countries. Illustration by
Zoltan Boros & Gabor Szikszai. Image used with permission;
Second row - continued:
(4) Local counting restriction k = |B|: Tromokratis
2016 c Wizards of the Coast LLC in the USA & other countries.
Illustration by Matt Stewart. Image used with permission;
(5) Global counting restriction k = 1: Silent Arbiter
2016 c Wizards of the Coast LLC in the USA & other countries.
Illustration by Mark Zug. Image used with permission;
(6) Global counting restriction k = 2: Caverns of Despair
2016 c Wizards of the Coast LLC in the USA & other countries.
Illustration by Harold McNeill. Image used with permission.
Razertooth Rats creates a local restriction with all non-artifact flow terminology (note that there must be something for the prob-
non-black creatures. lem to be coNP-complete, since min-cost flow can be solved in
P, see [9]). A local counting restriction on a ∈ A corresponds to
2. Local counting restrictions. Local counting restrictions are re- saying that a have either flow 0 or flow greater than k in min-cost
strictions of the form: a ∈ A cannot be blocked except by k or flow.
more creatures. Here, concretely, there exists cards for which k is
2 (i.e. cards with the ability Menace, like Boggart Brute), 3 (there 3. Global counting restrictions. Global counting restrictions are re-
are six cards, for instance Guile) and |B| (the card Tromokratis). strictions of the form: no more than k creatures can block. Here,
Local counting restrictions have no nice interpretation in min-cost concretely, there exists cards for which k is 1 (the cards Silent
Figure 3. Two first cards of first row - cards that can create capacity restrictions:
(1) Increase blocker capacity by 1: Iona’s Blessing
2016
c Wizards of the Coast LLC in the USA & other countries. Illustration
by David Gaillet. Image used with permission;
(2) Set capacity of attacker to 1:
Alpha Authority
2016c Wizards of the Coast LLC in the USA & other countries. Illustration by Ron Spencer. Image used
with permission.
Last card on first row and cards in second row - cards with various kinds of requirements:
(1) Generic attacker requirement: Irresistible Prey
2016
c Wizards of the Coast LLC in the USA & other countries. Illustration
by Jesper Ejsing. Image used with permission;
(2) Generic blocker requirement: Culling Mark
2016 c Wizards of the Coast LLC in the USA & other countries. Illustration
by Tomasz Jedruszek. Image used with permission;
(3) Special generic requirement: Nacatl War-Pride
2016 c Wizards of the Coast LLC in the USA & other countries. Illustra-
tion by James Kei. Image used with permission;
(4) Specific requirement: Hunt Down
2016 c Wizards of the Coast LLC in the USA & other countries. Illustration by Christo-
pher Moeller. Image used with permission.
Arbiter and Dueling Grounds) and 2 (the card Caverns of De- 4. Blocker capacity restriction. Blocker capacity restrictions are
spair). While there is no straightforward interpretation in min-cost restrictions of the form: b ∈ B must be such that |bA | ≤ k. By
flow, the global counting restrictions are easy to handle, by sim- default there is a blocker capacity restriction on each creature for
ply considering each creature or pair of creatures in B (depending k = 1, but k can be changed to any natural number4 , using for
on whether k is at least 1 or 2) as the set of creatures that can instance, a sufficiently large number of Iona’s Blessing. A blocker
block and then solving the problem with only those creatures in capacity restriction on b ∈ B with k ∈ N is modeled in min-cost
B (except that any Tromokratis cannot be blocked in this case,
assuming that |B| > 2 initially). 4 It can also be infinite. However, there is no difference between infinite and
k ≥ |A|
flow by having a capacity of k on b. since the declaration of blockers is a turn-based step, the coNP upper
bound holds.
5. Attacker capacity restriction. Attacker capacity restrictions are
restrictions of the form: a ∈ A must be such that |B a | ≤ k. coNP-hardness. Our reduction will be from exact cover by 3-sets.
Currently k can only be 1, which can be achieved by for instance The exact cover by 3-sets problem is as follows: A set of elements E
using Alpha Authority. A attacker capacity restriction on a ∈ A and a set S ⊆ 2E of sets of elements of E is given, such that |s| = 3
with k ∈ N can be modeled in min-cost flow with capacity of k for each s ∈ S, and
S the problem is to decide if there exists a subset
on a. S 0 of S such that s∈S 0 s = E and s ∩ s0 = ∅ for all s, s0 ∈ S 0 .
The exact cover by 3-sets problem is NP-complete ([13]).
Requirements. Rule 509.1c ([19]) states that the declaration of
blockers must maximize the number of requirements satisfied, while Consider an instance of the exact cover by 3-sets problem and we
not breaking any restrictions. A requirement is an ability that says will construct a combat instance and a declaration of blockers which
that a specific creature must block/be blocked (perhaps by a specific is not legal iff there exists a satisfying set S 0 for the exact cover by
set of creatures). In min-cost flow the requirements can be modeled 3-sets instance. There is a special attacker Tromokratis7 , which has,
as weights on edges5 . We focus on three requirements6 : together with some arbitrary creature b ∈ B, been targeted by Hunt
down |E| − 1 times (hence, blocking it with all creatures in B will
1. Generic attacker/blocker requirements. Generic attacker (resp. satisfy |E| − 1 requirements). Besides that the attackers will play
blocker) requirements are parameterised by an attacker a ∈ A the role of the sets of S and the blockers the elements of E. Each
(resp. blocker b ∈ B) and are satisfied if a is blocked (resp. if attacker a, besides the Tromokratis, is a Guile8 and will correspond
b blocks). Generic attacker (resp. blocker) requirements can be to a set (e1 , e2 , e3 ) ∈ S and Hunt Down has been cast on a and
modeled in min-cost flow by having two edges pointing to a from the blocker b1 corresponding to e1 (so that there is a specific require-
the source (resp. away from b to the sink), one with unbounded ca- ment between a and b1 ). Similarly for a and e2 and a and e3 . Hence,
pacity and 0 weight and another with capacity 1 and weight equal blocking a with the creatures corresponding to e1 , e2 and e3 will
to the number of times the creature is affected by the requirement. satisfy 3 requirements. Each blocker can block only 1 creature (as is
The requirement could for instance be caused by Irresistible Prey default) and each attacker can be blocked by any number of creatures
(resp. Culling Mark). (as is default). Blocking Tromokratis with all creatures is not legal
2. Special generic requirements are parametrised by an attacker iff there exists an exact cover by 3-sets.
a ∈ A and are satisfied if a is blocked by exactly one creature. Note that we are giving creatures to the goldfish player. This is some-
The requirement has no simple interpretation in min-cost flow, but times done even in real-life tournament Magic games, for instance it
any flow that has a flow of 1 through a satisfies the requirement. often happens that a player of the Oath of Druids deck will give crea-
The requirement is only in effect if a is a Nacatl War-Pride. tures to his opponent.
3. Specific requirements are parametrised by an attacker a ∈ A and Remark 2 How to make the setup in a concrete game of Magic:
blocker b ∈ B and are satisfied if b ∈ B a . Specific requirements This remark is meant for people familiar with the rules of Magic
could for instance be caused by Hunt Down. We can model k and we do not include illustrations of the cards used. Play Impe-
specific requirements between a ∈ A and b ∈ B by having a rious Perfect, Intruder Alarm, 2 Birds of Paradise (these first
weight of k on the edge from a to b in min-cost flow. cards gives an arbitrary amount of mana), Djinn Illuminatus,
Tromokratis, Concordant Crossroads, Vedalken Orrey, Fumiko
Remark 1 Finding the categories. Categorizing the requirements
the Lowblood and Guile. Djinn Illuminatus allows us to copy
and restrictions of all cards in Magic is a demanding task (because
spells an arbitrary number of times. On the opponents turn use Spit-
of the number of cards). To do so we made a case analysis with many
ting Image to create enough Guiles, Hunt Down to make the re-
thousands of cases. We do not explicitly include the very technical
quirements and Donate to give the attackers away (the cards can
case analysis, but only the outcome, because of the huge size of the
be played at that point because of Vedalken Orrey). Fumiko the
case analysis.
Lowblood and Concordant Crossroads makes the creatures attack,
without choice.
2.1 Complexity bound in general case Theorem 1 The complexity of a single step in a Magic game is
coNP-complete, and the hardness result holds even in the special
case of goldfish.
Inclusion in coNP. For a fixed declaration of blockers, it is easy to
check that all restrictions are satisfied. In case any restriction is not
satisfied, it is easy to find a declaration of blockers satisfying all (con- 2.2 Special cases with better complexities
cretely, not declaring any blockers always satisfies all restrictions). It
is also easy to count the number of requirements satisfied. Hence, In this section we consider several special cases, and show that they
the given declaration of blockers is legal precisely if no declaration have much better complexity. Note that the upper bounds we get in
can be found that satisfies more requirements while satisfying all re- this section is for any number of players because the declare blockers
strictions. Note that a declaration of blockers can be described as the step is turn-based.
sets B a for each a. This can be done in O(|A| · |B|) space, giving
a polynomial sized witness. Note that even in case of many players, Restriction 1: Neither local counting restrictions (except for
Tromokratis) nor Nacatl War-Pride. As argued above besides lo-
5 Except for the requirement caused by Nacatl War-Pride, which does not
have a simple interpretation in min-cost flow. 7 which must either be left unblocked or blocked by all
6 To our knowledge, all requirements fit into precisely one type 8 which must either be left unblocked or blocked by 3 or more creatures
cal and global counting restrictions and Nacatl War-Pride, every Theorem 2 The complexity of a single step in a Magic game with
requirement and restriction can be encoded in the standard min-cost any of the Restriction 1-3, no matter the number of players, can be
flow problem. We explain how to handle Tromokratis and global solved in polynomial time.
counting restrictions.
Also note that for Restriction 1-3 it follows from our results that the
• Handling Tromokratis. For any number k ≤ |A|, we can find the legality of a given move in a single step can be decided in the same
optimal solution such that precisely k Tromokratis are blocked, complexity as mentioned above.
because of the following: For each Tromokratis a ∈ A, the num-
ber of requirements satisfied by blocking a with all creatures in
B, is independent of how else the creatures in B block. There- 2.3 In depth analysis of Restriction 1
fore, we can sort the Tromokratis after how many requirements
are satisfied, block the first k with all creatures in B, and then We will, in this section, give a more in depth complexity analy-
solve the sub-problem where the set of attackers is A, except for sis, in case there are neither local counting restrictions (except for
the Tromokratis, and each creature in B can block k less crea- Tromokratis) nor Nacatl War-Pride (that is, of Restriction 1). To
tures. get a better complexity bound we consider the min-cost flow instance
• Handling global counting restrictions. We can handle global created in this case in Section 2.2. Observe that it has n = |A| + |B|
counting restrictions parametrised with k (even in the presence states. Also, there is an edge from a ∈ A to b ∈ B unless there is a lo-
of local counting restrictions) straightforwardly since k ∈ {1, 2} cal restriction between them. Hence, m = |A|·|B|−c, where c is the
(it is not clear if the problem is in polynomial time for k as a number of local restrictions between different pairs. Parametrising
parameter, but k is at most 2 for global counting restrictions in like this, Orlin’s strongly polynomial algorithm for minimum cost
Magic). That is, we simply guess the creatures in B A and then flow ([17]) runs in time O(m2 log n + mn log2 n).
solve the problem with only those creatures. We can, in the pres- We consider three cases:
ence of global counting restrictions also handle local counting re-
strictions easily. 1. If there is a global counting restriction of k (which is either 1
or 2), we can as explained in Section 2.2, consider each creature
For an in depth complexity analysis see Section 2.3, where we or pair of creatures in B in turn and solve the resulting instance
show the complexity is O(nm2 log n + mn2 log2 n + n2 log C) when B only consists of those creatures. This takes n2 times the
time, where, in our min-cost flow instance, n is the number of time for the case when B consists of two creatures.
states and m the number of edges (i.e. n = 2 + |A| + |B| and
m ≤ |A| + |B| + |A| · |B|), and C is the greatest weight on an edge Remark 3 Observe that if the case where |B| = 2 can be solved
(and thus C is at most the number of requirements). Hence, the prob- in O(n · f (n) + g(n)) time, where f (n) is a sum of terms, each
lem is in polynomial time if none of the 37 cards (of which 31 have of which is at least constant, then this case can be solved in time
or grants local counting restriction 2, i.e. Menace) that have or grants O(nm · f (n) + n2 g(n)). This is because the time for a pair of
a local counting restriction, besides Tromokratis, but also including states u, v is then O((du + dv ) · f (du + dv ) + g(du + dv )), where
Nacatl War-Pride, is in the game. None of these 37 cards, which is du and dv is the degree of u and v respectively. Hence,
less than 0.3% of the distinct Magic cards, are heavily used. Menace X
is a new ability that might be used in the future. O((du + dv ) · f (du + dv ) + g(du + dv ))
u,v
Restriction 2: Removing requirements. Another simple way to X
≤ O(n2 g(n)) + f (n) · O((du + dv ))
make the problem easier is to remove the cards that have or grants re- u,v
quirements. There are 63 cards, which is less than 0.5% of all distinct X
Magic cards, that causes requirements on blocking, none of which is = O(n2 g(n)) + f (n) · O(n · du + m)
u
used often. Note that only the card Nacatl War-Pride is in the 63
cards removed from this special case as well as the 37 cards removed = O(nmf (n) + n2 g(n))
in the above considered special case. A declaration of blockers is then
legal iff it satisfies all restrictions. For each type of restriction, as de- This shows that using Orlin’s method ([17]), this case would use
scribe above, it is easy to check in DL if the restriction is satisfied. O(m2 n2 log n + m2 n log2 n) = O(m2 n2 log n) time.
Hence, this special case is in DL ⊆ P. 2. If Tromokratis is not in the game and there are no global count-
ing restrictions, then it is easy to solve it in time O(m2 log n +
Restriction 3: Removing tokens. Another simple way is to remove
mn log2 n), since it is a standard flow problem.
all roughly 830 producers of tokens (i.e. creatures which are not
cards), which corresponds to less than 6.1% of all distinct Magic 3. Otherwise, if there is no global counting restrictions and
cards, some of which are used heavily. At this point, the number of Tromokratis is in play then we can guess the number ∆ of
creatures in play is bounded by the number of Magic cards in exis- Tromokratis each creature should block (observe that this is
tence and the problem can be solved by considering each possible bounded by the number of creatures in A), by simply trying all
declaration of blockers. Since the problem is bounded, it is trivial. options. We can then find the ∆ Tromokratis that, if blocked,
(We consider this restriction, since it is a reasonably obvious way to will give the most satisfied requirements, by sorting them af-
make the problem simpler – it does not lead to an efficient algorithm ter how many requirements will be satisfied (note that the num-
though). A variant of Restriction 3 is used in the online implemen- ber of satisfied requirements is independent of which other crea-
tation of Magic ([20]) where at most 200 tokens can be created per tures a creature block, and thus doing it greedily will find the
player (after which no more tokens appear when one tries to make best set). We can then reduce the capacity of each blocker by ∆,
any). remove the Tromokratis and solve the resulting instance in
O(m2 log n + mn log n) using Orlin’s algorithm ([17]). This re- [13] M. R. Garey and D. S. Johnson. Computers and Intractability;
quires O(nm2 log n + mn2 log2 n) time. A Guide to the Theory of NP-Completeness. W. H. Freeman &
Co., New York, NY, USA, 1990.
Observe that the worst case time, if we use Orlin’s algorithm ([17]) [14] R. A. Hearn and E. D. Demaine. Games, Puzzles, and Compu-
in the first case, will be the time for the first step. That said, there tation. A. K. Peters, Ltd., Natick, MA, USA, 2009.
exists specialized algorithms for this case, where one side is of con- [15] S. Iwata and T. Kasai. The Othello game on an n x n board is
stant size, see [1], using time O(n + log C) where C is the great- PSPACE-complete. Theoretical Computer Science, 123(2):329
est weight. Specifically, C is in this case the maximum number of – 340, 1994.
times any single state (resp. pair of states) are effect by a generic [16] D. Lucking-Reiley. Using Field Experiments to Test Equiva-
(resp. specific) requirement. This will ensure that the time for case 1 lence between Auction Formats: Magic on the Internet. The
is then O(nm + n2 log C) and the total time is O(nm2 log n + American Economic Review, 89(5):pp. 1063–1080, 1999.
mn2 log2 n + n2 log C). [17] J. Orlin. A Faster Strongly Polynomial Minimum Cost Flow
Algorithm. In STOC ’88, pages 377–387, 1988.
[18] J. M. Robson. N by N Checkers is Exptime Complete. SIAM
3 Conclusion Journal on Computing, 13(2):252–267, 1984.
[19] Wizards of the Coast. Magic: the Gathering Comprehensive
In this work we establish the complexity of deciding the legality of a Rules. http://tinyurl.com/qf6hlx4, 2015.
move in a single step of Magic. In sharp contrast to existing real-life [20] Wizards of the Coast. Magic: the Gathering Online.
games, where legality of a move in single step is trivial, we estab- http://tinyurl.com/h95z67n, 2016.
lish coNP-completeness for legality of a move in a single-step of
a single-player variant of Magic, which is quite unique and should
be of wide interest. Moreover, our result is established by showing a
close connection with a generalization of the min-cost-flow problem,
which is also of independent and general interest. While we show that
in general the legality of a move in a single-step is coNP-complete,
we present efficient algorithms for special cases which are different
from existing tools but these special cases are widely used. Hence
our algorithms are also practically relevant for automated tools to
analyzed important special cases in Magic.
References
[1] R. K. Ahuja, J. B. Orlin, and C. Stein. Improved Algorithms
for Bipartite Network Flow. SIAM J. Comput., 23(5):906–933,
1994.
[2] E. Bonnet, F. Jamain, and A. Saffidine. On the Complexity of
Trick-Taking Card Games. In IJCAI 2013, 2013.
[3] R. A. Bosch. Optimal Card-Collecting Strategies for Magic:
The Gathering. The College Mathematics Journal, 31(1):pp.
15–21, 2000.
[4] M. Buro and A. Kovarsky. Concurrent Action Execution with
Shared Fluents. In AAAI 2007, pages 950–955, 2007.
[5] A. Churchill. Magic: the Gathering is Turing Complete.
http://tinyurl.com/olg28d5, 2012.
[6] A. Churchill et. al. Magic: the Gathering is Turing Complete
(forum page 1). http://tinyurl.com/pv3n2lg, 2012.
[7] A. Churchill et. al. Magic: the Gathering is Turing Complete
(forum page 2). http://tinyurl.com/naq9jmc, 2012.
[8] A. Churchill et. al. Magic: the Gathering is Turing Complete
(forum page 3). http://tinyurl.com/ow7obh6, 2014.
[9] T. H. Cormen, C. Stein, R. L. Rivest, and C. E. Leiserson. In-
troduction to Algorithms. McGraw-Hill Higher Education, 2nd
edition, 2001.
[10] E. D. Demaine, M. L. Demaine, and D. Eppstein. Phutball
Endgames are Hard. CoRR, cs.CC/0008025, 2000.
[11] I. Frank and D. A. Basin. A theoretical and empirical investiga-
tion of search in imperfect information games. Theor. Comput.
Sci., 252(1-2):217–256, 2001.
[12] T. Furtak and M. Buro. On the Complexity of Two-Player At-
trition Games Played on Graphs. In AIIDE 2010, 2010.