예제 #1
0
    def tick(self, target, blackboard):

        # Create the TICK object
        tick = b3.Tick()
        tick.target = target
        tick.blackboard = blackboard
        tick.tree = self
        tick.debug = self.debug

        # Tick node
        state = self.root._execute(tick)

        # Close node from last tick, if needed
        last_open_nodes = blackboard.get('open_nodes', self.id)
        curr_open_nodes = tick._open_nodes

        start = 0
        for node1, node2 in itertools.izip(last_open_nodes, curr_open_nodes):
            start += 1
            if node1 != node2:
                break

        # - close nodes
        for i in xrange(len(last_open_nodes) - 1, start - 1, -1):
            last_open_nodes[i]._close(tick)

        # Populate blackboard
        blackboard.set('open_nodes', curr_open_nodes, self.id)
        blackboard.set('node_count', tick._node_count, self.id)
예제 #2
0
    def test_updateTickOnEnter(self):
        tick = b3.Tick()
        node = 'Node'

        tick._enter_node(node)

        self.assertEqual(tick._node_count, 1)
        self.assertListEqual(tick._open_nodes, ['Node'])
예제 #3
0
    def tick(self, target, blackboard):
        # Create the TICK object
        tick = b3.Tick()
        tick.target = target
        tick.blackboard = blackboard
        tick.tree = self
        tick.debug = self.debug

        return self._execute(tick)
예제 #4
0
 def test_initialization(self):
     tick = b3.Tick()
     
     self.assertIsNone(tick.tree)
     self.assertIsNone(tick.debug)
     self.assertIsNone(tick.target)
     self.assertIsNone(tick.blackboard)
     self.assertEqual(tick._node_count, 0)
     self.assertListEqual(tick._open_nodes, [])
예제 #5
0
    def test_updateTickOnClose(self):
        tick = b3.Tick()
        node = 'Node'

        tick._node_count = 1
        tick._open_nodes = [node]
        tick._close_node(node)

        self.assertEqual(tick._node_count, 1)
        self.assertListEqual(tick._open_nodes, [])
예제 #6
0
파일: behaviortree.py 프로젝트: iory/IKBT
    def tick(self, target, blackboard):

        self.tick_count += 1
        # Create the TICK object
        tick = b3.Tick()
        tick.target = target
        tick.blackboard = blackboard
        tick.tree = self
        tick.debug = self.debug

        # Tick node
        state = self.root._execute(tick)

        # BH Hacks
        # if state != b3.RUNNING:
        # if state == b3.SUCCESS:
        # print "Root node SUCCESS!!!"
        # if state == b3.FAILURE:
        # print "Root node FAILURE!!!"

        # BH:    code below nonfunctional with "RUNNING" nodes
        # and largely commented out
        # Close node from last tick, if needed
        last_open_nodes = blackboard.get('open_nodes', self.id)
        curr_open_nodes = tick._open_nodes

        start = 0
        # for node1, node2 in itertools.izip(last_open_nodes, curr_open_nodes):
        #start += 1
        # if node1 != node2:
        # break

        # - close nodes
        # for i in xrange(len(last_open_nodes)-1, start-1, -1):
        # last_open_nodes[i]._close(tick);

        # Populate blackboard
        blackboard.set('open_nodes', curr_open_nodes, self.id)
        blackboard.set('node_count', tick._node_count, self.id)

        return state