コード例 #1
0
    def test_JumpStart(self):
        threegeneric = MgManaExpression(
            MgManaSymbol(colorv=None, modifiers=None, cvalue=3))
        ability = MgJumpStartAbility(cost=threegeneric)

        self.assertTrue(ability.isTraversable())
        self.assertEqual(len(ability.getTraversalSuccessors()), 1)
        self.assertTrue(ability.isChild(threegeneric))
        self.assertEqual(threegeneric.getParent(), ability)
        self.assertEqual(ability.getCost(), threegeneric)
        self.assertEqual(ability.unparseToString().lower(), "jump-start {3}")
コード例 #2
0
    def test_Morph(self):
        threegeneric = MgManaExpression(
            MgManaSymbol(colorv=None, modifiers=None, cvalue=3))
        ability = MgMorphAbility(cost=threegeneric)

        self.assertTrue(ability.isTraversable())
        self.assertEqual(len(ability.getTraversalSuccessors()), 1)
        self.assertTrue(ability.isChild(threegeneric))
        self.assertEqual(threegeneric.getParent(), ability)
        self.assertEqual(ability.getCost(), threegeneric)
        self.assertEqual(ability.unparseToString().lower(), "morph {3}")

        self.assertFalse(ability.isMegamorphAbility())
        ability.setIsMegamorphAbility(True)
        self.assertEqual(ability.unparseToString().lower(), "megamorph {3}")
コード例 #3
0
 def test_BanisherPriest(self):
         #Card name: Banisher Priest
         cardName = MgName("Banisher Priest")
         
         #Mana cost: 1WW.
         s0 = MgManaSymbol(cvalue=1)
         s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White)
         s2 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White)
         manaExpr = MgManaExpression(s0,s1,s2)
         
         #Creature - Human Cleric
         t_creature = MgTypeExpression(MgType(MgType.TypeEnum.Creature))
         t_human = MgTypeExpression(MgType(MgType.SubtypeEnum.Human))
         t_cleric = MgTypeExpression(MgType(MgType.SubtypeEnum.Cleric))
         typeLine = MgTypeLine(types=MgTypeLine(t_creature),subtypes=MgTypeLine(t_human,t_cleric))
         
         
         #exile target creature an opponent controls
         exileEffect = MgExileEffectExpression(
                 subject = MgTargetExpression(MgDescriptionExpression(
                         MgTypeExpression(MgType(MgType.TypeEnum.Creature)),
                         MgControlExpression("an opponent")))                        
         )
         
         #[...] until Banisher Priest leaves the battlefield.
         untilCondition = MgUntilExpression(MgEntersLeavesBattlefieldExpression(MgNameReference(),entering=False))
         
         #when Banisher Priest enters the battlefield, [...]
         entersTheBattlefield = MgEntersLeavesBattlefieldExpression(MgNameReference,entering=True)
コード例 #4
0
 def test_DoomBlade(self):
         
         #Card name: Doom Blade.
         cardName = MgName("Doom Blade")
         
         #Mana cost: 1B.
         s0 = MgManaSymbol(cvalue=1)
         s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Black)
         manaExpr = MgManaExpression(s0,s1)
         
         #Instant.
         t_instant = MgTypeExpression(MgType(MgType.TypeEnum.Instant))
         typeLine = MgTypeLine(types=t_instant)
         
         #Destroy target non-black creature.
         c_nonblack = MgColorExpression(MgNonExpression(MgColorTerm(MgColorTerm.ColorTermEnum.Black)))
         t_creature = MgTypeExpression(MgType(MgType.TypeEnum.Creature)) 
         description = MgDescriptionExpression(c_nonblack,t_creature)
         targetExpr = MgTargetExpression(description)
         destroyExpr = MgDestroyExpression(targetExpr)
         instructions = MgStatementSequence(MgStatement(destroyExpr))
         ability = MgSpellAbility(instructions)
         textBox = MgTextBox(ability)
         
         #The card, all put together
         card = MgCard(**{
                 "name" : cardName,
                 "manaCost" : manaExpr,
                 "typeLine" : typeLine,
                 "textBox" : textBox
         })
