Class Map
represents the actual maze (well, its map). It is a required input parameter of all problem environments (SearchProblem, MDPProblem, RLProblem).
With the exception of creation, you will never need to work with the map directly. It provides the problem environments with information about the dimensions of the map, which positions (State
s) are free, what the start state is, where the goal states are, where the danger states are, whether a transition from one state to another is possible, etc.
A map can be represented/specified in many ways. In kuimaze2
we use two:
The meaning of individual characters/colors:
Char | Color | Meaning |
---|---|---|
. | White | Normal empty/free accessible position. |
# | Black | Wall (inaccessible position). |
S | Blue | Start position. Each map can have only a single start position. |
G | Green | Goal position (desired terminal). Each map can have multiple goal positions. |
D | Red | Danger position (undesired terminal). Each map can have multiple danger positions. |
A map can be created from a multiline string using Map.from_string()
class method:
>>> from kuimaze2 import Map >>> MAP = """ S#.G .D.D .... """ >>> m = Map.from_string(MAP) >>> m.width 4 >>> m.height 3 >>> m.start State(r=0, c=0) >>> m.goals {State(r=0, c=3)} >>> m.dangers {State(r=1, c=1), State(r=1, c=3)}
To create a map from a bitmap picture, do the following:
from kuimaze2.map_image import map_from_image map = map_from_image("../maps/normal/normal2.png")