Ejemplo n.º 1
0
                    _world.goal_state[c] = ac[c]
                    print "After", pn, "goal changes:", c, "=", ac[c]
                    _path = _world.calculate()
                    return False
    return True


if __name__ == '__main__':
    import time

    _world = Planner('hungry', 'has_food', 'in_kitchen', 'tired', 'in_bed',
                     'has_money', 'is_fat', 'has_ingredients')
    _world.set_start_state(hungry=True,
                           has_food=False,
                           in_kitchen=False,
                           tired=True,
                           in_bed=False,
                           has_money=False,
                           is_fat=False,
                           has_ingredients=False)
    _world.set_goal_state(tired=False)

    _actions = Action_List()
    _actions.add_condition('eat', hungry=True, has_food=True, in_kitchen=False)
    _actions.add_reaction('eat', hungry=False, has_food=False)
    _actions.add_condition('cook',
                           hungry=True,
                           has_food=False,
                           in_kitchen=True,
                           has_ingredients=True)
    _actions.add_reaction('cook', has_food=True, has_ingredients=False)
    _actions.add_condition('sleep', tired=True, in_bed=True)
Ejemplo n.º 2
0
from goapy import Planner, Action_List

if __name__ == '__main__':
    import time

    _world = Planner('hungry', 'has_food', 'in_kitchen', 'tired', 'in_bed')
    _world.set_start_state(hungry=True,
                           has_food=False,
                           in_kitchen=False,
                           tired=True,
                           in_bed=False)
    _world.set_goal_state(tired=False)

    _actions = Action_List()
    _actions.add_condition('eat', hungry=True, has_food=True, in_kitchen=False)
    _actions.add_reaction('eat', hungry=False)
    _actions.add_condition('cook',
                           hungry=True,
                           has_food=False,
                           in_kitchen=True)
    _actions.add_reaction('cook', has_food=True)
    _actions.add_condition('sleep', tired=True, in_bed=True)
    _actions.add_reaction('sleep', tired=False)
    _actions.add_condition('go_to_bed', in_bed=False, hungry=False)
    _actions.add_reaction('go_to_bed', in_bed=True)
    _actions.add_condition('go_to_kitchen', in_kitchen=False)
    _actions.add_reaction('go_to_kitchen', in_kitchen=True)
    _actions.add_condition('leave_kitchen', in_kitchen=True)
    _actions.add_reaction('leave_kitchen', in_kitchen=False)
    _actions.add_condition('order_pizza', has_food=False, hungry=True)
    _actions.add_reaction('order_pizza', has_food=True)
Ejemplo n.º 3
0
from goapy import Planner, Action_List

if __name__ == '__main__':
	import time

	_world = Planner('hungry', 'has_food', 'in_kitchen', 'tired', 'in_bed')
	_world.set_start_state(hungry=True, has_food=False, in_kitchen=False, tired=True, in_bed=False)
	_world.set_goal_state(tired=False)

	_actions = Action_List()
	_actions.add_condition('eat', hungry=True, has_food=True, in_kitchen=False)
	_actions.add_reaction('eat', hungry=False)
	_actions.add_condition('cook', hungry=True, has_food=False, in_kitchen=True)
	_actions.add_reaction('cook', has_food=True)
	_actions.add_condition('sleep', tired=True, in_bed=True)
	_actions.add_reaction('sleep', tired=False)
	_actions.add_condition('go_to_bed', in_bed=False, hungry=False)
	_actions.add_reaction('go_to_bed', in_bed=True)
	_actions.add_condition('go_to_kitchen', in_kitchen=False)
	_actions.add_reaction('go_to_kitchen', in_kitchen=True)
	_actions.add_condition('leave_kitchen', in_kitchen=True)
	_actions.add_reaction('leave_kitchen', in_kitchen=False)
	_actions.add_condition('order_pizza', has_food=False, hungry=True)
	_actions.add_reaction('order_pizza', has_food=True)
	_actions.set_weight('go_to_kitchen', 20)
	_actions.set_weight('order_pizza', 1)

	_world.set_action_list(_actions)
	
	_t = time.time()
	_path = _world.calculate()
