gridworldpy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gridworldpy/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
GridWorldPy - A Python package for creating and visualizing grid world environments.
|
|
3
|
+
|
|
4
|
+
This package provides a flexible and interactive grid world environment
|
|
5
|
+
for reinforcement learning experiments and educational purposes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .gridworld import GridWorldEnv
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
__author__ = "LIC"
|
|
12
|
+
__email__ = "liuchen.lic@gmail.com"
|
|
13
|
+
|
|
14
|
+
__all__ = ["GridWorldEnv"]
|
gridworldpy/gridworld.py
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import tkinter as tk
|
|
2
|
+
import numpy as np
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def value_to_rgb(value, vmin=-1.0, vmax=1.0, neutral=(200, 230, 255)):
|
|
7
|
+
"""
|
|
8
|
+
把 value 映射到 RGB:
|
|
9
|
+
- value <= vmin 映射为冰蓝 (0, 180, 255)
|
|
10
|
+
- value >= vmax 映射为火橙 (255, 100, 0)
|
|
11
|
+
- value = 0 映射为很浅的浅蓝 (200, 230, 255)
|
|
12
|
+
- 其他情况线性插值
|
|
13
|
+
"""
|
|
14
|
+
if vmin >= vmax:
|
|
15
|
+
raise ValueError("vmin must be < vmax")
|
|
16
|
+
|
|
17
|
+
# 裁剪
|
|
18
|
+
v = max(min(value, vmax), vmin)
|
|
19
|
+
|
|
20
|
+
if v == 0:
|
|
21
|
+
return neutral
|
|
22
|
+
|
|
23
|
+
if v < 0:
|
|
24
|
+
# 负值:浅蓝 (neutral) -> 冰蓝
|
|
25
|
+
t = v / vmin # vmin ≤ v ≤ 0, t ∈ [0,1]
|
|
26
|
+
cold = (0, 180, 255)
|
|
27
|
+
R = int(neutral[0] * (1 - t) + cold[0] * t)
|
|
28
|
+
G = int(neutral[1] * (1 - t) + cold[1] * t)
|
|
29
|
+
B = int(neutral[2] * (1 - t) + cold[2] * t)
|
|
30
|
+
else:
|
|
31
|
+
# 正值:浅蓝 (neutral) -> 火橙
|
|
32
|
+
t = v / vmax # 0 ≤ v ≤ vmax, t ∈ [0,1]
|
|
33
|
+
hot = (255, 100, 0)
|
|
34
|
+
R = int(neutral[0] * (1 - t) + hot[0] * t)
|
|
35
|
+
G = int(neutral[1] * (1 - t) + hot[1] * t)
|
|
36
|
+
B = int(neutral[2] * (1 - t) + hot[2] * t)
|
|
37
|
+
|
|
38
|
+
return (R, G, B)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def rgb_to_hex(rgb):
|
|
42
|
+
"""将RGB元组转换为十六进制颜色字符串"""
|
|
43
|
+
return f"#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def foreground_color(bg_rgb):
|
|
47
|
+
"""
|
|
48
|
+
给定背景色 RGB,返回黑或白中对比度更大的前景色
|
|
49
|
+
|
|
50
|
+
参数:
|
|
51
|
+
bg_rgb: tuple(int,int,int),背景颜色 (R, G, B),取值范围 0~255
|
|
52
|
+
|
|
53
|
+
返回:
|
|
54
|
+
tuple(int,int,int): 推荐的前景色 (R, G, B)
|
|
55
|
+
"""
|
|
56
|
+
def srgb_to_linear(c):
|
|
57
|
+
c = c / 255.0
|
|
58
|
+
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
|
|
59
|
+
|
|
60
|
+
def luminance(rgb):
|
|
61
|
+
r, g, b = [srgb_to_linear(v) for v in rgb]
|
|
62
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
63
|
+
|
|
64
|
+
def contrast(rgb1, rgb2):
|
|
65
|
+
L1, L2 = luminance(rgb1), luminance(rgb2)
|
|
66
|
+
L_light, L_dark = max(L1, L2), min(L1, L2)
|
|
67
|
+
return (L_light + 0.05) / (L_dark + 0.05)
|
|
68
|
+
|
|
69
|
+
black, white = (0, 0, 0), (255, 255, 255)
|
|
70
|
+
c_black = contrast(bg_rgb, black)
|
|
71
|
+
c_white = contrast(bg_rgb, white)
|
|
72
|
+
|
|
73
|
+
return black if c_black >= c_white else white
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class GridWorldEnv:
|
|
77
|
+
"""
|
|
78
|
+
一个简单的网格世界环境,支持自定义奖励、策略和状态禁用
|
|
79
|
+
使用tkinter进行可视化
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
def __init__(self, grid_size=(5, 5), render_mode="human", keyboard_control=True, terminal_condition=None,
|
|
83
|
+
cell_size=130, circle_radius=35, font_size=16, max_arrow_length=50):
|
|
84
|
+
"""
|
|
85
|
+
Args:
|
|
86
|
+
grid_size: (rows, cols) 网格大小
|
|
87
|
+
render_mode: 渲染模式,"human"表示可视化
|
|
88
|
+
keyboard_control: 是否启用键盘控制
|
|
89
|
+
terminal_condition: 终止条件
|
|
90
|
+
- None: 目标位置为右下角
|
|
91
|
+
- int: 最大步数限制
|
|
92
|
+
- tuple: 目标位置坐标 (x, y)
|
|
93
|
+
cell_size: 每个单元格的像素尺寸
|
|
94
|
+
circle_radius: 显示奖励/价值的圆半径
|
|
95
|
+
font_size: 圆内文本字号
|
|
96
|
+
max_arrow_length: 策略箭头最大长度
|
|
97
|
+
"""
|
|
98
|
+
self.grid_size = grid_size
|
|
99
|
+
self.render_mode = render_mode
|
|
100
|
+
self.keyboard_control = keyboard_control
|
|
101
|
+
|
|
102
|
+
# 动作空间:停留(0), 上(1), 下(2), 左(3), 右(4)
|
|
103
|
+
self.action_space_n = 5
|
|
104
|
+
|
|
105
|
+
# 初始状态(位置)
|
|
106
|
+
self.start_pos = (0, 0)
|
|
107
|
+
|
|
108
|
+
# 设置终止条件
|
|
109
|
+
if terminal_condition is None:
|
|
110
|
+
# 默认:目标位置为右下角
|
|
111
|
+
self.terminal_condition = (grid_size[0]-1, grid_size[1]-1)
|
|
112
|
+
self.goal_pos = self.terminal_condition
|
|
113
|
+
self.max_steps = None
|
|
114
|
+
elif isinstance(terminal_condition, int):
|
|
115
|
+
# 整数:最大步数限制
|
|
116
|
+
self.terminal_condition = terminal_condition
|
|
117
|
+
self.goal_pos = None
|
|
118
|
+
self.max_steps = terminal_condition
|
|
119
|
+
elif isinstance(terminal_condition, tuple):
|
|
120
|
+
# 元组:目标位置坐标
|
|
121
|
+
self.terminal_condition = terminal_condition
|
|
122
|
+
self.goal_pos = terminal_condition
|
|
123
|
+
self.max_steps = None
|
|
124
|
+
else:
|
|
125
|
+
raise ValueError("terminal_condition must be None, int (max_steps), or tuple (goal_position)")
|
|
126
|
+
|
|
127
|
+
self.state = self.start_pos
|
|
128
|
+
self.step_count = 0
|
|
129
|
+
|
|
130
|
+
# 初始化奖励矩阵 - 每个cell的奖励值
|
|
131
|
+
self.rewards = np.zeros(grid_size)
|
|
132
|
+
|
|
133
|
+
# 初始化策略矩阵 - 每个cell的动作概率分布 [停留,上,下,左,右]
|
|
134
|
+
self.policy = None # 初始化放在 set_policy 方法之中
|
|
135
|
+
|
|
136
|
+
# 初始化禁用状态集合
|
|
137
|
+
self.disabled_states = set()
|
|
138
|
+
|
|
139
|
+
# 键盘控制相关
|
|
140
|
+
self.space_pressed = False
|
|
141
|
+
|
|
142
|
+
# 记录上一步动作
|
|
143
|
+
self.previous_action = None
|
|
144
|
+
|
|
145
|
+
# 可视化初始化
|
|
146
|
+
self.cell_size = cell_size
|
|
147
|
+
self.circle_radius = circle_radius
|
|
148
|
+
self.max_arrow_length = max_arrow_length
|
|
149
|
+
self.font_size = font_size
|
|
150
|
+
|
|
151
|
+
# tkinter相关
|
|
152
|
+
self.root = None
|
|
153
|
+
self.canvas = None
|
|
154
|
+
self._current_state_values = None
|
|
155
|
+
self._last_circle_color_rgb = None
|
|
156
|
+
self.is_closed = False # 添加一个标志来表示窗口是否关闭
|
|
157
|
+
|
|
158
|
+
if self.render_mode == "human":
|
|
159
|
+
self._init_gui()
|
|
160
|
+
|
|
161
|
+
def _init_gui(self):
|
|
162
|
+
"""初始化tkinter GUI"""
|
|
163
|
+
self.root = tk.Tk()
|
|
164
|
+
self.root.title("GridWorld")
|
|
165
|
+
if self.keyboard_control:
|
|
166
|
+
self.root.title("GridWorld - 按空格键执行下一步")
|
|
167
|
+
self.root.wm_attributes('-topmost', 1)
|
|
168
|
+
|
|
169
|
+
# 设置窗口大小
|
|
170
|
+
width = self.grid_size[1] * self.cell_size
|
|
171
|
+
height = self.grid_size[0] * self.cell_size + 50 # 额外空间用于显示信息
|
|
172
|
+
|
|
173
|
+
# 计算屏幕中心位置
|
|
174
|
+
screen_width = self.root.winfo_screenwidth()
|
|
175
|
+
screen_height = self.root.winfo_screenheight()
|
|
176
|
+
x = (screen_width - width) // 2
|
|
177
|
+
y = (screen_height - height) // 2
|
|
178
|
+
|
|
179
|
+
self.root.geometry(f"{width}x{height}+{x}+{y}")
|
|
180
|
+
self.root.resizable(False, False)
|
|
181
|
+
|
|
182
|
+
# 创建信息标签
|
|
183
|
+
self.info_label = tk.Label(self.root, text="Steps: 0", font=('Arial', 12))
|
|
184
|
+
self.info_label.pack()
|
|
185
|
+
|
|
186
|
+
# 创建画布
|
|
187
|
+
self.canvas = tk.Canvas(self.root, width=width, height=height-50, bg='white')
|
|
188
|
+
self.canvas.pack()
|
|
189
|
+
|
|
190
|
+
# 绑定键盘事件
|
|
191
|
+
if self.keyboard_control:
|
|
192
|
+
self.root.bind('<KeyPress-space>', self._on_space_press)
|
|
193
|
+
self.root.focus_set() # 确保窗口能接收键盘事件
|
|
194
|
+
# 处理窗口关闭事件
|
|
195
|
+
self.root.protocol("WM_DELETE_WINDOW", self.close)
|
|
196
|
+
|
|
197
|
+
def _on_space_press(self, event):
|
|
198
|
+
"""空格键事件处理"""
|
|
199
|
+
self.space_pressed = True
|
|
200
|
+
|
|
201
|
+
def get_current_policy(self,):
|
|
202
|
+
"""获取当前策略"""
|
|
203
|
+
return self.policy[self.state]
|
|
204
|
+
|
|
205
|
+
def set_rewards(self, reward_config):
|
|
206
|
+
"""设置或更新奖励
|
|
207
|
+
Args:
|
|
208
|
+
reward_config:
|
|
209
|
+
- 'random': 随机设置奖励
|
|
210
|
+
- list: [(x,y,reward), ...] 指定坐标和奖励的列表
|
|
211
|
+
"""
|
|
212
|
+
if reward_config == 'random':
|
|
213
|
+
self.rewards = np.random.uniform(-1, 1, self.grid_size)
|
|
214
|
+
elif isinstance(reward_config, list):
|
|
215
|
+
for x, y, reward in reward_config:
|
|
216
|
+
if 0 <= x < self.grid_size[0] and 0 <= y < self.grid_size[1]:
|
|
217
|
+
self.rewards[x, y] = reward
|
|
218
|
+
|
|
219
|
+
def set_policy(self, policy_config):
|
|
220
|
+
"""设置或更新策略
|
|
221
|
+
Args:
|
|
222
|
+
policy_config:
|
|
223
|
+
- 'random': 随机设置每个cell的动作概率
|
|
224
|
+
- list: [(x,y,[keep,up,down,left,right]), ...] 指定坐标和概率的列表
|
|
225
|
+
"""
|
|
226
|
+
# 若策略未初始化,则使用均匀分布
|
|
227
|
+
if self.policy is None:
|
|
228
|
+
self.policy = np.ones((self.grid_size[0], self.grid_size[1], 5)) * 0.2
|
|
229
|
+
|
|
230
|
+
if policy_config == 'random':
|
|
231
|
+
# 为每个cell随机生成概率分布
|
|
232
|
+
for i in range(self.grid_size[0]):
|
|
233
|
+
for j in range(self.grid_size[1]):
|
|
234
|
+
probs = np.random.uniform(0, 1, 5)
|
|
235
|
+
probs = probs / np.sum(probs) # 归一化
|
|
236
|
+
self.policy[i, j] = probs
|
|
237
|
+
elif isinstance(policy_config, list):
|
|
238
|
+
for x, y, probs in policy_config:
|
|
239
|
+
if 0 <= x < self.grid_size[0] and 0 <= y < self.grid_size[1]:
|
|
240
|
+
assert len(probs) == 5, "Policy must have 5 values: [keep, up, down, left, right]"
|
|
241
|
+
probs = np.array(probs)
|
|
242
|
+
if np.sum(probs) > 0:
|
|
243
|
+
self.policy[x, y] = probs / np.sum(probs) # 归一化
|
|
244
|
+
else:
|
|
245
|
+
# 所有概率都为0,保持为0
|
|
246
|
+
self.policy[x, y] = probs
|
|
247
|
+
|
|
248
|
+
# 调整禁用状态的概率分布
|
|
249
|
+
self._adjust_policy_for_disabled_states()
|
|
250
|
+
|
|
251
|
+
def disable_states(self, disabled_poses):
|
|
252
|
+
"""禁用指定坐标的状态
|
|
253
|
+
Args:
|
|
254
|
+
disabled_poses: [(x,y), ...] 要禁用的坐标列表
|
|
255
|
+
"""
|
|
256
|
+
self.disabled_states = set()
|
|
257
|
+
for x, y in disabled_poses:
|
|
258
|
+
if 0 <= x < self.grid_size[0] and 0 <= y < self.grid_size[1]:
|
|
259
|
+
self.disabled_states.add((x, y))
|
|
260
|
+
|
|
261
|
+
# 调整策略概率分布
|
|
262
|
+
if self.policy is not None:
|
|
263
|
+
self._adjust_policy_for_disabled_states()
|
|
264
|
+
|
|
265
|
+
def _adjust_policy_for_disabled_states(self):
|
|
266
|
+
"""调整策略,将转移到禁用状态或边界外的概率添加到停留(keep)动作的概率上"""
|
|
267
|
+
for i in range(self.grid_size[0]):
|
|
268
|
+
for j in range(self.grid_size[1]):
|
|
269
|
+
if (i, j) in self.disabled_states:
|
|
270
|
+
self.policy[i, j] = np.zeros(5) # 禁用状态无动作
|
|
271
|
+
continue
|
|
272
|
+
|
|
273
|
+
# 获取当前策略 [keep, up, down, left, right]
|
|
274
|
+
current_policy = self.policy[i, j].copy()
|
|
275
|
+
blocked_prob = 0.0
|
|
276
|
+
|
|
277
|
+
# 检查上方动作 (index 1)
|
|
278
|
+
next_x = i - 1
|
|
279
|
+
if next_x < 0 or (next_x, j) in self.disabled_states:
|
|
280
|
+
blocked_prob += current_policy[1]
|
|
281
|
+
current_policy[1] = 0
|
|
282
|
+
|
|
283
|
+
# 检查下方动作 (index 2)
|
|
284
|
+
next_x = i + 1
|
|
285
|
+
if next_x >= self.grid_size[0] or (next_x, j) in self.disabled_states:
|
|
286
|
+
blocked_prob += current_policy[2]
|
|
287
|
+
current_policy[2] = 0
|
|
288
|
+
|
|
289
|
+
# 检查左方动作 (index 3)
|
|
290
|
+
next_y = j - 1
|
|
291
|
+
if next_y < 0 or (i, next_y) in self.disabled_states:
|
|
292
|
+
blocked_prob += current_policy[3]
|
|
293
|
+
current_policy[3] = 0
|
|
294
|
+
|
|
295
|
+
# 检查右方动作 (index 4)
|
|
296
|
+
next_y = j + 1
|
|
297
|
+
if next_y >= self.grid_size[1] or (i, next_y) in self.disabled_states:
|
|
298
|
+
blocked_prob += current_policy[4]
|
|
299
|
+
current_policy[4] = 0
|
|
300
|
+
|
|
301
|
+
# 将所有被阻挡的概率加到keep动作上 (index 0)
|
|
302
|
+
current_policy[0] += blocked_prob
|
|
303
|
+
|
|
304
|
+
self.policy[i, j] = current_policy
|
|
305
|
+
|
|
306
|
+
def _get_obs(self):
|
|
307
|
+
return self.state
|
|
308
|
+
|
|
309
|
+
def step(self, action):
|
|
310
|
+
"""
|
|
311
|
+
Args:
|
|
312
|
+
action: 动作索引 0-4
|
|
313
|
+
Returns: (observation, reward, terminated, info)
|
|
314
|
+
"""
|
|
315
|
+
self.step_count += 1 # 更新步数
|
|
316
|
+
info = {} # 保存返回信息的字典
|
|
317
|
+
# 离开上一状态后得到的奖励
|
|
318
|
+
received_reward = self.rewards[self.state]
|
|
319
|
+
info['previous_state'] = self.state
|
|
320
|
+
|
|
321
|
+
x, y = self.state
|
|
322
|
+
new_x, new_y = x, y
|
|
323
|
+
|
|
324
|
+
if action == 0: # 停留
|
|
325
|
+
pass # 保持当前位置
|
|
326
|
+
elif action == 1: # 上
|
|
327
|
+
new_x = max(x-1, 0)
|
|
328
|
+
elif action == 2: # 下
|
|
329
|
+
new_x = min(x+1, self.grid_size[0]-1)
|
|
330
|
+
elif action == 3: # 左
|
|
331
|
+
new_y = max(y-1, 0)
|
|
332
|
+
elif action == 4: # 右
|
|
333
|
+
new_y = min(y+1, self.grid_size[1]-1)
|
|
334
|
+
|
|
335
|
+
# 如果新位置被禁用,保持在当前位置
|
|
336
|
+
if (new_x, new_y) not in self.disabled_states:
|
|
337
|
+
self.state = (new_x, new_y)
|
|
338
|
+
|
|
339
|
+
# 检查终止条件
|
|
340
|
+
done = False
|
|
341
|
+
if self.goal_pos is not None:
|
|
342
|
+
# 基于目标位置的终止
|
|
343
|
+
done = self.state == self.goal_pos
|
|
344
|
+
if done:
|
|
345
|
+
info['exit_reason'] = 'done'
|
|
346
|
+
elif self.max_steps is not None:
|
|
347
|
+
# 基于最大步数的终止
|
|
348
|
+
done = self.step_count >= self.max_steps
|
|
349
|
+
if done:
|
|
350
|
+
info['exit_reason'] = 'max_steps'
|
|
351
|
+
else:
|
|
352
|
+
info['exit_reason'] = 'unknown_reason'
|
|
353
|
+
|
|
354
|
+
# 当前状态的奖励
|
|
355
|
+
info['current_reward'] = self.rewards[self.state]
|
|
356
|
+
info['current_state'] = self.state
|
|
357
|
+
info['step_count'] = self.step_count
|
|
358
|
+
info['current_action'] = action
|
|
359
|
+
info['previous_action'] = self.previous_action
|
|
360
|
+
self.previous_action = action
|
|
361
|
+
# observation, reward, terminated, info
|
|
362
|
+
return self._get_obs(), received_reward, done, info
|
|
363
|
+
|
|
364
|
+
def render(self, state_values=None, policy_config=None, reward_config=None):
|
|
365
|
+
"""
|
|
366
|
+
渲染环境
|
|
367
|
+
Args:
|
|
368
|
+
state_values: 可选的状态价值列表,格式为[(x, y, value), ...]
|
|
369
|
+
policy_config: 设置或更新策略
|
|
370
|
+
- 'random': 随机设置每个cell的动作概率
|
|
371
|
+
- list: [(x,y,[keep,up,down,left,right]), ...] 指定坐标和概率的列表
|
|
372
|
+
reward_config: 设置或更新奖励
|
|
373
|
+
- 'random': 随机设置奖励
|
|
374
|
+
- list: [(x,y,reward), ...] 指定坐标和奖励的列表
|
|
375
|
+
"""
|
|
376
|
+
if self.render_mode != "human" or self.is_closed:
|
|
377
|
+
return
|
|
378
|
+
|
|
379
|
+
# 更新策略
|
|
380
|
+
if policy_config is not None:
|
|
381
|
+
self.set_policy(policy_config)
|
|
382
|
+
|
|
383
|
+
# 更新奖励
|
|
384
|
+
if reward_config is not None:
|
|
385
|
+
self.set_rewards(reward_config)
|
|
386
|
+
|
|
387
|
+
# 存储状态价值以便在绘制时使用
|
|
388
|
+
self._current_state_values = state_values
|
|
389
|
+
|
|
390
|
+
if self.keyboard_control:
|
|
391
|
+
self._render_and_wait_for_keyboard()
|
|
392
|
+
else:
|
|
393
|
+
self._render_once()
|
|
394
|
+
|
|
395
|
+
def _render_once(self):
|
|
396
|
+
"""渲染一次,不等待输入"""
|
|
397
|
+
if self.canvas is None or self.is_closed:
|
|
398
|
+
return
|
|
399
|
+
try:
|
|
400
|
+
self._draw_screen()
|
|
401
|
+
if self.root:
|
|
402
|
+
self.root.update()
|
|
403
|
+
except tk.TclError:
|
|
404
|
+
self.is_closed = True
|
|
405
|
+
|
|
406
|
+
def _render_and_wait_for_keyboard(self):
|
|
407
|
+
"""渲染并等待空格键输入"""
|
|
408
|
+
if self.canvas is None or self.is_closed:
|
|
409
|
+
return
|
|
410
|
+
|
|
411
|
+
self.space_pressed = False
|
|
412
|
+
self._draw_screen()
|
|
413
|
+
|
|
414
|
+
while not self.space_pressed and not self.is_closed:
|
|
415
|
+
try:
|
|
416
|
+
if self.root:
|
|
417
|
+
self.root.update_idletasks()
|
|
418
|
+
self.root.update()
|
|
419
|
+
time.sleep(0.01) # 小延时避免CPU过度使用
|
|
420
|
+
except tk.TclError:
|
|
421
|
+
# 窗口已关闭
|
|
422
|
+
self.is_closed = True
|
|
423
|
+
break
|
|
424
|
+
|
|
425
|
+
def _draw_screen(self):
|
|
426
|
+
"""绘制整个屏幕"""
|
|
427
|
+
if self.canvas is None:
|
|
428
|
+
return
|
|
429
|
+
|
|
430
|
+
# 清空画布
|
|
431
|
+
self.canvas.delete("all")
|
|
432
|
+
|
|
433
|
+
# 绘制网格和cell内容
|
|
434
|
+
for i in range(self.grid_size[0]):
|
|
435
|
+
for j in range(self.grid_size[1]):
|
|
436
|
+
self._draw_cell(i, j)
|
|
437
|
+
|
|
438
|
+
# 绘制智能体
|
|
439
|
+
self._draw_agent()
|
|
440
|
+
|
|
441
|
+
# 更新信息标签
|
|
442
|
+
self.info_label.config(text=f"Steps: {self.step_count}")
|
|
443
|
+
|
|
444
|
+
def _draw_cell(self, i, j):
|
|
445
|
+
"""绘制单个格子"""
|
|
446
|
+
x_pixel = j * self.cell_size
|
|
447
|
+
y_pixel = i * self.cell_size
|
|
448
|
+
center_x = x_pixel + self.cell_size // 2
|
|
449
|
+
center_y = y_pixel + self.cell_size // 2
|
|
450
|
+
|
|
451
|
+
# 确定背景颜色
|
|
452
|
+
if (i, j) in self.disabled_states:
|
|
453
|
+
bg_color = "gray"
|
|
454
|
+
elif self.goal_pos is not None and (i, j) == self.goal_pos:
|
|
455
|
+
bg_color = "yellow"
|
|
456
|
+
else:
|
|
457
|
+
bg_color = "white"
|
|
458
|
+
|
|
459
|
+
# 绘制格子背景
|
|
460
|
+
self.canvas.create_rectangle(
|
|
461
|
+
x_pixel, y_pixel, x_pixel + self.cell_size, y_pixel + self.cell_size,
|
|
462
|
+
fill=bg_color, outline="lightgray", width=2
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
# 如果不是禁用状态,绘制奖励圆和策略箭头
|
|
466
|
+
if (i, j) not in self.disabled_states:
|
|
467
|
+
self._draw_reward_circle(i, j, center_x, center_y)
|
|
468
|
+
self._draw_policy_arrows(i, j, center_x, center_y)
|
|
469
|
+
self._draw_cell_text(i, j, center_x, center_y)
|
|
470
|
+
|
|
471
|
+
def _draw_reward_circle(self, i, j, center_x, center_y):
|
|
472
|
+
"""绘制奖励圆圈"""
|
|
473
|
+
reward_val = self.rewards[i, j]
|
|
474
|
+
|
|
475
|
+
# 获取状态价值
|
|
476
|
+
state_value = None
|
|
477
|
+
if self._current_state_values is not None:
|
|
478
|
+
for x, y, value in self._current_state_values:
|
|
479
|
+
if x == i and y == j:
|
|
480
|
+
state_value = value
|
|
481
|
+
break
|
|
482
|
+
|
|
483
|
+
if self._current_state_values is not None:
|
|
484
|
+
# 当有状态价值时,根据状态价值映射颜色
|
|
485
|
+
if state_value is not None:
|
|
486
|
+
circle_color_rgb = value_to_rgb(state_value)
|
|
487
|
+
circle_color = rgb_to_hex(circle_color_rgb)
|
|
488
|
+
else:
|
|
489
|
+
circle_color_rgb = (150, 150, 150)
|
|
490
|
+
circle_color = rgb_to_hex(circle_color_rgb)
|
|
491
|
+
else:
|
|
492
|
+
# 当没有状态价值时,根据奖励值映射到颜色
|
|
493
|
+
circle_color_rgb = value_to_rgb(reward_val)
|
|
494
|
+
circle_color = rgb_to_hex(circle_color_rgb)
|
|
495
|
+
|
|
496
|
+
# 绘制圆圈
|
|
497
|
+
radius = self.circle_radius
|
|
498
|
+
self.canvas.create_oval(
|
|
499
|
+
center_x - radius, center_y - radius,
|
|
500
|
+
center_x + radius, center_y + radius,
|
|
501
|
+
fill=circle_color, outline="black", width=1
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
# 存储颜色信息用于文本颜色计算
|
|
505
|
+
self._last_circle_color_rgb = circle_color_rgb
|
|
506
|
+
|
|
507
|
+
def _draw_one_arrow(self, x0, y0, x1, y1, arrow_color, outline_color):
|
|
508
|
+
"""绘制带轮廓的箭头"""
|
|
509
|
+
self.canvas.create_line(x0, y0, x1, y1, fill=outline_color, width=5, arrow=tk.LAST)
|
|
510
|
+
self.canvas.create_line(x0, y0, x1, y1, fill=arrow_color, width=3, arrow=tk.LAST)
|
|
511
|
+
|
|
512
|
+
def _draw_policy_arrows(self, i, j, center_x, center_y):
|
|
513
|
+
"""绘制策略箭头"""
|
|
514
|
+
if self.policy is None:
|
|
515
|
+
return
|
|
516
|
+
|
|
517
|
+
probs = self.policy[i, j]
|
|
518
|
+
max_arrow_length = self.max_arrow_length
|
|
519
|
+
min_prob_threshold = 0.001 # 最小概率阈值,低于此值不显示箭头
|
|
520
|
+
arrow_color = "lightgreen"
|
|
521
|
+
outline_color = "black"
|
|
522
|
+
|
|
523
|
+
# 显示keep概率(在圆圈中心附近显示一个小点)
|
|
524
|
+
if probs[0] > min_prob_threshold:
|
|
525
|
+
keep_radius = int(self.max_arrow_length/2 * probs[0]) # 根据概率调整点的大小
|
|
526
|
+
if keep_radius > 1:
|
|
527
|
+
self.canvas.create_oval(
|
|
528
|
+
center_x - keep_radius, center_y - keep_radius,
|
|
529
|
+
center_x + keep_radius, center_y + keep_radius,
|
|
530
|
+
fill=arrow_color, outline=arrow_color
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
# 上箭头 (index 1)
|
|
534
|
+
if probs[1] > min_prob_threshold:
|
|
535
|
+
length = int(max_arrow_length * probs[1])
|
|
536
|
+
if length > 3:
|
|
537
|
+
start_y = center_y - self.circle_radius
|
|
538
|
+
end_y = start_y - length
|
|
539
|
+
self._draw_one_arrow(center_x, start_y, center_x, end_y, arrow_color, outline_color)
|
|
540
|
+
|
|
541
|
+
# 下箭头 (index 2)
|
|
542
|
+
if probs[2] > min_prob_threshold:
|
|
543
|
+
length = int(max_arrow_length * probs[2])
|
|
544
|
+
if length > 3:
|
|
545
|
+
start_y = center_y + self.circle_radius
|
|
546
|
+
end_y = start_y + length
|
|
547
|
+
self._draw_one_arrow(center_x, start_y, center_x, end_y, arrow_color, outline_color)
|
|
548
|
+
|
|
549
|
+
# 左箭头 (index 3)
|
|
550
|
+
if probs[3] > min_prob_threshold:
|
|
551
|
+
length = int(max_arrow_length * probs[3])
|
|
552
|
+
if length > 3:
|
|
553
|
+
start_x = center_x - self.circle_radius
|
|
554
|
+
end_x = start_x - length
|
|
555
|
+
self._draw_one_arrow(start_x, center_y, end_x, center_y, arrow_color, outline_color)
|
|
556
|
+
|
|
557
|
+
# 右箭头 (index 4)
|
|
558
|
+
if probs[4] > min_prob_threshold:
|
|
559
|
+
length = int(max_arrow_length * probs[4])
|
|
560
|
+
if length > 3:
|
|
561
|
+
start_x = center_x + self.circle_radius
|
|
562
|
+
end_x = start_x + length
|
|
563
|
+
self._draw_one_arrow(start_x, center_y, end_x, center_y, arrow_color, outline_color)
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
def _draw_cell_text(self, i, j, center_x, center_y):
|
|
567
|
+
"""在格子中绘制文本(奖励和状态价值)"""
|
|
568
|
+
reward_val = self.rewards[i, j]
|
|
569
|
+
|
|
570
|
+
# 获取状态价值
|
|
571
|
+
state_value = None
|
|
572
|
+
if self._current_state_values is not None:
|
|
573
|
+
for x, y, value in self._current_state_values:
|
|
574
|
+
if x == i and y == j:
|
|
575
|
+
state_value = value
|
|
576
|
+
break
|
|
577
|
+
|
|
578
|
+
# 确定文本颜色
|
|
579
|
+
if self._last_circle_color_rgb is not None:
|
|
580
|
+
text_color_rgb = foreground_color(self._last_circle_color_rgb)
|
|
581
|
+
text_color = rgb_to_hex(text_color_rgb)
|
|
582
|
+
else:
|
|
583
|
+
text_color = "black"
|
|
584
|
+
|
|
585
|
+
font_size = self.font_size - 2 if state_value is not None else self.font_size
|
|
586
|
+
|
|
587
|
+
if state_value is not None:
|
|
588
|
+
# 显示两行:奖励和状态价值
|
|
589
|
+
reward_text = f"R: {reward_val: .2f}"
|
|
590
|
+
value_text = f"V: {state_value: .2f}"
|
|
591
|
+
|
|
592
|
+
# 第一行(奖励)
|
|
593
|
+
self.canvas.create_text(
|
|
594
|
+
center_x, center_y - font_size//2,
|
|
595
|
+
text=reward_text, fill=text_color, font=('Arial', font_size)
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
# 第二行(状态价值)
|
|
599
|
+
self.canvas.create_text(
|
|
600
|
+
center_x, center_y + font_size//2,
|
|
601
|
+
text=value_text, fill=text_color, font=('Arial', font_size)
|
|
602
|
+
)
|
|
603
|
+
else:
|
|
604
|
+
# 只显示奖励
|
|
605
|
+
reward_text = f"R: {reward_val: .2f}"
|
|
606
|
+
self.canvas.create_text(
|
|
607
|
+
center_x, center_y,
|
|
608
|
+
text=reward_text, fill=text_color, font=('Arial', font_size)
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
def _draw_agent(self):
|
|
612
|
+
"""绘制智能体"""
|
|
613
|
+
agent_center_x = self.state[1] * self.cell_size + self.cell_size // 2
|
|
614
|
+
agent_center_y = self.state[0] * self.cell_size + self.cell_size // 2
|
|
615
|
+
|
|
616
|
+
# 绘制红色圆圈轮廓表示智能体
|
|
617
|
+
radius = self.circle_radius + 5
|
|
618
|
+
self.canvas.create_oval(
|
|
619
|
+
agent_center_x - radius, agent_center_y - radius,
|
|
620
|
+
agent_center_x + radius, agent_center_y + radius,
|
|
621
|
+
outline="red", width=3, fill=""
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
def close(self):
|
|
625
|
+
"""关闭环境"""
|
|
626
|
+
if self.root is not None and not self.is_closed:
|
|
627
|
+
self.is_closed = True
|
|
628
|
+
try:
|
|
629
|
+
self.root.destroy()
|
|
630
|
+
except tk.TclError:
|
|
631
|
+
# 捕获当根窗口已销毁时可能发生的 TclError
|
|
632
|
+
pass
|
|
633
|
+
self.root = None
|
|
634
|
+
self.canvas = None
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 GridWorldPy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gridworldpy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A flexible and interactive grid world environment for reinforcement learning
|
|
5
|
+
Home-page: https://github.com/hitlic/gridworldpy
|
|
6
|
+
Author: LIC
|
|
7
|
+
Author-email: LIC <liuchen.lic@gmail.com>
|
|
8
|
+
Maintainer-email: LIC <liuchen.lic@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://github.com/hitlic/gridworldpy
|
|
11
|
+
Project-URL: Repository, https://github.com/hitlic/gridworldpy
|
|
12
|
+
Project-URL: Documentation, https://github.com/hitlic/gridworldpy#readme
|
|
13
|
+
Project-URL: Bug Reports, https://github.com/hitlic/gridworldpy/issues
|
|
14
|
+
Keywords: reinforcement learning,grid world,environment,RL,AI,machine learning,visualization
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Education
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: numpy >=1.21.0
|
|
32
|
+
Provides-Extra: examples
|
|
33
|
+
Requires-Dist: matplotlib >=3.5.0 ; extra == 'examples'
|
|
34
|
+
|
|
35
|
+
# GridWorldPy
|
|
36
|
+
|
|
37
|
+
[](https://badge.fury.io/py/gridworldpy)
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
|
|
41
|
+
一个灵活且交互式的网格世界环境,专为强化学习实验和教育目的设计。
|
|
42
|
+
|
|
43
|
+
## ✨ 特性
|
|
44
|
+
|
|
45
|
+
- 🎯 **灵活的环境配置**:支持自定义网格大小、奖励函数和终止条件
|
|
46
|
+
- 🎨 **实时可视化**:基于tkinter的直观图形界面,支持实时渲染
|
|
47
|
+
- ⚡ **交互控制**:支持键盘控制和自动执行模式
|
|
48
|
+
- 🎮 **策略可视化**:直观显示动作概率分布和状态价值
|
|
49
|
+
- 🚫 **状态禁用**:支持禁用特定状态创建障碍物
|
|
50
|
+
- 📊 **颜色映射**:根据奖励值和状态价值自动调整颜色显示
|
|
51
|
+
|
|
52
|
+
## 🚀 安装
|
|
53
|
+
|
|
54
|
+
使用pip从PyPI安装:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install gridworldpy
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
或者从源码安装:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/hitlic/gridworldpy.git
|
|
64
|
+
cd gridworldpy
|
|
65
|
+
pip install -e .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 📖 快速开始
|
|
69
|
+
|
|
70
|
+
### 基本使用
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import numpy as np
|
|
74
|
+
from gridworldpy import GridWorldEnv
|
|
75
|
+
|
|
76
|
+
# 创建一个5x5的网格世界
|
|
77
|
+
env = GridWorldEnv(grid_size=(5, 5))
|
|
78
|
+
|
|
79
|
+
# 设置随机奖励
|
|
80
|
+
env.set_rewards('random')
|
|
81
|
+
|
|
82
|
+
# 设置随机策略
|
|
83
|
+
env.set_policy('random')
|
|
84
|
+
|
|
85
|
+
# 渲染环境
|
|
86
|
+
env.render()
|
|
87
|
+
|
|
88
|
+
# 执行一个动作
|
|
89
|
+
obs, reward, done, info = env.step(1) # 向上移动
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 自定义配置
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# 创建带自定义配置的环境
|
|
96
|
+
env = GridWorldEnv(
|
|
97
|
+
grid_size=(4, 4),
|
|
98
|
+
keyboard_control=True, # 启用键盘控制
|
|
99
|
+
terminal_condition=(3, 3), # 目标位置为(3,3)
|
|
100
|
+
cell_size=150, # 每个格子150像素
|
|
101
|
+
circle_radius=40, # 奖励圆圈半径40像素
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# 设置特定位置的奖励
|
|
105
|
+
rewards = [
|
|
106
|
+
(0, 0, -0.1), # 起始位置小负奖励
|
|
107
|
+
(1, 1, -1.0), # 陷阱:大负奖励
|
|
108
|
+
(3, 3, 1.0), # 目标:大正奖励
|
|
109
|
+
]
|
|
110
|
+
env.set_rewards(rewards)
|
|
111
|
+
|
|
112
|
+
# 设置特定的策略
|
|
113
|
+
policy = [
|
|
114
|
+
(0, 0, [0.1, 0.2, 0.2, 0.2, 0.3]), # 位置(0,0)的动作概率
|
|
115
|
+
(1, 0, [0.0, 0.0, 0.5, 0.0, 0.5]), # 位置(1,0)的动作概率
|
|
116
|
+
]
|
|
117
|
+
env.set_policy(policy)
|
|
118
|
+
|
|
119
|
+
# 禁用某些状态(创建障碍物)
|
|
120
|
+
env.disable_states([(1, 2), (2, 1)])
|
|
121
|
+
|
|
122
|
+
# 渲染环境
|
|
123
|
+
env.render()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 带状态价值的可视化
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# 创建状态价值列表
|
|
130
|
+
state_values = [
|
|
131
|
+
(0, 0, 0.1), (0, 1, 0.2), (0, 2, 0.3),
|
|
132
|
+
(1, 0, 0.4), (1, 1, -0.5), (1, 2, 0.6),
|
|
133
|
+
(2, 0, 0.7), (2, 1, 0.8), (2, 2, 0.9),
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
# 渲染时包含状态价值
|
|
137
|
+
env.render(state_values=state_values)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 🎮 控制方式
|
|
141
|
+
|
|
142
|
+
### 键盘控制模式
|
|
143
|
+
|
|
144
|
+
当`keyboard_control=True`时,使用空格键控制执行:
|
|
145
|
+
|
|
146
|
+
- 按**空格键**执行下一步
|
|
147
|
+
- 窗口会显示当前步数和环境状态
|
|
148
|
+
- 程序会等待用户输入后继续
|
|
149
|
+
|
|
150
|
+
### 自动模式
|
|
151
|
+
|
|
152
|
+
当`keyboard_control=False`时,可以连续调用`render()`方法:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
for step in range(10):
|
|
156
|
+
action = np.random.randint(0, 5) # 随机选择动作
|
|
157
|
+
obs, reward, done, info = env.step(action)
|
|
158
|
+
env.render()
|
|
159
|
+
if done:
|
|
160
|
+
break
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 🎯 API 参考
|
|
164
|
+
|
|
165
|
+
### GridWorldEnv
|
|
166
|
+
|
|
167
|
+
主要的环境类,提供网格世界的完整功能。
|
|
168
|
+
|
|
169
|
+
#### 构造函数
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
GridWorldEnv(
|
|
173
|
+
grid_size=(5, 5), # 网格大小 (行, 列)
|
|
174
|
+
render_mode="human", # 渲染模式
|
|
175
|
+
keyboard_control=True, # 是否启用键盘控制
|
|
176
|
+
terminal_condition=None, # 终止条件
|
|
177
|
+
cell_size=130, # 每个格子的像素大小
|
|
178
|
+
circle_radius=35, # 奖励圆圈半径
|
|
179
|
+
font_size=16, # 字体大小
|
|
180
|
+
max_arrow_length=50 # 策略箭头最大长度
|
|
181
|
+
)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### 主要方法
|
|
185
|
+
|
|
186
|
+
- `step(action)`: 执行动作,返回(observation, reward, done, info)
|
|
187
|
+
- `render(state_values=None, policy_config=None, reward_config=None)`: 渲染环境
|
|
188
|
+
- `set_rewards(reward_config)`: 设置奖励配置
|
|
189
|
+
- `set_policy(policy_config)`: 设置策略配置
|
|
190
|
+
- `disable_states(disabled_poses)`: 禁用指定状态
|
|
191
|
+
- `close()`: 关闭环境
|
|
192
|
+
|
|
193
|
+
#### 动作空间
|
|
194
|
+
|
|
195
|
+
- 0: 停留在当前位置
|
|
196
|
+
- 1: 向上移动
|
|
197
|
+
- 2: 向下移动
|
|
198
|
+
- 3: 向左移动
|
|
199
|
+
- 4: 向右移动
|
|
200
|
+
|
|
201
|
+
## 🎨 可视化说明
|
|
202
|
+
|
|
203
|
+
### 颜色编码
|
|
204
|
+
|
|
205
|
+
- **冰蓝色**: 负值(奖励或状态价值)
|
|
206
|
+
- **火橙色**: 正值(奖励或状态价值)
|
|
207
|
+
- **浅蓝色**: 零值或中性值
|
|
208
|
+
- **黄色**: 目标状态
|
|
209
|
+
- **灰色**: 禁用状态
|
|
210
|
+
- **红色边框**: 智能体当前位置
|
|
211
|
+
|
|
212
|
+
### 显示元素
|
|
213
|
+
|
|
214
|
+
- **圆圈**: 显示奖励值和状态价值
|
|
215
|
+
- **箭头**: 显示策略的动作概率分布
|
|
216
|
+
- **文本**: 显示具体的数值
|
|
217
|
+
|
|
218
|
+
## 📝 示例
|
|
219
|
+
|
|
220
|
+
查看`examples/`目录获取更多使用示例:
|
|
221
|
+
|
|
222
|
+
- `basic_usage.py`: 基本使用示例
|
|
223
|
+
- `custom_environment.py`: 自定义环境配置
|
|
224
|
+
- `reinforcement_learning.py`: 强化学习训练示例
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
## 📄 许可证
|
|
228
|
+
|
|
229
|
+
本项目使用MIT许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
gridworldpy/__init__.py,sha256=Uty2NCYZwOCYryyi9vpo96k1RezZWJrVseMbbxYO2ec,374
|
|
2
|
+
gridworldpy/gridworld.py,sha256=zDMqCpwY3aHUmNASZjj0zF2c4WNv-OlxagEsWMs4gyU,23292
|
|
3
|
+
gridworldpy-0.1.0.dist-info/LICENSE,sha256=Zx9nZ_XtmotL83M0F7ZI5y81ij1cr2tErp4NzAtQ1Ps,1067
|
|
4
|
+
gridworldpy-0.1.0.dist-info/METADATA,sha256=uL8T7jR7cxpEKdYP-C1sQXr6nPpL-GPKEs3mn3mFoMw,6440
|
|
5
|
+
gridworldpy-0.1.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
6
|
+
gridworldpy-0.1.0.dist-info/top_level.txt,sha256=bjELP-xLEsZIZlC9cKp4qSQoByigDov1KD3ScKAEkao,12
|
|
7
|
+
gridworldpy-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gridworldpy
|