Search
Environment kuimaze2.SearchProblem shall be used for problems of finding the shortest path in a maze. It is used in optional task 01-easy_search and the first mandatory semestral task 03-search.
kuimaze2.SearchProblem
After creation of the SearchProblem instance (see Usage), you can use the following methods of the environment:
SearchProblem
env.get_start()
State
env.get_goals()
env.is_goal(state)
state
env.get_actions(state)
env.get_transition_result(state, action)
(new_state, transition_cost)
action
env.render()
help(env.render)
To use the environment, you need to:
>>> from kuimaze2 import SearchProblem, Map
>>> MAP = "S...G" >>> env = SearchProblem(Map.from_string(MAP))
>>> start = env.get_start() # start State >>> start State(r=0, c=0) >>> goals = env.get_goals() # set of goal States >>> goals {State(r=0, c=4)}
>>> actions = env.get_actions(start) >>> actions [<Action.UP: 0>, <Action.RIGHT: 1>, <Action.DOWN: 2>, <Action.LEFT: 3>] >>> next_state, cost = env.get_transition_result(start, actions[0]) >>> next_state State(r=0, c=0) # It is not possible to go UP from the start state, so stay in place >>> cost 1 # Although you stayed in place, the action costs you 1 unit >>> env.get_transition_result(start, actions[1]) # ... but it should be possible to go RIGHT (State(r=0, c=1), 1) # And yes, it is, we moved.
To update the graphical display of the environment (if you created it with env = SearchProblem(…, graphics=True)), use:
env = SearchProblem(…, graphics=True)
render()
help(SearchProblem.render)