# Path: MTG/gameobject.py
# class Characteristics():
# class GameObject():
#     def __init__(self,
#                  name='',
#                  mana_cost='',
#                  color=[],
#                  types=[],
#                  subtype=[],
#                  supertype=[],
#                  text='',
#                  abilities=[],
#                  power=None,
#                  toughness=None,
#                  loyalty=None):
#     def __repr__(self):
#     def satisfy(self, criteria):
#     def __init__(self, characteristics=None,
#                  controller=None, owner=None, zone=None, 
#                  previousState=None):
#     def __repr__(self):
#     def __str__(self):
#     def __eq__(x, y):
#     def __hash__(self):
#     def owner(self):
#     def game(self):
#     def is_permanent(self):
#     def is_spell(self):
#     def name(self):
#     def raw_manacost(self):
#     def manacost(self):
#     def is_land(self):
#     def is_basic_land(self):
#     def is_creature(self):
#     def is_instant(self):
#     def is_sorcery(self):
#     def is_artifact(self):
#     def is_enchantment(self):
#     def is_aura(self):
#     def is_equipment(self):
#     def power(self):
#     def toughness(self):
#     def has_ability(self, ability):
#     def share_color(self, other):
#     def has_color(self, color):
#     def is_color(self, color):
#     def is_monocolored(self):
#     def is_multicolored(self):
#     def is_colorless(self):
#     def has_subtype(self, subtype):
#     def exile(self):
#     def targets(self):
#     def target_legality(self):
#     def has_valid_target(self):
#     def choose_targets(self):
#     def change_zone(self, target_zone, from_top=0, shuffle=True,
#                     status_mod=None, modi_func=None):
# 
# Path: MTG/zone.py
# class ZoneType(Enum):
# class Zone():
# class Battlefield(Zone):
# class Stack(Zone):
# class Hand(Zone):
# class Graveyard(Zone):
# class Exile(Zone):
# class Library(Zone):
#     LIBRARY = 0
#     HAND = 1
#     BATTLEFIELD = 2
#     GRAVEYARD = 3
#     STACK = 4
#     EXILE = 5
# def str_to_zone_type(z):
#     def __init__(self, controller=None, elements: list=None):
#     def __repr__(self):
#     def __str__(self):
#     def __len__(self):
#     def __bool__(self):
#     def __getitem__(self, pos):
#     def isEmpty(self):
#     def add(self, obj):
#     def remove(self, obj):
#     def filter(self, characteristics=None, filter_func=None):
#     def count(self, characteristics=None, filter_func=None):
#     def get_card_by_name(self, name):
#     def pop(self, pos=-1):
#     def clear(self):
#     def add(self, obj, status_mod=None, modi_func=None):
#     def shuffle(self):
#     def __init__(self, controller=None, elements: list=None):
#     def add(self, obj, from_top=0, shuffle=True):
#     def remove(self, obj, shuffle=False):
# 
# Path: MTG/cardtype.py
# class SuperType(Enum):
# class CardType(Enum):
# class LandType(Enum):
#     BASIC = 0
#     LEGENDARY = 1
#     SNOW = 2
#     WORLD = 3
#     ARTIFACT = 0
#     CREATURE = 1
#     ENCHANTMENT = 2
#     INSTANT = 3
#     LAND = 4
#     PLANESWALKER = 5
#     SORCERY = 6
#     TRIBAL = 7
#     PLAINS = 0
#     ISLAND = 1
#     SWAMP = 2
#     MOUNTAIN = 3
#     FOREST = 4
# 
# Path: MTG/triggers.py
# class triggerConditions(Enum):
# 
# Path: MTG/play.py
# class Play(gameobject.GameObject):
#     def __init__(self, apply_func, apply_condition=lambda: True, 
#                  card=None, source=None, name=None,
#                  targets_chosen=None, target_criterias=None, is_mana_ability=False):
#     def __repr__(self):
#     def can_be_countered(self, source=None):
#     def counter(self, source):
#     def apply(self):
# 
# Path: MTG/abilities.py
# class Ability(gameobject.GameObject):
# class ActivatedAbility(Ability):
# class TriggeredAbility(Ability):
#     def __init__(self, card, effect, target_criterias=None,
#                  prompts=None):
#     def __str__(self):
#     def __repr__(self):
#     def resolve(self):
#     def __init__(self, card, cost, effect, target_criterias=None, prompts=None, is_mana_ability=False):
#     def can_activate(self):
#     def __init__(self, card, effect, requirements, target_criterias=None,
#                  prompts=None, intervening_if=None):
#     def condition_satisfied(self):
#     def put_on_stack(self):


