def test_conditional_long(self):
		state = dict(target=[], condition=True)
		tree = behaviours.conditional("condition",
			condition=behaviours.evalb("check", lambda state: state['condition']),
			true=behaviours.repeat(behaviours.do("success", lambda state: state['target'].append(True))),
			false=behaviours.repeat(behaviours.do("fail", lambda state: state['target'].append(False))),
		)

		
		running, success = tree.tick(state)
		self.assertEqual(running, True)
		self.assertEqual(state['target'], [True])
		
		running, success = tree.tick(state)
		self.assertEqual(running, True)
		self.assertEqual(state['target'], [True, True])

		state['condition'] = False
		running, success = tree.tick(state)
		self.assertEqual(running, True)
		self.assertEqual(state['target'], [True, True, False])

		state['condition'] = True
		running, success = tree.tick(state)
		self.assertEqual(running, True)
		self.assertEqual(state['target'], [True, True, False, True])
Esempio n. 2
0
    def test_conditional_long(self):
        state = dict(target=[], condition=True)
        tree = behaviours.conditional(
            "condition",
            condition=behaviours.evalb("check",
                                       lambda state: state['condition']),
            true=behaviours.repeat(
                behaviours.do("success",
                              lambda state: state['target'].append(True))),
            false=behaviours.repeat(
                behaviours.do("fail",
                              lambda state: state['target'].append(False))),
        )

        running, success = tree.tick(state)
        self.assertEqual(running, True)
        self.assertEqual(state['target'], [True])

        running, success = tree.tick(state)
        self.assertEqual(running, True)
        self.assertEqual(state['target'], [True, True])

        state['condition'] = False
        running, success = tree.tick(state)
        self.assertEqual(running, True)
        self.assertEqual(state['target'], [True, True, False])

        state['condition'] = True
        running, success = tree.tick(state)
        self.assertEqual(running, True)
        self.assertEqual(state['target'], [True, True, False, True])
	def test_repeat(self):
		target = []
		tree = behaviours.repeat(behaviours.do("success", lambda state: state.append(True)))
		running, success = tree.tick(target)
		self.assertEqual(running, True)
		self.assertEqual(target, [True])
		running, success = tree.tick(target)
		self.assertEqual(running, True)
		self.assertEqual(target, [True, True])
Esempio n. 4
0
 def test_repeat(self):
     target = []
     tree = behaviours.repeat(
         behaviours.do("success", lambda state: state.append(True)))
     running, success = tree.tick(target)
     self.assertEqual(running, True)
     self.assertEqual(target, [True])
     running, success = tree.tick(target)
     self.assertEqual(running, True)
     self.assertEqual(target, [True, True])