Exemplo n.º 1
0
def create_default_tree() -> SkillDecisionTree:
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> t = create_default_tree()
    >>> type(t.value) == MageAttack
    True
    >>> len(t.children)
    3
    """
    root = SkillDecisionTree(MageAttack(), lambda c, t: c.get_hp() > 50, 5)
    root.children = \
        [SkillDecisionTree(MageAttack(),
                           lambda c, t: c.get_sp() > 20, 3,
                           [SkillDecisionTree
                            (RogueSpecial(),
                             lambda c, t: t.get_hp() < 30, 4,
                             [SkillDecisionTree
                              (RogueAttack(),
                               lambda c, t: False, 6)])]),
         SkillDecisionTree(MageSpecial(),
                           lambda c, t: t.get_sp() > 40, 2,
                           [SkillDecisionTree(RogueAttack(),
                                              lambda c, t: False, 8)]),
         SkillDecisionTree(RogueAttack(),
                           lambda c, t: c.get_hp() > 90, 1,
                           [SkillDecisionTree(RogueSpecial(),
                                              lambda c, t: False, 7)])]
    return root
def create_default_tree() -> SkillDecisionTree:
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    """

    t6 = SkillDecisionTree(RogueAttack(), def_f, 6)

    t4 = SkillDecisionTree(RogueSpecial(), f4, 4)
    t4.children = [t6]

    t3 = SkillDecisionTree(MageAttack(), f3, 3)
    t3.children = [t4]

    t8 = SkillDecisionTree(RogueAttack(), def_f, 8)

    t2 = SkillDecisionTree(MageSpecial(), f2, 2)
    t2.children = [t8]

    t7 = SkillDecisionTree(RogueSpecial(), def_f, 7)

    t1 = SkillDecisionTree(RogueAttack(), f1, 1)
    t1.children = [t7]

    t = SkillDecisionTree(MageAttack(), f, 5)
    t.children = [t3, t2, t1]

    return t
Exemplo n.º 3
0
def create_default_tree() -> SkillDecisionTree:
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> from a2_skills import MageAttack
    >>> t = create_default_tree()
    >>> t.priority
    5
    >>> str(t.condition)[10:32]
    'caster_hp_more_than_50'
    >>> type(t.value) == MageAttack
    True
    """
    from a2_skills import MageAttack, MageSpecial, RogueAttack, RogueSpecial
    t1 = SkillDecisionTree(MageAttack(), caster_sp_more_than_20, 3)
    t2 = SkillDecisionTree(RogueSpecial(), target_hp_less_than_30, 4)
    t3 = SkillDecisionTree(RogueAttack(), just_want_return_false, 6)
    t4 = SkillDecisionTree(MageSpecial(), target_sp_more_than_40, 2)
    t5 = SkillDecisionTree(RogueAttack(), just_want_return_false, 8)
    t6 = SkillDecisionTree(RogueAttack(), caster_hp_more_than_90, 1)
    t7 = SkillDecisionTree(RogueSpecial(), just_want_return_false, 7)
    t1.children = [t2]
    t2.children = [t3]
    t4.children = [t5]
    t6.children = [t7]
    t = SkillDecisionTree(MageAttack(), caster_hp_more_than_50, 5,
                          [t1, t4, t6])
    return t
Exemplo n.º 4
0
def create_default_tree() -> 'SkillDecisionTree':
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> from a2_skills import RogueAttack
    >>> t100 = SkillDecisionTree(RogueAttack(), leaf_function, 100)
    >>> t100.priority
    100
    """
    t6 = SkillDecisionTree(RogueAttack(), leaf_function, 6)
    t8 = SkillDecisionTree(RogueAttack(), leaf_function, 8)
    t7 = SkillDecisionTree(RogueSpecial(), leaf_function, 7)
    t4 = SkillDecisionTree(RogueSpecial(), target_hp_less_than_30, 4, [t6])
    t3 = SkillDecisionTree(MageAttack(), caster_sp_more_than_20, 3, [t4])
    t2 = SkillDecisionTree(MageSpecial(), target_sp_more_than_40, 2, [t8])
    t1 = SkillDecisionTree(RogueAttack(), caster_hp_more_than_90, 1, [t7])
    t5 = SkillDecisionTree(MageAttack(), caster_hp_more_than_50, 5,
                           [t3, t2, t1])
    return t5