import sys
import pdb
import math
import re
from collections import defaultdict, namedtuple
from sortedcontainers import SortedListWithKey
from functools import reduce
from MTG import gameobject
from MTG import zone
from MTG import cardtype
from MTG import triggers
from MTG import play
from MTG import abilities
        self.is_attacking = []
        self.is_blocking = []
        self.counters = defaultdict(lambda: 0)




class Effect():
    """ name: name of effct (dict key to self.effects)

    expiration: either a float representing timestamp (usually eot),
                or a function (lambda eff: ...) that when evaluated to True signals expiration

    toggle_func is the function that, while inactive, if evaluated to True toggles on the effct
        while active, the toggle function is negated; thus, it is passed into Effect(...)
        as a boolean dictionary (toggle_funcs)
    """
    def __init__(self, value, timestamp, apply_target=None, source=None, expiration=math.inf, is_active=True,
                 toggle_func=lambda eff: False):
        self.value = value
        self.source = source
        self.expiration = expiration
        self.is_active = is_active
        self.toggle_funcs = {False: toggle_func,
                             True: lambda eff: not toggle_func(eff)}
        self.timestamp = timestamp
        self.apply_target = apply_target




# Path: MTG/gameobject.py
# class Characteristics():
# class GameObject():
#     def __init__(self,
#                  name='',
#                  mana_cost='',
#                  color=[],
#                  types=[],
#                  subtype=[],
#                  supertype=[],
#                  text='',
#                  abilities=[],
#                  power=None,
#                  toughness=None,
#                  loyalty=None):
#     def __repr__(self):
#     def satisfy(self, criteria):
#     def __init__(self, characteristics=None,
#                  controller=None, owner=None, zone=None, 
#                  previousState=None):
#     def __repr__(self):
#     def __str__(self):
#     def __eq__(x, y):
#     def __hash__(self):
#     def owner(self):
#     def game(self):
#     def is_permanent(self):
#     def is_spell(self):
#     def name(self):
#     def raw_manacost(self):
#     def manacost(self):
#     def is_land(self):
#     def is_basic_land(self):
#     def is_creature(self):
#     def is_instant(self):
#     def is_sorcery(self):
#     def is_artifact(self):
#     def is_enchantment(self):
#     def is_aura(self):
#     def is_equipment(self):
#     def power(self):
#     def toughness(self):
#     def has_ability(self, ability):
#     def share_color(self, other):
#     def has_color(self, color):
#     def is_color(self, color):
#     def is_monocolored(self):
#     def is_multicolored(self):
#     def is_colorless(self):
#     def has_subtype(self, subtype):
#     def exile(self):
#     def targets(self):
#     def target_legality(self):
#     def has_valid_target(self):
#     def choose_targets(self):
#     def change_zone(self, target_zone, from_top=0, shuffle=True,
#                     status_mod=None, modi_func=None):
# 
# Path: MTG/zone.py
# class ZoneType(Enum):
# class Zone():
# class Battlefield(Zone):
# class Stack(Zone):
# class Hand(Zone):
# class Graveyard(Zone):
# class Exile(Zone):
# class Library(Zone):
#     LIBRARY = 0
#     HAND = 1
#     BATTLEFIELD = 2
#     GRAVEYARD = 3
#     STACK = 4
#     EXILE = 5
# def str_to_zone_type(z):
#     def __init__(self, controller=None, elements: list=None):
#     def __repr__(self):
#     def __str__(self):
#     def __len__(self):
#     def __bool__(self):
#     def __getitem__(self, pos):
#     def isEmpty(self):
#     def add(self, obj):
#     def remove(self, obj):
#     def filter(self, characteristics=None, filter_func=None):
#     def count(self, characteristics=None, filter_func=None):
#     def get_card_by_name(self, name):
#     def pop(self, pos=-1):
#     def clear(self):
#     def add(self, obj, status_mod=None, modi_func=None):
#     def shuffle(self):
#     def __init__(self, controller=None, elements: list=None):
#     def add(self, obj, from_top=0, shuffle=True):
#     def remove(self, obj, shuffle=False):
# 
# Path: MTG/cardtype.py
# class SuperType(Enum):
# class CardType(Enum):
# class LandType(Enum):
#     BASIC = 0
#     LEGENDARY = 1
#     SNOW = 2
#     WORLD = 3
#     ARTIFACT = 0
#     CREATURE = 1
#     ENCHANTMENT = 2
#     INSTANT = 3
#     LAND = 4
#     PLANESWALKER = 5
#     SORCERY = 6
#     TRIBAL = 7
#     PLAINS = 0
#     ISLAND = 1
#     SWAMP = 2
#     MOUNTAIN = 3
#     FOREST = 4
# 
# Path: MTG/triggers.py
# class triggerConditions(Enum):
# 
# Path: MTG/play.py
# class Play(gameobject.GameObject):
#     def __init__(self, apply_func, apply_condition=lambda: True, 
#                  card=None, source=None, name=None,
#                  targets_chosen=None, target_criterias=None, is_mana_ability=False):
#     def __repr__(self):
#     def can_be_countered(self, source=None):
#     def counter(self, source):
#     def apply(self):
# 
# Path: MTG/abilities.py
# class Ability(gameobject.GameObject):
# class ActivatedAbility(Ability):
# class TriggeredAbility(Ability):
#     def __init__(self, card, effect, target_criterias=None,
#                  prompts=None):
#     def __str__(self):
#     def __repr__(self):
#     def resolve(self):
#     def __init__(self, card, cost, effect, target_criterias=None, prompts=None, is_mana_ability=False):
#     def can_activate(self):
#     def __init__(self, card, effect, requirements, target_criterias=None,
#                  prompts=None, intervening_if=None):
#     def condition_satisfied(self):
#     def put_on_stack(self):


# Path: MTG/permanent.py
import sys
import pdb
import math
import re
from collections import defaultdict, namedtuple
from sortedcontainers import SortedListWithKey
from functools import reduce
from MTG import gameobject
from MTG import zone
from MTG import cardtype
from MTG import triggers
from MTG import play
from MTG import abilities

        self.is_attacking = []
        self.is_blocking = []
        self.counters = defaultdict(lambda: 0)




class Effect():
    """ name: name of effct (dict key to self.effects)

    expiration: either a float representing timestamp (usually eot),
                or a function (lambda eff: ...) that when evaluated to True signals expiration

    toggle_func is the function that, while inactive, if evaluated to True toggles on the effct
        while active, the toggle function is negated; thus, it is passed into Effect(...)
        as a boolean dictionary (toggle_funcs)
    """
    def __init__(self, value, timestamp, apply_target=None, source=None, expiration=math.inf, is_active=True,
                 toggle_func=lambda eff: False):
        self.value = value
        self.source = source
        self.expiration = expiration
        self.is_active = is_active
        self.toggle_funcs = {False: toggle_func,
                             True: lambda eff: not toggle_func(eff)}
        self.timestamp = timestamp
        self.apply_target = apply_target




class Permanent(gameobject.GameObject):