social_dilemmas/envs/map_env.py
def map_to_colors(self, mmap, color_map, rgb_arr, orientation="UP"):
        """Converts a map to an array of RGB values.
        Parameters
        ----------
        mmap: np.ndarray
            map to convert to colors
            Double m to avoid shadowing map.
        color_map: dict
            mapping between array elements and desired colors
        rgb_arr: np.array
            Variable to store the mapping in
        orientation:
            The way in which the output should be oriented.
             UP = no rotation.
             RIGHT = Clockwise 90 degree rotation.
             DOWN = Clockwise 180 degree rotation.
             LEFT = Clockwise 270 degree rotation.
        Returns
        -------
        arr: np.ndarray
            3-dim numpy array consisting of color map
        """
        x_len = mmap.shape[0]
        y_len = mmap.shape[1]
        if orientation == "UP":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[row_elem, col_elem]]
        elif orientation == "LEFT":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[col_elem, x_len - 1 - row_elem]]
        elif orientation == "DOWN":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[
                        mmap[x_len - 1 - row_elem, y_len - 1 - col_elem]
                    ]
        elif orientation == "RIGHT":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[y_len - 1 - col_elem, row_elem]]
        else:
            raise ValueError("Orientation {} is not valid".format(orientation))

        return rgb_arr
Converts a map to an array of RGB values.
        Parameters
        ----------
        mmap: np.ndarray
            map to convert to colors
            Double m to avoid shadowing map.
        color_map: dict
            mapping between array elements and desired colors
        rgb_arr: np.array
            Variable to store the mapping in
        orientation:
            The way in which the output should be oriented.
             UP = no rotation.
             RIGHT = Clockwise 90 degree rotation.
             DOWN = Clockwise 180 degree rotation.
             LEFT = Clockwise 270 degree rotation.
        Returns
        -------
        arr: np.ndarray
            3-dim numpy array consisting of color map
        
Converts a map to an array of RGB values.
Parameters

np.ndarray
map to convert to colors
Double m to avoid shadowing map.
color_map: dict
mapping between array elements and desired colors
rgb_arr: np.array
Variable to store the mapping in
orientation:
The way in which the output should be oriented.
UP = no rotation.
RIGHT = Clockwise 90 degree rotation.
DOWN = Clockwise 180 degree rotation.
LEFT = Clockwise 270 degree rotation.
Returns

np.ndarray
3-dim numpy array consisting of color map
Converts a map to an array of RGB values . Parameters np . ndarray map to convert to colors Double m to avoid shadowing map . color_map : dict mapping between array elements and desired colors rgb_arr : np . array Variable to store the mapping in orientation : The way in which the output should be oriented . UP = no rotation . RIGHT = Clockwise 90 degree rotation . DOWN = Clockwise 180 degree rotation . LEFT = Clockwise 270 degree rotation . Returns np . ndarray 3 - dim numpy array consisting of color map
def map_to_colors(self, mmap, color_map, rgb_arr, orientation="UP"):
        x_len = mmap.shape[0]
        y_len = mmap.shape[1]
        if orientation == "UP":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[row_elem, col_elem]]
        elif orientation == "LEFT":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[col_elem, x_len - 1 - row_elem]]
        elif orientation == "DOWN":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[
                        mmap[x_len - 1 - row_elem, y_len - 1 - col_elem]
                    ]
        elif orientation == "RIGHT":
            for row_elem in range(x_len):
                for col_elem in range(y_len):
                    rgb_arr[row_elem, col_elem, :] = color_map[mmap[y_len - 1 - col_elem, row_elem]]
        else:
            raise ValueError("Orientation {} is not valid".format(orientation))
        return rgb_arr
def map_to_colors ( self , mmap , color_map , rgb_arr , orientation = "UP" ) : x_len = mmap . shape [ 0 ] y_len = mmap . shape [ 1 ] if orientation == "UP" : for row_elem in range ( x_len ) : for col_elem in range ( y_len ) : rgb_arr [ row_elem , col_elem , : ] = color_map [ mmap [ row_elem , col_elem ] ] elif orientation == "LEFT" : for row_elem in range ( x_len ) : for col_elem in range ( y_len ) : rgb_arr [ row_elem , col_elem , : ] = color_map [ mmap [ col_elem , x_len - 1 - row_elem ] ] elif orientation == "DOWN" : for row_elem in range ( x_len ) : for col_elem in range ( y_len ) : rgb_arr [ row_elem , col_elem , : ] = color_map [ mmap [ x_len - 1 - row_elem , y_len - 1 - col_elem ] ] elif orientation == "RIGHT" : for row_elem in range ( x_len ) : for col_elem in range ( y_len ) : rgb_arr [ row_elem , col_elem , : ] = color_map [ mmap [ y_len - 1 - col_elem , row_elem ] ] else : raise ValueError ( "Orientation {} is not valid" . format ( orientation ) ) return rgb_arr
Converts a map to an array of RGB values.
Converts a map to an array of RGB values .
"""Converts a map to an array of RGB values.
        Parameters
        ----------
        mmap: np.ndarray
            map to convert to colors
            Double m to avoid shadowing map.
        color_map: dict
            mapping between array elements and desired colors
        rgb_arr: np.array
            Variable to store the mapping in
        orientation:
            The way in which the output should be oriented.
             UP = no rotation.
             RIGHT = Clockwise 90 degree rotation.
             DOWN = Clockwise 180 degree rotation.
             LEFT = Clockwise 270 degree rotation.
        Returns
        -------
        arr: np.ndarray
            3-dim numpy array consisting of color map
        """
self
mmap
color_map
rgb_arr
orientation