示例#1
0
    def setUp(self):
        # Create the initial state
        initial_state_dict = {
            'characters': {
                'alice': {
                    'toes': 10
                }
            }
        }
        state = State.from_dict(initial_state_dict)

        # Create an action
        class AddToes(Action):
            name = 'add toes'

            def apply(self, state_dict):
                for character_key in self.objects:
                    state_dict['characters'][character_key]['toes'] += 1
                return state_dict

        # Create the goal verification function
        def enough_toes(state):
            state_dict = state.as_dict()
            return state_dict['characters']['alice']['toes'] >= 12

        self.goal_fn = enough_toes
        self.action = AddToes
        self.state = state
示例#2
0
 def setUp(self):
     self.initial_state_dict = {
         'characters': {
             'alice': {
                 'alive': True
             },
             'bob': {
                 'alive': True
             }
         }
     }
     self.state = State.from_dict(self.initial_state_dict)
     self.goal_fn = dead_goal_factory('bob')
示例#3
0
    def setUp(self):
        # Create the initial state
        initial_state_dict = {
            'characters': {
                'alice': {
                    'has_money': False
                },
                'bob': {
                    'has_money': True
                },
                'carol': {
                    'has_money': False
                }
            }
        }
        state = State.from_dict(initial_state_dict)

        # Create an action
        class GiveMoney(Action):
            name = 'give money'

            def apply(self, state_dict):
                for character_key in self.subjects:
                    if not state_dict['characters'][character_key]['has_money']:
                        raise ImpossibleActionException()
                for character_key in self.subjects:
                    state_dict['characters'][character_key]['has_money'] = False
                for character_key in self.objects:
                    state_dict['characters'][character_key]['has_money'] = True
                return state_dict

        # Create the goal verification function
        def carol_has_money(state):
            state_dict = state.as_dict()
            return state_dict['characters']['carol']['has_money']

        self.goal_fn = carol_has_money
        self.give_money = GiveMoney
        self.state = state
示例#4
0
 def test_already_satisfied(self):
     self.initial_state_dict['characters']['bob']['alive'] = False
     state = State.from_dict(self.initial_state_dict)
     plan = plan_search(['alice'], state, [Kill], self.goal_fn)
     self.assertIsNone(plan)