コード例 #1
0
    def test_TapUntapExpressions(self):
        t_creature = MgType(MgType.TypeEnum.Creature)
        typeexpr = MgTypeExpression(t_creature)
        targetExpr = MgTargetExpression(typeexpr)

        tapExpr = MgTapUntapExpression(targetExpr, tap=True, untap=False)

        self.assertTrue(tapExpr.isTraversable())
        self.assertEqual(len(tapExpr.getTraversalSuccessors()), 1)
        self.assertTrue(tapExpr.isChild(targetExpr))
        self.assertEqual(targetExpr.getParent(), tapExpr)

        self.assertTrue(tapExpr.isTap())
        self.assertFalse(tapExpr.isUntap())
        self.assertEqual(tapExpr.unparseToString().lower(),
                         "tap target creature")

        tapExpr.setTap(False)
        tapExpr.setUntap(True)
        self.assertFalse(tapExpr.isTap())
        self.assertTrue(tapExpr.isUntap())
        self.assertEqual(tapExpr.unparseToString().lower(),
                         "untap target creature")

        tapExpr.setTap(True)
        self.assertEqual(tapExpr.unparseToString().lower(),
                         "tap or untap target creature")
コード例 #2
0
 def test_TargetExpressions(self):
         t_artifact = MgType(MgType.TypeEnum.Artifact)
         t_creature = MgType(MgType.TypeEnum.Creature)
         typeexpr = MgTypeExpression(t_artifact,t_creature)
         
         targetExpr = MgTargetExpression(typeexpr)
         
         self.assertEqual(targetExpr.unparseToString().lower(),"target artifact creature")
コード例 #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_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)
コード例 #6
0
    def test_UncastExpressions(self):

        t_nonenchantment = MgTypeExpression(
            MgNonExpression(MgType(MgType.TypeEnum.Enchantment)))
        q_spell = MgQualifier(MgQualifier.QualifierEnum.Spell)
        description = MgDescriptionExpression(t_nonenchantment, q_spell)
        targetExpr = MgTargetExpression(description)

        uncastExpr = MgUncastExpression(targetExpr)

        self.assertTrue(uncastExpr.isTraversable())
        self.assertEqual(len(uncastExpr.getTraversalSuccessors()), 1)
        self.assertTrue(uncastExpr.isChild(targetExpr))
        self.assertEqual(targetExpr.getParent(), uncastExpr)

        self.assertEqual(uncastExpr.unparseToString().lower(),
                         "counter target non-enchantment spell")
コード例 #7
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)
コード例 #8
0
    def test_DealsDamageExpressions(self):
        nameref = MgNameReference(None)
        one = MgNumberValue(1, MgNumberValue.NumberTypeEnum.Literal)
        any_target = MgTargetExpression(isAny=True)

        damageexpr_0 = MgDealsDamageExpression(origin=nameref,
                                               damageExpression=one,
                                               subject=any_target)

        self.assertTrue(damageexpr_0.isTraversable())
        self.assertEqual(len(damageexpr_0.getTraversalSuccessors()), 3)
        self.assertTrue(damageexpr_0.isChild(any_target))
        self.assertEqual(any_target.getParent(), damageexpr_0)

        self.assertEqual(damageexpr_0.getOrigin(), nameref)
        self.assertTrue(damageexpr_0.hasDamageExpression())
        self.assertEqual(damageexpr_0.getDamageExpression(), one)
        self.assertTrue(damageexpr_0.hasSubject())
        self.assertEqual(damageexpr_0.getSubject(), any_target)

        self.assertEqual(damageexpr_0.unparseToString().lower(),
                         "~ deals 1 damage to any target")
コード例 #9
0
 def test_selfReferences(self):
         creature_description = MgDescriptionExpression(MgTypeExpression(MgType(MgType.TypeEnum.Creature)))
         targetExpr = MgTargetExpression(creature_description)
         
         selfref = MgSelfReference(reftype=MgSelfReference.SelfEnum.Neutral,antecedent=creature_description)
         
         self.assertTrue(selfref.isTraversable())
         self.assertEqual(len(selfref.getTraversalSuccessors()),0)
         self.assertTrue(selfref.hasAntecedent())
         selfref.setAntecedent(creature_description)
         self.assertEqual(selfref.getAntecedent(),creature_description)
         self.assertTrue(selfref.isNeutral())
         self.assertEqual(selfref.unparseToString().lower(),"itself")
         
         selfref.setNeutral()
         selfref.setMale()
         self.assertTrue(selfref.isMale())
         self.assertEqual(selfref.unparseToString().lower(),"himself")
         
         selfref.setFemale()
         self.assertTrue(selfref.isFemale())
         self.assertEqual(selfref.unparseToString().lower(),"herself")
コード例 #10
0
 def test_thatReferences(self):
         color_white = MgColorExpression(MgColorTerm(MgColorTerm.ColorTermEnum.White))
         t_enchantment = MgTypeExpression(MgType(MgType.TypeEnum.Enchantment))
         original_enchantment_description = MgDescriptionExpression(color_white,t_enchantment)
         targetExpr = MgTargetExpression(original_enchantment_description)
         
         
         descriptor_enchantment = MgDescriptionExpression(MgTypeExpression(MgType(MgType.TypeEnum.Enchantment)))
         thatref_enchantment = MgThatReference(descriptor=descriptor_enchantment,antecedent=original_enchantment_description)
         
         self.assertTrue(thatref_enchantment.isTraversable())
         self.assertEqual(len(thatref_enchantment.getTraversalSuccessors()),1)
         self.assertTrue(thatref_enchantment.isChild(descriptor_enchantment))
         self.assertEqual(descriptor_enchantment.getParent(),thatref_enchantment)
         self.assertEqual(thatref_enchantment.getDescriptor(),descriptor_enchantment)
         
         self.assertTrue(thatref_enchantment.hasAntecedent())
         self.assertEqual(thatref_enchantment.getAntecedent(),original_enchantment_description)
         thatref_enchantment.setAntecedent(original_enchantment_description)
         
         
         self.assertEqual(thatref_enchantment.getAntecedent(),original_enchantment_description)
         self.assertEqual(thatref_enchantment.unparseToString().lower(),"that enchantment")