如何利用网格环境创建一个openAI健身房观察空间

zor*_*ali 6 python artificial-intelligence reinforcement-learning openai-gym

我在 Tkinter 中构建了环境,如何使用该环境创建观察空间。我无法理解如何使用数组中的网格坐标来制作观察空间, self.observation_space = space.Box(np.array([]), np.array([]), dtype=np.int),给出了代码。如果有人提供帮助,我将不胜感激。

enter code here

# Setting the sizes for the environment
pixels = 40   # pixels
env_height =9   # grid height
env_width = 9  # grid width

# Global variable for dictionary with coordinates for the final route
a = {}


# Creating class for the environment
class Environment(tk.Tk, object):
def __init__(self):
    super(Environment, self).__init__()
    self.action_space = ['up', 'down', 'left', 'right']
    self.n_actions = len(self.action_space)
    self.title('RL Q-learning. Sichkar Valentyn')
    self.geometry('{0}x{1}'.format(env_height * pixels, env_height * pixels))
    self.build_environment()
    print(self.geometry('{0}x{1}'.format(env_height * pixels, env_height * pixels)))
    # Dictionaries to draw the final route
    self.d = {}
    self.f = {}

    # Key for the dictionaries
    self.i = 0

    # Writing the final dictionary first time
    self.c = True

    # Showing the steps for longest found route
    self.longest = 0

    # Showing the steps for the shortest route
    self.shortest = 0

# Function to build the environment
def build_environment(self):
    self.canvas_widget = tk.Canvas(self,  bg='black',
                                   height=env_height * pixels,
                                   width=env_width * pixels)

    # Uploading an image for background
    # img_background = Image.open("images/bg.png")
    # self.background = ImageTk.PhotoImage(img_background)
    # # Creating background on the widget
    # self.bg = self.canvas_widget.create_image(0, 0, anchor='nw', image=self.background)

    # Creating grid lines
    for column in range(0, env_width * pixels, pixels):
        x0, y0, x1, y1 = column, 0, column, env_height * pixels
        self.canvas_widget.create_line(x0, y0, x1, y1, fill='grey')
    for row in range(0, env_height * pixels, pixels):
        x0, y0, x1, y1 = 0, row, env_height * pixels, row
        self.canvas_widget.create_line(x0, y0, x1, y1, fill='grey')
    self.canvas_widget.pack()    
if __name__ == '__main__':
env = Environment()
Run Code Online (Sandbox Code Playgroud)