示例#1
0
def createTree():
    global siegeTowerAttackingTree
    siegeTowerAttackingTree = b3.BehaviorTree()
    siegeTowerAttackingTree.id = 'siegeTowerAttackingTree'
    node1 = b3.Sequence([
        IsNotDefeated(),
        IsAttacking(),
        IsInBattlefield(),
        ReadyToShoot(),
        SelectPosAndClosestConstruction(),
        Attack()
    ])
    siegeTowerAttackingTree.root = node1

#     global siegeTowerDefendingTree
#     siegeTowerDefendingTree = b3.BehaviorTree()
#     siegeTowerDefendingTree.id = 'siegeTowerDefendingTree'
#     node2 = b3.Sequence([
#         IsDefeated(),
#         IsCorrectCommand(),
#         IsDefendingLine(),
#         IsReloading(),
#         AcquireTargetForDefense(),
#         Defend()
#         ])
#     siegeTowerDefendingTree.root = node2

    global siegeTowerMovingTree
    siegeTowerMovingTree = b3.BehaviorTree()
    siegeTowerMovingTree.id = 'siegeTowerMovingTree'
    node3 = b3.Sequence([
        IsNotDefeated(),
        HasValidPath(),
        UpdateConstructionStatus(),
        b3.Priority([b3.Inverter(HasMoat()),            # if not (HasMoat is False): 
            b3.Sequence([                               #
                b3.Priority([HasTurtle(),               #     if (hasTurtle is False):
                    CreateTurtle()]),                   #         createTurtle
                b3.Priority([b3.Inverter(HasTurtle()),  #     if not (hasTurtle is False):
                    HandleTurtle()]),                   #         HandleTurtle
            ]),
        ]),
        b3.Sequence([ReadyToMove(),                     # if (ReadyToMove is True):
                     SelectNextCell(),                  #    SelectNextCell
                     Move()                             #    Move !
        ])
    ])
    siegeTowerMovingTree.root = node3

    resetBlackboard()
示例#2
0
    def test_success(self):
        node = NodeStub()
        inverter = b3.Inverter(node)
        tick = TickStub()

        node._execute.return_value = b3.SUCCESS
        status = inverter._execute(tick)
        self.assertEqual(status, b3.FAILURE)
示例#3
0
    def test_running(self):
        node = NodeStub()
        inverter = b3.Inverter(node)
        tick = TickStub()

        node._execute.return_value = b3.RUNNING
        status = inverter._execute(tick)
        self.assertEqual(status, b3.RUNNING)
示例#4
0
 def __init__(self):
     isFarFromGoal = b3.Inverter(isNextToGoalCondition())
     childSequence = b3.Sequence(
         [isFarFromGoal,
          WalkToGoalSEQ(),
          SetGoalToRessource()])
     childList = [childSequence, b3.Succeeder()]
     super().__init__(childList)
示例#5
0
 def __init__(self):
     isNotFull = b3.Inverter(isFullCondition())
     childSequence = b3.Sequence([
         isNotFull,
         isGoalLootCondition(),
         isNextToGoalCondition(),
         MineGoal()
     ])
     childList = [childSequence, b3.Succeeder()]
     super().__init__(childList)
示例#6
0
def Mario_agent(sensor, state):
    aug_leaf.sensor = sensor
    aug_leaf.fire = state
    obstacle = 100
    enemy = 1
    control = {'right': 3, 'fire': 5, 'jump': 4}
    tree = b3.BehaviorTree()
    #--------------------------C1----------------------#
    n0 = mario_state_condition()
    n1 = mario_leaf_condition(2, 4, enemy)
    n2 = mario_leaf_action(control['fire'])
    c1 = b3.Sequence([n0, n1, n2])

    #--------------------------C4-----------------------#
    n5 = mario_leaf_condition(3, 1, obstacle)
    n6 = mario_leaf_condition(3, 2, obstacle)
    i1 = b3.Inverter(n5)
    i2 = b3.Inverter(n6)
    c4 = b3.Sequence([i1, i2])

    #--------------------------C3------------------------#
    n3 = mario_leaf_condition(2, 2, obstacle)
    n4 = mario_leaf_condition(1, 3, obstacle)
    c3 = b3.Priority([n3, n4, c4])

    #--------------------------C2-----------------------#
    n7 = mario_leaf_action(control['jump'])
    c2 = b3.Sequence([c3, n7])

    #--------------------------Root----------------------#
    n8 = mario_leaf_action(control['right'])
    root = b3.Priority([c1, c2, n8])
    ###################################################################
    tree.root = root

    return tree
示例#7
0
def createTree():
    global archerAttackingTree
    archerAttackingTree = b3.BehaviorTree()
    archerAttackingTree.id = 'archerAttackingTree'
    node1 = b3.Sequence([
        IsDefeated(),
        IsCorrectCommand(),
        IsInBattlefield(),
        IsReloading(),
        Attack()
    ])
    archerAttackingTree.root = node1

    global archerDefendingTree
    archerDefendingTree = b3.BehaviorTree()
    archerDefendingTree.id = 'archerDefendingTree'
    node2 = b3.Sequence([
        IsDefeated(),
        IsCorrectCommand(),
        IsDefendingLine(),
        IsReloading(),
        AcquireTargetForDefense(),
        Defend()
    ])
    archerDefendingTree.root = node2

    global archerMovingTree
    archerMovingTree = b3.BehaviorTree()
    archerMovingTree.id = 'archerMovingTree'
    node3 = b3.Sequence([
        IsDefeated(),
        IsMoveCommand(),
        IsInBattlefield(),
        AcquireCandidateCells(),
        b3.Sequence([
            selectDestinationTarget(),
            b3.Priority([
                b3.Inverter(doesDestinationNeedCorrection()),
                correctDestinationTarget(),
            ]),
        ]),
        selectFinalDestinationCell(),
        Move()
    ])
    archerMovingTree.root = node3

    resetBlackboard()