Exemplo n.º 5
0
def create_default_tree() -> 'SkillDecisionTree':
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.
    
    >>> tree = create_default_tree()
    >>> from a2_characters import Mage, Rogue
    >>> from a2_battle_queue import BattleQueue
    >>> from a2_playstyle import *
    >>> from a2_skills import *
    >>> bq = BattleQueue()
    >>> ps = ManualPlaystyle(bq)
    >>> r = Rogue('r', bq, ps)
    >>> m = Mage('m', bq, ps)
    >>> m.enemy, r.enemy = r, m
    >>> m.set_hp(100)
    >>> m.set_sp(40)
    >>> r.set_hp(50)
    >>> r.set_sp(30)
    >>> tree = create_default_tree()
    >>> picked_skill = tree.pick_skill(m, r)
    >>> isinstance(picked_skill, MageSpecial)
    True
    >>> m.set_hp(80)
    >>> m.set_sp(40)
    >>> r.set_hp(20)
    >>> r.set_sp(50)
    >>> picked_skill = tree.pick_skill(m, r)
    >>> isinstance(picked_skill, RogueAttack)
    True
    """
    # TODO: Return a SkillDecisionTree that matches the one in a2.pdf.
    t6 = SkillDecisionTree(RogueAttack(), f6, 8)
    t7 = SkillDecisionTree(RogueSpecial(), f6, 7)
    t4 = SkillDecisionTree(RogueAttack(), f4, 1, [t7])
    t8 = SkillDecisionTree(RogueAttack(), f6, 6)
    t5 = SkillDecisionTree(RogueSpecial(), f5, 4, [t8])
    t3 = SkillDecisionTree(MageSpecial(), f3, 2, [t6])
    t2 = SkillDecisionTree(MageAttack(), f2, 3, [t5])
    t9 = SkillDecisionTree(MageAttack(), f1, 5, [t2, t3, t4])
    return t9
def create_default_tree() -> 'SkillDecisionTree':
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> t = create_default_tree()
    >>> t.value.get_sp_cost()
    5
    >>> t.priority
    5
    >>> t.children[0].priority
    3
    """
    from a2_skills import RogueAttack, RogueSpecial, MageAttack, MageSpecial
    t4 = SkillDecisionTree(RogueSpecial(), f4, 4,
                           [SkillDecisionTree(RogueAttack(), f1, priority=6)])
    t3 = SkillDecisionTree(MageAttack(), f3, 3, [t4])
    t2 = SkillDecisionTree(MageSpecial(), f2, 2,
                           [SkillDecisionTree(RogueAttack(), f1, priority=8)])
    t1 = SkillDecisionTree(RogueAttack(), f1, 1,
                           [SkillDecisionTree(RogueSpecial(), f1, priority=7)])
    root = SkillDecisionTree(MageAttack(), f5, 5, [t3, t2, t1])
    return root
