Python 如何利用网格环境创建开放式健身房观察空间
我在Tkinter创建了一个环境,如何使用这个环境创建观察空间。我不明白如何使用数组中的网格坐标来生成观察空间,self.observation\u space=spaces.Box(np.array([]),np.array([]),dtype=np.int),给出了代码。如果有人帮助我,我将不胜感激Python 如何利用网格环境创建开放式健身房观察空间,python,artificial-intelligence,reinforcement-learning,openai-gym,Python,Artificial Intelligence,Reinforcement Learning,Openai Gym,我在Tkinter创建了一个环境,如何使用这个环境创建观察空间。我不明白如何使用数组中的网格坐标来生成观察空间,self.observation\u space=spaces.Box(np.array([]),np.array([]),dtype=np.int),给出了代码。如果有人帮助我,我将不胜感激 enter code here # Setting the sizes for the environment pixels = 40 # pixels env_height =9 #
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()