当前位置: 首页>>代码示例>>Python>>正文


Python GameState.tickTurn方法代码示例

本文整理汇总了Python中GameState.GameState.tickTurn方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.tickTurn方法的具体用法?Python GameState.tickTurn怎么用?Python GameState.tickTurn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameState.GameState的用法示例。


在下文中一共展示了GameState.tickTurn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import tickTurn [as 别名]
class GeneticBot:
	def __init__(self):
		sys.stderr = open('errors.txt', 'w')
	
	# This method is called in ants.py (can be removed)
	def do_setup(self, ants_instance):
		self.gs = GameState(ants_instance) # Keep track of important game state stuff
		# GENOME IS DEFINED HERE
		self.genome = [Genes.ExploreGene(), Genes.FoodGene()]
	
	# Called once a turn in ants.py, orders called from here
	def do_turn(self, ants_instance):
		sys.stderr.write('rem: ' + str(ants_instance.time_remaining()) + '\n')
		self.gs.updateAll(ants_instance)
		sys.stderr.write('rem (building af): ' + str(ants_instance.time_remaining()) + '\n')

		# Get the hill protectors to do their business
		# This is a necessary evil as it would be far messier to screw around with the Genes
		sys.stderr.write('rem (hill protection...): ' + str(ants_instance.time_remaining()) + '\n')
		self.gs.hp.protect(ants_instance, self.gs, self.genome) # does dispersion while staying near the hill

		afs = [] # see Utils.py -> AntForce
		# Build default ant force holders based on current ants
		for ant_loc in ants_instance.my_ants():
			# Do not do dispersions for the normal ants
			if ant_loc in self.gs.hp.getProtectors():
				continue
			row, col = ant_loc
			afs.append(utils.AntForce(row, col))
		sys.stderr.write('rem (expressing genome...): ' + str(ants_instance.time_remaining()) + '\n')

		# Express the genes (not related to hill protectors)
		for gene in self.genome:
			sys.stderr.write('rem (expressing gene {0}): '.format(gene.id) + str(ants_instance.time_remaining()) + '\n')
			df = gene.express(ants_instance, self.gs, afs)
			utils.logdf(gene.id, df, self.gs.turn)
		sys.stderr.write('rem (applying forces): ' + str(ants_instance.time_remaining()) + '\n')
		
		# Resolve the forces to produce actions
		for af in afs:
			af.applyForces(ants_instance, self.gs)
		sys.stderr.write('rem: ' + str(ants_instance.time_remaining()) + '\n')
		sys.stderr.flush()
				
		self.gs.tickTurn()
开发者ID:jsom,项目名称:nothingboring,代码行数:47,代码来源:GeneticBot.py


注:本文中的GameState.GameState.tickTurn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。