コード例 #5
0
    def test_Equip(self):
        manaExpr = MgManaExpression(MgManaSymbol(cvalue=4))
        ability = MgEquipAbility(cost=manaExpr)

        self.assertTrue(ability.isTraversable())
        self.assertEqual(len(ability.getTraversalSuccessors()), 1)
        self.assertTrue(ability.isChild(manaExpr))
        self.assertEqual(manaExpr.getParent(), ability)
        self.assertEqual(ability.unparseToString().lower(), "equip {4}")

        t_planetouched = MgTypeExpression(MgSupertype("Planetouched"))
        equip_planetouched = MgEquipAbility(cost=manaExpr,
                                            quality=t_planetouched)
        self.assertEqual(len(equip_planetouched.getTraversalSuccessors()), 2)
        self.assertEqual(equip_planetouched.unparseToString().lower(),
                         "equip planetouched {4}")
コード例 #6
0
    def test_Forecast(self):
        return None  #TODO
        manaCost = MgManaExpression(
            MgManaSymbol(cvalue=1),
            MgManaSymbol(colorv=MgManaSymbol.ManaType.White))

        tap_creature = MgStatementSequence(
            MgStatement(
                MgTapUntapExpression(MgTargetExpression(
                    MgTypeExpression(MgType(MgType.TypeEnum.Creature))),
                                     tap=True)))

        activatedAbility = MgActivatedAbility(
            cost=None,
            instructions=tap_creature,
            abilityWord=None,  #Forecast is in fact *not* an ability word.
            reminderText=
            None  #The reminder text is attached to Forecast, not the underlying ability.
        )
        reminder = MgReminderText(
            "Activate this ability only during your upkeep and only once each turn."
        )

        forecast = MgForecastAbility(activatedAbility=activatedAbility,
                                     reminderText=reminder)
コード例 #7
0
    def test_Splice(self):
        t_arcane = MgTypeExpression(
            MgSubtype(MgSubtype.SpellSubtypeEnum.Arcane))
        s0 = MgManaSymbol(cvalue=1)
        s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White)
        s2 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White)
        manaExpr = MgManaExpression(s0, s1, s2)

        ability = MgSpliceAbility(cost=manaExpr, spliceType=t_arcane)

        self.assertTrue(ability.isTraversable())
        self.assertEqual(len(ability.getTraversalSuccessors()), 2)
        self.assertTrue(ability.isChild(t_arcane))
        self.assertEqual(manaExpr.getParent(), ability)
        self.assertEqual(ability.getCost(), manaExpr)
        self.assertEqual(ability.unparseToString().lower(),
                         "splice onto arcane {1}{w}{w}")
コード例 #8
0
 def test_CrypticCommand(self):
         #Card name: Cryptic Command
         cardName = MgName("Cryptic Command")
         
         #Mana cost: 1UUU.
         s0 = MgManaSymbol(cvalue=1)
         s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Blue)
         s2 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Blue)
         s3 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Blue)
         manaExpr = MgManaExpression(s0,s1,s2,s3)
         
         #Instant.
         t_instant = MgTypeExpression(MgType(MgType.TypeEnum.Instant))
         typeLine = MgTypeLine(types=t_instant)
         
         #counter target spell
         choice_counterspell = MgStatementSequence(MgStatement(MgUncastExpression(MgTargetExpression(MgDescriptionExpression(
                 MgQualifier(MgQualifier.QualifierEnum.Spell)
         )))))
         
         #Return target permanent to its owner's hand.
         choice_bounce = MgStatementSequence(MgStatement(MgReturnExpression(
                 subject = MgTargetExpression(MgDescriptionExpression(MgQualifier(MgQualifier.QualifierEnum.Permanent))),
                 destination = MgPossessiveExpression(possessive=MgPossessiveExpression.PossessiveEnum.Owner,owned=MgZone(MgZone.ZoneEnum.Hand))
         )))
         
         #Tap all creatures your opponents control.
         choice_tap = MgStatementSequence(MgStatement(MgTapUntapExpression(
                 MgAllExpression(MgDescriptionExpression(MgTypeExpression(MgType(MgType.TypeEnum.Creature)),MgControlExpression("your opponents")))
                 ,tap=True
         )))
         
         #Draw a card.
         choice_draw = MgStatementSequence(MgStatement(MgCardDrawExpression(MgNumberValue(value=1,ntype=MgNumberValue.NumberTypeEnum.Quantity))))
         
         #Choose two
         modalExpr = MgModalExpression(
                 MgNumberValue(value=2,ntype=MgNumberValue.NumberTypeEnum.Quantity),
                 choice_counterspell,choice_bounce,choice_tap,choice_draw
         )
         
         instructions = MgStatementSequence(MgStatement(modalExpr,periodTerminated=False))
         ability = MgSpellAbility(instructions)
         textBox = MgTextBox(ability)
         
         card = MgCard(**{
                 "name" : cardName,
                 "manaCost" : manaExpr,
                 "typeLine" : typeLine,
                 "textBox" : textBox
         })
         
         print(card.unparseToString().lower())
         visitor = SimpleGraphingVisitor()
         visitor.traverse(card)
