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


Python Map.surround_with方法代码示例

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


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

示例1: Player

# 需要导入模块: import Map [as 别名]
# 或者: from Map import surround_with [as 别名]

#.........这里部分代码省略.........
	def cleanup_ships_map(self):
		"""
		Cleanup the ships map of all the helpful water fields.
		"""
		mymap = self.ships
		mymap.set_fields(mymap.get_fields('water'), None)


	def save_foes_ships(self, shipdef):
		# I have to copy this dictionary deeply, not copying the
		# reference to it only.
		self.foeships = copy.deepcopy(shipdef)


	def is_all_sunk(self):
		"""
		Returns True when all own ships are sunk.
		"""
		if self.ship_count < 1: return True
		return False


	def turn(self):
		"""
		Play one turn and return a koordninate to bomb the foe's ships.
		Returns None when when player resigns or has no possible turn left.
		"""
		if self.human:
			# This is the human part of turn() -- I do not comment it
			# and left it to the reader...
			if self.last_result:
				lkoor,lstat = self.last_result
				if lstat == 'sunk':
					self.hits.surround_with(lkoor, 'water')

				elif lstat == 'hit':
					self._mark_hit_ship(lkoor)

			bomb_map = self.hits
			ship_map = self.ships

			koor = None		# is a tuple()
			while True:
				line = input( "\nCaptain> " )
				token = line.rstrip("\n").split()
				token.append('')	# empty lines fail to pop()
				cmd = token.pop(0).lower()
				if re.match('^(resign|aufgeben|quit|exit|ende|stop)', cmd):
					exit(0)
				elif re.match('^(hilfe|help)', cmd):
					_print_help()
				elif re.match('^(skip)', cmd):
					break
				elif cmd == '':
					bomb_map.print()
				elif cmd == 'ships':
					ship_map.print()
				elif cmd == 'strategie':
					t_map = self._best_moves()
					Map(t_map).print()
				elif cmd == 'tmap':
					t_map = self._rate_unknown_fields(int(token[0]))
					Map(t_map).print()
				elif cmd == 'tipp':
					t_map = self._best_moves()
#					Map(t_map).print()
开发者ID:OBdA,项目名称:battleships,代码行数:70,代码来源:battleships.py


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