首页 > 解决方案 > 改变网格中周期性出现的对象的速度

问题描述

我在minigrid 环境中工作。我目前有一个对象在屏幕上以每步数的一个网格空间移动(从左到右)。此对象当前定期出现在屏幕上的一半时间和一半时间。我想减慢对象的速度,使其在屏幕上的移动速度变慢。我不确定如何在不丢失周期性外观属性的情况下做到这一点。当前代码如下:

        idx = (self.step_count+2)%(2*self.width) # 2 is the ratio of appear not appear
        if idx < self.width:
            try:
                self.put_obj(self.obstacles[i_obst], idx , old_pos[1]) 
                self.grid.set(*old_pos, None) # deletes old  obstacle
            except:
                pass
        else:
            self.grid.set(*old_pos, None) # deletes old  obstacle  

标签: openai-gym

解决方案


我有事要干。下面的代码片段包含一个名为“slow_factor”的整数,它降低了速度,但仍然具有对原始目的有用的 idx。

idx = (self.step_count+2)//slow_factor%(2*self.width)

推荐阅读