コード例 #9
0
 def test_ManaExpressions(self):
         s0 = MgManaSymbol(cvalue=1)
         s1 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Red)
         s2 = MgManaSymbol(colorv=MgManaSymbol.ManaType.Green)
         s3 = MgManaSymbol(colorv=MgManaSymbol.ManaType.White)
         mexpr = MgManaExpression(s0,s1,s2,s3)
         
         self.assertTrue(mexpr.isTraversable())
         self.assertEqual(len(mexpr.getTraversalSuccessors()),4)
         
         self.assertTrue(mexpr.isChild(s0))
         self.assertEqual(s0.getParent(),mexpr)
         
         self.assertEqual(mexpr.unparseToString(),"{1}{R}{G}{W}")
コード例 #10
0
ファイル: card.py プロジェクト: rmmilewi/mtgcompiler
    def __init__(self, **kwargs):
        """kwargs: A keyword argument dictionary, because there are so many damn fields in this card,
                most of which are optional."""

        if "name" in kwargs:
            self._name = kwargs["name"]
            if self._name is not None:
                self._name.setParent(self)
        else:
            self._name = MgName()
            self._name.setParent(self)

        if "manaCost" in kwargs:
            self._manaCost = kwargs["manaCost"]
            if self._manaCost is not None:
                self._manaCost.setParent(self)
        else:
            self._manaCost = MgManaExpression()
            self._manaCost.setParent(self)

        if "colorIndicator" in kwargs:
            self._colorIndicator = kwargs["colorIndicator"]
            if self._colorIndicator is not None:
                self._colorIndicator.setParent(self)
        else:
            self._colorIndicator = None

        if "typeLine" in kwargs:
            self._typeLine = kwargs["typeLine"]
            if self._typeLine is not None:
                self._typeLine.setParent(self)
        else:
            self._typeLine = MgTypeLine()

        if "loyalty" in kwargs:
            self._loyalty = kwargs["loyalty"]
            if self._loyalty is not None:
                self._loyalty.setParent(self)
        else:
            self._loyalty = None

        #TODO: The expansion symbol is going into some kind of 'card details' data structure,
        #along with info like artist name.
        if "expansionSymbol" in kwargs:
            self._expansionSymbol = kwargs["expansionSymbol"]
        else:
            self._expansionSymbol = None

        if "textBox" in kwargs:
            self._textBox = kwargs["textBox"]
            if self._textBox is not None:
                self._textBox.setParent(self)
        else:
            self._textBox = MgTextBox()
            self._textBox.setParent(self)

        if "powerToughness" in kwargs:
            self._powerToughness = kwargs["powerToughness"]
            if self._powerToughness is not None:
                self._powerToughness.setParent(self)
        else:
            self._powerToughness = None

        if "handModifier" in kwargs:
            self._handModifier = kwargs["handModifier"]
            if self._handModifier is not None:
                self._handModifier.setParent(self)
        else:
            self._handModifier = None

        if "lifeModifier" in kwargs:
            self._lifeModifier = kwargs["lifeModifier"]
            if self._lifeModifier is not None:
                self._lifeModifier.setParent(self)
        else:
            self._lifeModifier = None

        if "flavor" in kwargs:
            self._flavor = kwargs["flavor"]
            if self._flavor is not None:
                self._flavor.setParent(self)
        else:
            self._flavor = None
