# 问题6: 模拟机器人 # 姓名: # 合作人: # 时间: import math # === 问题 1 def new_room(width, height): """ 返回一个新的,用WIDTH和HEIGHT的乘积,表示房间大小的数据结构,并储存房间中的每块地砖,无论是否被清理。初始情况下,所有地砖都没有被清理. """ # 返回值将会作为 ROOM的参数,传给如下的方程 return # ... 此处为你的代码 def set_tile_cleaned(room, m, n): """ 房间中已经清理的地砖,标记为(m, n). 假设(m, n)表示房间中一块有效的地砖. """ # 此处为你的代码 def is_tile_cleaned(room, m, n): """ 返回 True,如果房间中的地砖(m, n)已经被清理. 假设(m, n)表示房间中一块有效的地砖. """ # 此处为你的代码 def get_num_tiles(room): """ 返回房间中地砖的总数. """ # 此处为你的代码 def get_num_cleaned_tiles(room): """ 返回房间中已经清理的地砖数. """ # 此处为你的代码 def get_random_position(room): """ 返回一个房间中的随机位置(元组(x, y)). """ # 此处为你的代码 def is_position_in_room(room, position): """ 返回 True,如果位置(元组(x, y))在房间中. """ # 此处为你的代码 def new_robot_structure(n, room): """ 返回一个新的数据结构(我们叫它'机器人数据结构')来存储房间中N个不同机器人的位置和方向.位置和方向需要被随机的初始化. """ # 返回值将会作为 robot_structure的参数,传给如下的方程 return # ... 此处为你的代码 def get_robot_position(robot_structure, i): """ 机器人数据结构中返回第 i个机器人的位置(元组(x, y)). 假设0 <= i < n, n是机器人的总数. """ # 此处为你的代码 def get_robot_direction(robot_structure, i): """ 在机器人数据结构中返回第 i个机器人的方向(角度, 0 <= dir < 360). 假设0 <= i < n, n是机器人的总数. """ # 此处为你的代码 def set_robot_position(robot_structure, i, position): """ 在机器人数据结构中设置第 i个机器人的位置到(元组(x, y)). 假设0 <= i < n, n是机器人的总数, 位置表示房间中有效的位置. """ # 此处为你的代码 def set_robot_direction(robot_structure, i, dir): """ 在机器人数据结构中设置第 i个机器人的方向到 DIR(一个角度). 假设0 <= i < n, n是机器人的总数, DIR是有效的角度(0 <= dir < 360). """ # 此处为你的代码 # === 问题 2 def run_simulation(num_robots, speed, width, height, min_coverage, num_trials): """ 运行NUM_TRIALS模拟实验并且返回清理房间中MIN_COVERAGE部分所需要的平均时间. 用 NUM_ROBOTS机器人运行模拟, 每个的速度为 SPEED,在面积为WIDTH x HEIGHT的房间中. """ # 此处为你的代码 # 你会用到如下有用的方程. def get_new_position(coords, angle, speed): """ 在一个时钟周期之后,计算并返回新位置 (x,y), 给出现在的位置, 角度, 和速度. 不要测试返回位置是否在房间内. 坐标: 元组(x, y)代表现在的位置 角度: 浮点数代表角度, 0 <= angle < 360 速度: 正的浮点数代表速度 返回值: 元组(x,y)代表新的 x, y坐标 """ old_x, old_y = coords # 计算位置的改变 delta_y = speed * math.cos(math.radians(angle)) delta_x = speed * math.sin(math.radians(angle)) # 把它加到现有的位置里 new_x = old_x + delta_x new_y = old_y + delta_y return (new_x, new_y) # === 问题 3 def show_plot_1(): """ 产生基于机器人数量的清理时间的数据图。 """ # 此处为你的代码 def show_plot_2(): """ 产生基于房间大小的清理时间的数据图。 """ # 此处为你的代码 def show_plot_3(): """ 产生基于房间形状的清理时间的数据图。 """ # 此处为你的代码