def test_Protection(self): #Protection from Red red = MgColorExpression(MgColorTerm(MgColorTerm.ColorTermEnum.Red)) pro_red = MgProtectionAbility(red) self.assertTrue(pro_red.isTraversable()) self.assertEqual(len(pro_red.getTraversalSuccessors()), 1) self.assertTrue(pro_red.isChild(red)) self.assertEqual(red.getParent(), pro_red) self.assertEqual(pro_red.unparseToString().lower(), "protection from red") #Protection from instant spell[s] and from sorcery spell[s] #Note that the default unparsing routine does not do pluralization, #though it's expected of a dedicated unparser. instant_spells = MgDescriptionExpression( MgTypeExpression(MgType(MgType.TypeEnum.Instant)), MgQualifier(MgQualifier.QualifierEnum.Spell)) sorcery_spells = MgDescriptionExpression( MgTypeExpression(MgType(MgType.TypeEnum.Sorcery)), MgQualifier(MgQualifier.QualifierEnum.Spell)) pro_instantAndSorcery = MgProtectionAbility(instant_spells, sorcery_spells) self.assertEqual(len(pro_instantAndSorcery.getTraversalSuccessors()), 2) self.assertTrue(pro_instantAndSorcery.isChild(instant_spells)) self.assertEqual(instant_spells.getParent(), pro_instantAndSorcery) self.assertEqual( pro_instantAndSorcery.unparseToString().lower(), "protection from instant spell and from sorcery spell")
def test_CreateTokenExpressions(self): saproling_description = MgDescriptionExpression( #1/1 MgPTExpression( MgNumberValue(1, MgNumberValue.NumberTypeEnum.Literal), MgNumberValue(1, MgNumberValue.NumberTypeEnum.Literal)), #green MgColorExpression(MgColorTerm(MgColorTerm.ColorTermEnum.Green)), #saproling creature MgTypeExpression( MgSubtype(MgSubtype.CreatureSubtypeEnum.Saproling), MgType(MgType.TypeEnum.Creature)), #token MgQualifier(MgQualifier.QualifierEnum.Token)) three_of_them = MgNumberValue(3, MgNumberValue.NumberTypeEnum.Quantity) create_three_saprolings = MgCreateTokenExpression( descriptor=saproling_description, quantity=three_of_them) self.assertTrue(create_three_saprolings.isTraversable()) self.assertEqual(len(create_three_saprolings.getTraversalSuccessors()), 2) self.assertTrue(create_three_saprolings.isChild(saproling_description)) self.assertEqual(saproling_description.getParent(), create_three_saprolings) self.assertTrue(create_three_saprolings.isChild(three_of_them)) self.assertEqual(three_of_them.getParent(), create_three_saprolings) self.assertEqual(create_three_saprolings.unparseToString().lower(), "create three 1/1 green saproling creature token")
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)
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)
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 })
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")
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")
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")
def test_modifiers(self): triggered = MgAbilityModifier(MgAbilityModifier.AbilityModifierEnum.Triggered) ability = MgQualifier(MgQualifier.QualifierEnum.Ability) triggered_ability = MgDescriptionExpression(triggered,ability) self.assertTrue(triggered.isTraversable()) self.assertEqual(len(triggered.getTraversalSuccessors()),0) self.assertEqual(triggered.getModifier(),MgAbilityModifier.AbilityModifierEnum.Triggered) self.assertEqual(triggered_ability.unparseToString().lower(),"triggered ability") blocking = MgCombatStatusModifier(MgCombatStatusModifier.CombatStatusEnum.Blocking) creature = MgTypeExpression(MgType(MgType.TypeEnum.Creature)) blocking_creature = MgDescriptionExpression(blocking,creature) self.assertEqual(blocking_creature.unparseToString().lower(),"blocking creature") enchanted = MgKeywordStatusModifier(MgKeywordStatusModifier.KeywordStatusEnum.Enchanted) permanent = MgQualifier(MgQualifier.QualifierEnum.Permanent) enchanted_permanent = MgDescriptionExpression(enchanted,permanent) self.assertEqual(enchanted_permanent.unparseToString().lower(),"enchanted permanent") tapped = MgTapStatusModifier(MgTapStatusModifier.TapStatusEnum.Tapped) artifact = MgTypeExpression(MgType(MgType.TypeEnum.Artifact)) tapped_artifact = MgDescriptionExpression(tapped,artifact) self.assertEqual(tapped_artifact.unparseToString().lower(),"tapped artifact") chosen = MgEffectStatusModifier(MgEffectStatusModifier.EffectStatusEnum.Chosen) token = MgQualifier(MgQualifier.QualifierEnum.Token) tapped_artifact = MgDescriptionExpression(chosen,token) self.assertEqual(tapped_artifact.unparseToString().lower(),"chosen token")