Map

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 (States) 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.

Map representation

A map can be represented/specified in many ways. In kuimaze2 we use two:

  • a multiline string where each character represents a position in the map, or
  • a bitmap picture where each pixel represents a position in the map.

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.

Creating a map ...

... from a string

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)}

... from a bitmap picture

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")

courses/be5b33kui/semtasks/kuimaze/05_map.txt · Last modified: 2024/02/20 15:44 by xposik