Ejemplo n.º 4
0
	import time

	_brain = World()

	_combat_brain = Planner('has_ammo',
							'has_weapon',
							'weapon_armed',
							'weapon_loaded',
							'in_engagement',
							'in_cover',
							'in_enemy_los',
							'is_near')
	_combat_brain.set_start_state(in_engagement=True,
								  is_near=False,
								  in_cover=False,
								  in_enemy_los=True,
								  has_ammo=False,
								  has_weapon=True,
								  weapon_armed=False,
								  weapon_loaded=False)
	_combat_brain.set_goal_state(in_engagement=False)

	_combat_actions = Action_List()
	_combat_actions.add_condition('track',
								  is_near=False,
								  weapon_armed=True)
	_combat_actions.add_reaction('track', is_near=True)
	_combat_actions.add_condition('unpack_ammo', has_ammo=False)
	_combat_actions.add_reaction('unpack_ammo', has_ammo=True)
	_combat_actions.add_condition('search_for_ammo', has_ammo=False)
	_combat_actions.add_reaction('search_for_ammo', has_ammo=True)
	_combat_actions.add_condition('reload',
Ejemplo n.º 5
0
    _brain = World()

    _movement_brain = Planner(
        'x',
        'y',
        'rotation',
        'canMoveLeft',
        'canMoveRight',
        'moved_down',
        'moved_horizontal',
    )

    _movement_brain.set_start_state(x=fallingPiece['x'],
                                    y=fallingPiece['y'],
                                    rotation=fallingPiece['rotation'],
                                    canMoveLeft=True,
                                    canMoveRight=True,
                                    moved_down=True,
                                    moved_horizontal=False)

    _movement_brain.set_goal_state(x=goalPiece['x'],
                                   y=goalPiece['y'],
                                   rotation=goalPiece['rotation'])

    _movement_actions = Action_List()

    _movement_actions.add_condition('move_left',
                                    canMoveLeft=True,
                                    moved_down=True)

    _movement_actions.add_reaction('move_left',
Ejemplo n.º 6
0
    def step(self):

        selforders = self.getOrders(c_selforder)
        passorders = self.getOrders(c_passorder)

        print(selforders, passorders)

        world = Planner('hungry', 'tired', "has_noorder", "has_order", "has_passorder", "get_order", "give_order", "execute_order", "bored")
        world.set_start_state(hungry=self.need_hunger > 70, tired=self.need_sleep > 70, has_order=len(selforders), has_passorder=len(passorders)>0, has_noorder=len(selforders)==0, bored=self.bored)
        world.set_goal_state(tired=False, has_passorder=False, has_noorder=True, has_order=True, bored=True)

        actions = Action_List()
        actions.add_condition('eat', hungry=True)
        actions.add_reaction('eat', hungry=False)

        actions.add_condition('sleep', tired=True)
        actions.add_reaction('sleep', tired=False)

        actions.add_condition("get_order", has_order=False)
        actions.add_reaction("get_order", has_order=True)
        actions.set_weight('get_order', 10)#dynamically adjust these weights

        actions.add_condition("give_order", has_passorder=True)
        actions.add_reaction("give_order", has_passorder=False)
        actions.set_weight('give_order', 5)

        actions.add_condition("execute_order", has_noorder=False)
        actions.add_reaction("execute_order", has_noorder=True)
        actions.set_weight('execute_order', 1)

        actions.add_condition("idle", bored=False)
        actions.add_reaction("idle", bored=True)
        actions.set_weight('idle', 20)



        world.set_action_list(actions)

        _t = time.time()
        path = world.calculate()
        _took_time = time.time() - _t

        #print(path)

        for pi, p in enumerate(path):
            print(pi, p['name'])

        if path is None or len(path) == 0:
            print("no path found")
            return

        self.listening = False


        pn = path[0]["name"]
        self.history.append(pn)
        if pn == "eat":
            self.need_hunger = max(0, self.need_hunger-20)
        elif pn == "sleep":
            self.need_sleep = max(0, self.need_sleep-20)
        elif pn == "give_order":
            po = choice(passorders)

            if po.target.listening:
                self.orders.remove(po)
                po.target.orders.append(po)
        elif pn == "get_order":
            self.listening = True
            print("listening")
        elif pn == "execute_order":
            order = selforders.pop(0)
            print("EXEC", order.message)
            self.orders.remove(order)

        if pn == "idle":
            self.bored = True
        else:
            self.bored = False
        #print('\nTook:', _took_time)

        self.need_hunger += 1
        self.need_sleep += 1
from goapy import World, Planner, Action_List

if __name__ == '__main__':
    import time

    _brain = World()

    _combat_brain = Planner('has_ammo', 'has_weapon', 'weapon_armed',
                            'weapon_loaded', 'in_engagement', 'in_cover',
                            'in_enemy_los', 'is_near')
    _combat_brain.set_start_state(in_engagement=True,
                                  is_near=False,
                                  in_cover=False,
                                  in_enemy_los=True,
                                  has_ammo=False,
                                  has_weapon=True,
                                  weapon_armed=False,
                                  weapon_loaded=False)
    _combat_brain.set_goal_state(in_engagement=False)

    _combat_actions = Action_List()
    _combat_actions.add_condition('track', is_near=False, weapon_armed=True)
    _combat_actions.add_reaction('track', is_near=True)
    _combat_actions.add_condition('unpack_ammo', has_ammo=False)
    _combat_actions.add_reaction('unpack_ammo', has_ammo=True)
    _combat_actions.add_condition('search_for_ammo', has_ammo=False)
    _combat_actions.add_reaction('search_for_ammo', has_ammo=True)
    _combat_actions.add_condition('reload',
                                  has_ammo=True,
                                  weapon_loaded=False,
                                  in_cover=True)