Exemplo n.º 7
0
def create_default_tree() -> SkillDecisionTree:
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> type(create_default_tree())
    <class '__main__.SkillDecisionTree'>

    """
    # TODO: Return a SkillDecisionTree that matches the one in a2.pdf.

    t2 = SkillDecisionTree(MageAttack(), checker2, 3, [
        SkillDecisionTree(RogueSpecial(), checker3, 4,
                          [SkillDecisionTree(RogueAttack(), general, 6)])
    ])
    t3 = SkillDecisionTree\
        (MageSpecial(), checker4, 2,
         [SkillDecisionTree(RogueAttack(),
                            general, 8)])
    t4 = SkillDecisionTree(RogueAttack(), checker5, 1,
                           [SkillDecisionTree(RogueSpecial(), general, 7)])

    t1 = SkillDecisionTree(MageAttack(), checker1, 5, [t2, t3, t4])
    return t1
Exemplo n.º 8
0
    def __init__(self, name: str, bq: 'BattleQueue', ps: 'Playstyle') -> None:
        """
        Initialize this Rogue with the name name, battle_queue bq, and
        playstyle ps.

        >>> from a2_battle_queue import BattleQueue
        >>> from a2_playstyle import ManualPlaystyle
        >>> bq = BattleQueue()
        >>> c = Rogue("r", bq, ManualPlaystyle(bq))
        >>> c2 = Rogue("r2", bq, ManualPlaystyle(bq))
        >>> c.enemy = c2
        >>> c2.enemy = c
        >>> c
        r (Rogue): 100/100
        """
        super().__init__(name, bq, ps)
        self._character_type = 'rogue'
        self._skills['A'] = RogueAttack()
        self._skills['S'] = RogueSpecial()
        self._defense = 10
Exemplo n.º 9
0
def create_default_tree() -> SkillDecisionTree:
    """
    Return a SkillDecisionTree that matches the one described in a2.pdf.

    >>> sdt = create_default_tree()
    >>> from a2_battle_queue import BattleQueue
    >>> bq = BattleQueue()
    >>> from a2_playstyle import ManualPlaystyle
    >>> from a2_characters import Rogue, Mage, Vampire, Sorcerer
    >>> caster = Vampire("Caster", bq, ManualPlaystyle(bq))
    >>> target = Vampire("Target", bq, ManualPlaystyle(bq))
    >>> caster.set_hp(80)
    >>> caster.set_sp(40)
    >>> target.set_hp(20)
    >>> target.set_sp(50)
    >>> sdt.get_satisfied_sdt(caster, target)
    [SDT(6, RogueAttack), SDT(8, RogueAttack), SDT(1, RogueAttack)]
    >>> sdt.pick_skill(caster, target).__class__.__name__
    'RogueAttack'
    """
    def caster_hp_gt_90(caster, _):
        """
        Return True if the caster's HP is > 90
        """
        return caster.get_hp() > 90

    def target_sp_gt_40(_, target):
        """
        Return True if the target's SP is >40
        """
        return target.get_sp() > 40

    def caster_sp_gt_20(caster, _):
        """
        Return True if the caster's SP is > 20
        """
        return caster.get_sp() > 20

    def target_hp_lt_30(_, target):
        """
        Return True if the target's HP is < 30
        """
        return target.get_hp() < 30

    def caster_hp_gt_50(caster, _):
        """
        Return True if the caster's HP is > 50
        """
        return caster.get_hp() > 50

    def no_condition(_, __):
        """
        By default, return True.
        """
        return True

    priority_1 = SkillDecisionTree(RogueAttack(), caster_hp_gt_90, 1)
    priority_2 = SkillDecisionTree(MageSpecial(), target_sp_gt_40, 2)
    priority_3 = SkillDecisionTree(MageAttack(), caster_sp_gt_20, 3)
    priority_4 = SkillDecisionTree(RogueSpecial(), target_hp_lt_30, 4)
    priority_5 = SkillDecisionTree(MageAttack(), caster_hp_gt_50, 5)
    priority_6 = SkillDecisionTree(RogueAttack(), no_condition, 6)
    priority_7 = SkillDecisionTree(RogueSpecial(), no_condition, 7)
    priority_8 = SkillDecisionTree(RogueAttack(), no_condition, 8)

    priority_4.children.append(priority_6)
    priority_3.children.append(priority_4)
    priority_2.children.append(priority_8)
    priority_1.children.append(priority_7)

    priority_5.children = [priority_3, priority_2, priority_1]
    return priority_5