示例#8
0
    def test_running(self):
        inverter = b3.Inverter()
        tick = TickStub()

        status = inverter._execute(tick)
        self.assertEqual(status, b3.ERROR)
示例#9
0
    def test_dump(self):
        tree = b3.BehaviorTree()

        class Custom(b3.Condition):
            title = 'custom'

        tree.properties = {
            'prop': 'value',
            'comp': {
                'val1': 234,
                'val2': 'value'
            }
        }

        node5 = Custom()
        node5.id = 'node-5'
        node5.title = 'Node5'
        node5.description = 'Node 5 Description'

        node4 = b3.Wait()
        node4.id = 'node-4'
        node4.title = 'Node4'
        node4.description = 'Node 4 Description'

        node3 = b3.MemSequence([node5])
        node3.id = 'node-3'
        node3.title = 'Node3'
        node3.description = 'Node 3 Description'

        node2 = b3.Inverter(node4)
        node2.id = 'node-2'
        node2.title = 'Node2'
        node2.description = 'Node 2 Description'

        node1 = b3.Priority([node2, node3])
        node1.id = 'node-1'
        node1.title = 'Node1'
        node1.description = 'Node 1 Description'
        node1.properties = {'key': 'value'}

        tree.root = node1
        tree.title = 'Title in Tree'
        tree.description = 'Tree Description'

        data = tree.dump()

        self.assertEqual(data['title'], 'Title in Tree')
        self.assertEqual(data['description'], 'Tree Description')
        self.assertEqual(data['root'], 'node-1')
        self.assertEqual(data['properties']['prop'], 'value')
        self.assertEqual(data['properties']['comp']['val1'], 234)
        self.assertEqual(data['properties']['comp']['val2'], 'value')

        self.assertNotEqual(data['custom_nodes'], None)
        self.assertEqual(len(data['custom_nodes']), 1)
        self.assertEqual(data['custom_nodes'][0]['name'], 'Custom')
        self.assertEqual(data['custom_nodes'][0]['title'], 'Node5')
        self.assertEqual(data['custom_nodes'][0]['category'], b3.CONDITION)

        self.assertNotEqual(data['nodes']['node-1'], None)
        self.assertNotEqual(data['nodes']['node-2'], None)
        self.assertNotEqual(data['nodes']['node-3'], None)
        self.assertNotEqual(data['nodes']['node-4'], None)
        self.assertNotEqual(data['nodes']['node-5'], None)

        self.assertEqual(data['nodes']['node-1']['id'], 'node-1')
        self.assertEqual(data['nodes']['node-1']['name'], 'Priority')
        self.assertEqual(data['nodes']['node-1']['title'], 'Node1')
        self.assertEqual(data['nodes']['node-1']['description'],
                         'Node 1 Description')
        self.assertEqual(data['nodes']['node-1']['children'][0], 'node-3')
        self.assertEqual(data['nodes']['node-1']['children'][1], 'node-2')
        self.assertEqual(data['nodes']['node-1']['properties']['key'], 'value')

        self.assertEqual(data['nodes']['node-2']['name'], 'Inverter')
        self.assertEqual(data['nodes']['node-2']['title'], 'Node2')
        self.assertEqual(data['nodes']['node-2']['description'],
                         'Node 2 Description')
        self.assertNotEqual(data['nodes']['node-2']['child'], None)

        self.assertEqual(data['nodes']['node-3']['name'], 'MemSequence')
        self.assertEqual(data['nodes']['node-3']['title'], 'Node3')
        self.assertEqual(data['nodes']['node-3']['description'],
                         'Node 3 Description')
        self.assertEqual(len(data['nodes']['node-3']['children']), 1)

        self.assertEqual(data['nodes']['node-4']['name'], 'Wait')
        self.assertEqual(data['nodes']['node-4']['title'], 'Node4')
        self.assertEqual(data['nodes']['node-4']['description'],
                         'Node 4 Description')

        self.assertEqual(data['nodes']['node-5']['name'], 'Custom')
        self.assertEqual(data['nodes']['node-5']['title'], 'Node5')
        self.assertEqual(data['nodes']['node-5']['description'],
                         'Node 5 Description')
示例#10
0
 def __init__(self):
     isThereNoPath = b3.Inverter(isThereAPathCondition())
     ifNoPathCreateIt = b3.Sequence([isThereNoPath, CreatePath()])
     childList = [ifNoPathCreateIt, b3.Succeeder()]
     super().__init__(childList)
示例#11
0
 def __init__(self):
     isFarFromGoal = b3.Inverter(isNextToGoalCondition())
     isGoalHomeOrNoPath = b3.Priority(
         [isGoalHomeCondition(), isFarFromGoal])
     childList = [isGoalHomeOrNoPath, GetCheckConsumeNextMoveSEQ()]
     super().__init__(childList)
示例#12
0
 def __init__(self):
     isThereNoGoal = b3.Inverter(isThereAGoalCondition())
     childSequence = b3.Sequence([isThereNoGoal, SetGoalToRessource()])
     childList = [childSequence, b3.Succeeder()]
     super().__init__(childList)