本文整理汇总了Python中Object.Object.getRealPosition方法的典型用法代码示例。如果您正苦于以下问题:Python Object.getRealPosition方法的具体用法?Python Object.getRealPosition怎么用?Python Object.getRealPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object.Object
的用法示例。
在下文中一共展示了Object.getRealPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import getRealPosition [as 别名]
#.........这里部分代码省略.........
x = objStartX - 2.0 * HALF_W + (1 + i / 4) * kilobotOffsets[i % 4, 0]
y = objStartY + (1 + i / 4) * kilobotOffsets[i % 4, 1]
kilobot.body.position = vec2(x, y) * self.SCALE_REAL_TO_SIM
s = asmatrix(empty((1, 2 + 2 * self.numKilobots)))
targetPos = matrix([objStartX, objStartY])
while True:
""" user interaction """
# handle keys
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_PLUS:
self.stepsPerSec *= 2
elif event.key == K_MINUS:
self.stepsPerSec = np.max([1, self.stepsPerSec / 2])
""" drawing """
self.screen.fill((0, 0, 0, 0))
self.maze.draw(self.screen)
self.pushObject.draw(self.screen)
for kilobot in self.kilobots:
kilobot.draw(self.screen)
# draw light
lx = int(self.SCALE_REAL_TO_VIS * lightPos[0, 0])
ly = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
lightPos[0, 1])
lr = int(self.SCALE_REAL_TO_VIS * 0.02)
gfxdraw.aacircle(self.screen, lx, ly, lr, (255, 255, 0))
objPos = self.pushObject.getRealPosition()
# draw line from object to target position
ox = int(self.SCALE_REAL_TO_VIS * objPos[0, 0])
oy = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
objPos[0, 1])
tx = int(self.SCALE_REAL_TO_VIS * targetPos[0, 0])
ty = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
targetPos[0, 1])
pygame.draw.aaline(self.screen, (0, 0, 255), (ox, oy), (tx, ty))
pygame.display.flip()
self.clock.tick(self.stepsPerSec)
""" simulation """
# current state
s[0, 0] = lightPos[0, 0] - objPos[0, 0]
s[0, 1] = lightPos[0, 1] - objPos[0, 1]
for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
kbPos = kilobot.getRealPosition()
s[0, 2 + 2 * i + 0] = kbPos[0, 0] - objPos[0, 0]
s[0, 2 + 2 * i + 1] = kbPos[0, 1] - objPos[0, 1]
# solve maze
targetPos = self.mazePolicy.getTargetPosition(objPos)
# rotate state
direction = targetPos - objPos
angle = -math.atan2(direction[0, 1], direction[0, 0])
sx = s.flat[0::2] * math.cos(angle) - s.flat[1::2] * math.sin(angle)
示例2: __init__
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import getRealPosition [as 别名]
#.........这里部分代码省略.........
for step in range(self.numStepsPerEpisode):
""" user interaction """
# handle keys
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_PLUS:
self.stepsPerSec *= 2
elif event.key == K_MINUS:
self.stepsPerSec = np.max([1, self.stepsPerSec / 2])
""" drawing """
self.screen.fill((0, 0, 0, 0))
self.pushObject.draw(self.screen)
for kilobot in self.kilobots:
kilobot.draw(self.screen)
# draw light
lx = int(self.SCALE_REAL_TO_VIS * lightPos[0, 0])
ly = int(self.screen.get_height() - self.SCALE_REAL_TO_VIS *
lightPos[0, 1])
lr = int(self.SCALE_REAL_TO_VIS * 0.02)
gfxdraw.aacircle(self.screen, lx, ly, lr, (255, 255, 0))
pygame.display.set_caption(('ep: {} - step: {} - ' +
'stepsPerSec: {}').format(ep + 1, step + 1, self.stepsPerSec))
pygame.display.flip()
self.clock.tick(self.stepsPerSec)
""" simulation """
# current state
objPos = self.pushObject.getRealPosition()
objPosOld = objPos
s = asmatrix(empty((1, S.shape[1])))
s[0, 0] = lightPos[0, 0] - objPos[0, 0]
s[0, 1] = lightPos[0, 1] - objPos[0, 1]
for (i, kilobot) in zip(range(self.numKilobots), self.kilobots):
kbPos = kilobot.getRealPosition()
s[0, 2 + 2 * i + 0] = kbPos[0, 0] - objPos[0, 0]
s[0, 2 + 2 * i + 1] = kbPos[0, 1] - objPos[0, 1]
# choose action
if self.useMean:
a = self.policy.getMeanAction(s)
else:
if random.random() <= self.epsilon:
a = self.policy.getRandomAction()
else:
a = self.policy.sampleActions(s)
# take action
n = linalg.norm(a)
if n > 0.015:
lightPos += (a * 0.015 / n)
else:
lightPos += a
# move directly toward the light
for kilobot in self.kilobots:
kbPos = kilobot.getRealPosition()
v = lightPos - kbPos