本文整理汇总了Python中env.Env.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Env.reset方法的具体用法?Python Env.reset怎么用?Python Env.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类env.Env
的用法示例。
在下文中一共展示了Env.reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Field
# 需要导入模块: from env import Env [as 别名]
# 或者: from env.Env import reset [as 别名]
class Field(ScatterPlane):
'''
This is the Field which will contain cells.
'''
agent_widget = ObjectProperty(None)
total_reward = NumericProperty(0)
def __init__(self, cell_size=25, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cell_size = cell_size
# At the __init__ height and width, and consecutively center may be not
# established, yet due to layout logic.
Clock.schedule_once(self._init_after)
Clock.schedule_interval(self.update, 0.1)
def _init_after(self, dt):
''' Perform initializations after the layout is finalized. '''
self.env = Env()
# TODO: Move params to config file
with open('sarsa.pickle', 'rb') as fd:
self.sarsa = pickle.load(fd)
self.grid = Grid(self.canvas, 'line_loop', Color(), self.cell_size,
self.to_local(*self.center))
self.state = self.env.reset(self.grid)
self._place_agent(self.state.cell)
def _place_agent(self, cell):
self.agent_widget.center = self.grid.pixcenter(cell.q, cell.r)
# FIXME
for _ in self.grid.neighbors(cell.q, cell.r):
pass
def on_touch_down(self, touch):
super().on_touch_down(touch)
x, y = self.to_local(touch.x, touch.y)
q, r = self.grid.pixel_to_hex(x, y)
if (q, r) in self.grid:
print("Touched ({}, {}) in {}.".format(q, r, (x, y)))
print("env tvisited", self.env.tvisited[q, r])
print("state food", self.state.food)
else:
self.grid.init(q, r)
for _ in self.grid.neighbors(q, r):
pass
return True
# TODO: Shouldn't this feel better in SwarmApp?
def update(self, dt):
action = self.sarsa.policy(self.state, explore=False)
next_state, reward, done = self.env.step(action)
self.sarsa.adapt_policy(self.state, action, next_state, reward)
self.state = next_state
self.total_reward += int(reward)
self._place_agent(self.state.cell)