コード例 #11
0
ファイル: card.py プロジェクト: rmmilewi/mtgcompiler
class MgCard(core.MgNode):
    """This node represents a Magic card. When a card is parsed,
        one of these objects is produced. It contains features for
        interacting with all aspects of a Magic card. 
        
        From the rules... The parts of a card are name, mana cost, illustration, 
        color indicator, type line, expansion symbol, text box, power and toughness, loyalty, 
        hand modifier, life modifier, illustration credit, legal text, and collector number. 
        Some cards may have more than one of any or all of these parts.
        """
    def __init__(self, **kwargs):
        """kwargs: A keyword argument dictionary, because there are so many damn fields in this card,
                most of which are optional."""

        if "name" in kwargs:
            self._name = kwargs["name"]
            if self._name is not None:
                self._name.setParent(self)
        else:
            self._name = MgName()
            self._name.setParent(self)

        if "manaCost" in kwargs:
            self._manaCost = kwargs["manaCost"]
            if self._manaCost is not None:
                self._manaCost.setParent(self)
        else:
            self._manaCost = MgManaExpression()
            self._manaCost.setParent(self)

        if "colorIndicator" in kwargs:
            self._colorIndicator = kwargs["colorIndicator"]
            if self._colorIndicator is not None:
                self._colorIndicator.setParent(self)
        else:
            self._colorIndicator = None

        if "typeLine" in kwargs:
            self._typeLine = kwargs["typeLine"]
            if self._typeLine is not None:
                self._typeLine.setParent(self)
        else:
            self._typeLine = MgTypeLine()

        if "loyalty" in kwargs:
            self._loyalty = kwargs["loyalty"]
            if self._loyalty is not None:
                self._loyalty.setParent(self)
        else:
            self._loyalty = None

        #TODO: The expansion symbol is going into some kind of 'card details' data structure,
        #along with info like artist name.
        if "expansionSymbol" in kwargs:
            self._expansionSymbol = kwargs["expansionSymbol"]
        else:
            self._expansionSymbol = None

        if "textBox" in kwargs:
            self._textBox = kwargs["textBox"]
            if self._textBox is not None:
                self._textBox.setParent(self)
        else:
            self._textBox = MgTextBox()
            self._textBox.setParent(self)

        if "powerToughness" in kwargs:
            self._powerToughness = kwargs["powerToughness"]
            if self._powerToughness is not None:
                self._powerToughness.setParent(self)
        else:
            self._powerToughness = None

        if "handModifier" in kwargs:
            self._handModifier = kwargs["handModifier"]
            if self._handModifier is not None:
                self._handModifier.setParent(self)
        else:
            self._handModifier = None

        if "lifeModifier" in kwargs:
            self._lifeModifier = kwargs["lifeModifier"]
            if self._lifeModifier is not None:
                self._lifeModifier.setParent(self)
        else:
            self._lifeModifier = None

        if "flavor" in kwargs:
            self._flavor = kwargs["flavor"]
            if self._flavor is not None:
                self._flavor.setParent(self)
        else:
            self._flavor = None

    def getName(self):
        return self._name

    def hasName(self):
        return self._name is not None

    def setName(self, name):
        self._name = name
        self._name.setParent(self)

    def getManaCost(self):
        return self._manaCost

    def hasManaCost(self):
        return self._manaCost is not None

    def setManaCost(self, manaCost):
        self._manaCost = manaCost
        self._manaCost.setParent(self)

    def getColorIndicator(self):
        return self._colorIndicator

    def hasColorIndicator(self):
        return self._colorIndicator is not None

    def setColorIndicator(self, colorIndicator):
        self._colorIndicator = colorIndicator

    def getTypeLine(self):
        return self._typeLine

    def hasTypeLine(self):
        return self._typeLine is not None

    def setTypeLine(self):
        return self._typeLine
        self._typeline.setParent(self)

    def getLoyalty(self):
        return self._loyalty

    def hasLoyalty(self):
        return self._loyalty is not None

    def setLoyalty(self, loyalty):
        self._loyalty = loyalty
        self._loyalty.setParent(self)

    def getExpansionSymbol(self):
        return self._expansionSymbol

    def hasExpansionSymbol(self):
        return self._expansionSymbol is not None

    def setExpansionSymbol(self, expansionSymbol):
        self._expansionSymbol = expansionSymbol

    def getTextBox(self):
        return self._textBox

    def hasTextBox(self):
        return self._textBox is not None

    def setTextBox(self, textBox):
        self._textBox = textBox
        self._textBox.setParent(self)

    def getPowerToughness(self):
        return self._powerToughness

    def hasPowerToughness(self):
        return self._powerToughness is not None

    def setPowerToughness(self, powerToughness):
        self._powerToughness = powerToughness
        self._powerToughness.setParent(self)

    def getHandModifier(self):
        """Note: This only matters for Vanguard cards."""
        return self._handModifier

    def hasHandModifier(self):
        """Note: This only matters for Vanguard cards."""
        return self._handModifier is not None

    def setHandModifier(self, handModifier):
        """Note: This only matters for Vanguard cards."""
        self._handModifier = handModifier
        self._handModifier.setParent(self)

    def getLifeModifier(self):
        """Note: This only matters for Vanguard cards."""
        return self._lifeModifier

    def hasLifeModifier(self):
        """Note: This only matters for Vanguard cards."""
        return self._lifeModifier is not None

    def setLifeModifier(self, lifeModifier):
        """Note: This only matters for Vanguard cards."""
        self._lifeModifier = lifeModifier
        self._lifeModifier.setParent(self)

    def getFlavor(self):
        return self._flavor

    def hasFlavor(self):
        return self._flavor is not None

    def setFlavor(self, flavor):
        self._flavor = flavor
        self._flavor.setParent(self)

    def isChild(self, child):
        return child in {
            self._name, self._manaCost, self._colorIndicator, self._typeLine,
            self._loyalty, self._expansionSymbol, self._textBox,
            self._powerToughness, self._handModifier, self._lifeModifier
        }

    def getTraversalSuccessors(self):
        return [
            ts for ts in {
                self._name, self._manaCost, self._colorIndicator, self.
                _typeLine, self._loyalty, self._expansionSymbol, self._textBox,
                self._powerToughness, self._handModifier, self._lifeModifier
            } if ts is not None and ts.isTraversable()
        ]

    def unparseToString(self):
        output = ""
        if self._name is not None:
            output += "{0}".format(self._name.unparseToString())
        if self._manaCost is not None:
            output += " {0}\n".format(self._manaCost.unparseToString())
        else:
            output += "\n"
        if self._colorIndicator is not None:
            output += "Color Indicator: {0}\n".format(self._colorIndicator)
        if self._typeLine is not None:
            output += "{0}".format(self._typeLine.unparseToString())
        if self._expansionSymbol is not None:
            output += "     {0}\n".format(self._typeline.unparseToString())
        else:
            output += "\n"
        if self._textBox is not None:
            output += "{0}\n".format(self._textBox.unparseToString())
        if self._loyalty is not None:
            output += "{0}\n".format(self._loyalty.unparseToString())
        if self._powerToughness is not None:
            output += "{0}\n".format(self._powerToughness.unparseToString())
        if self._handModifier is not None:
            output += "{0}\n".format(self._lifeModifier.unparseToString())
        if self._lifeModifier is not None:
            output += "{0}\n".format(self._lifeModifier.unparseToString())
        return output