本文整理汇总了Python中terrain.Terrain.respawntree方法的典型用法代码示例。如果您正苦于以下问题:Python Terrain.respawntree方法的具体用法?Python Terrain.respawntree怎么用?Python Terrain.respawntree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terrain.Terrain
的用法示例。
在下文中一共展示了Terrain.respawntree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import respawntree [as 别名]
class Game:
def __init__(self):
self._running = True
self.screen = None
self.size = self.width, self.height = SCREEN_WIDTH, SCREEN_HEIGHT
def on_init(self):
pygame.init()
self.screen = pygame.display.set_mode(
self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
# Fill background and blits everything to the screen
self.background = pygame.Surface(self.size)
self.background = self.background.convert()
self.background.fill(BG_COLOR)
self.screen.blit(self.background, (0, 0))
pygame.display.flip()
self.terrain = Terrain()
self.beaver = Beaver()
self.beaversprite = pygame.sprite.RenderPlain(self.beaver)
self.generationtime = pygame.time.get_ticks()
self.brain = Brain()
self.brain.environment.setbeaver(self.beaver)
self.wolf = Wolf()
self.wolfsprite = pygame.sprite.RenderPlain(self.wolf)
self._clock = pygame.time.Clock()
self._running = True
def on_event(self, event):
if event.type == pygame.QUIT:
self._running = False
def on_loop(self):
self.beaver.seteyeview(self.terrain.terraingroup)
self.beaversprite.update()
self.brain.experiment.doInteractions(1)
self.wolf.seteyeview(self.terrain.terraingroup)
self.wolf.setscentview(self.beaver)
#self.wolfsprite.update()
marsh = self.terrain.getmarsh()
if (self.beaver.action == Constants.BEAVER_ACTION_DROP_LUMBER and
self.beaver.droppedlumber and
pygame.sprite.collide_rect(self.beaver, marsh)):
marsh.improve()
marsh.update()
# Reset the wolf if it gets stuck in marsh
if pygame.sprite.collide_rect(self.wolf, marsh):
self.wolf.respawn()
if (self.beaver.energy <= 0 or
self.beaver.rect.colliderect(self.wolf.rect)):
temp = pygame.time.get_ticks()
# Only when beaver starves
if self.beaver.energy <= 0:
generationtimes.append("%d\t%d" % (self.beaver.generationcount,
temp - self.generationtime))
self.generationtime = temp
self.beaver.respawn()
self.brain.agent.learn()
self.brain.agent.reset()
if self.beaver.generationcount > NUM_GENERATIONS:
self._running = False
# Reset the wolf so that it seems as if time has passed
# (aka wolf not lurking around marsh on beaver spawn)
self.wolf.respawn()
# Reset the environment so beavers start alike.
marsh.respawn()
self.terrain.respawntrees()
else:
tree = pygame.sprite.spritecollideany(self.beaver,
self.terrain.gettreelist())
if tree is not None and not isinstance(tree, Marsh):
# Check beaver state
if self.beaver.action == Constants.BEAVER_ACTION_EAT:
tree.setstate(Constants.TREE_STATE_ATE)
tree.update()
elif (self.beaver.action == Constants.BEAVER_ACTION_PICK_UP_LUMBER and
self.beaver.pickeduplumber):
tree.setstate(Constants.TREE_STATE_FORAGED)
tree.update()
# Check tree state
if tree.health <= 0:
#.........这里部分代码省略.........