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


Python Region.to_set方法代码示例

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


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

示例1: __init__

# 需要导入模块: from region import Region [as 别名]
# 或者: from region.Region import to_set [as 别名]

#.........这里部分代码省略.........
	def direction_to_offset(self, direction):
		'''
		Method: direction_to_offset
		Description: Converts a Direction to a cell offset.
		Parameters: direction
			direction: Direction - The direction to convert into an offset
		Return: 2-Tuple - An offset in a given direction
			[0] = The x-dimensional offset
			[1] = The y-dimensional offset
		'''

		if direction == Direction.NORTH:
			return (0, -1)
		elif direction == Direction.EAST:
			return (1, 0)
		elif direction == Direction.SOUTH:
			return (0, 1)
		elif direction == Direction.WEST:
			return (-1, 0)
		else:
			return (0, 0)

	def is_valid_cell_position(self, position):
		'''
		Method: is_valid_cell_position
		Description: Determines whether the given position is a valid cell within the maze.
		Parameters: position
			position: 2-Tuple - A position value
				[0] = The x-position
				[1] = The y-position
		Return: Boolean - Whether or not the given position is a valid cell within the maze
		'''

		if position in self.m_region.to_set():
			return True
		else:
			return False

	def valid_cell_set(self, region, exemptions):
		'''
		Method: valid_cell_set
		Description: Constructs a set of valid cells (cells that are in the intersection of the maze cell set and the region cell set, subtracting those in the exempt region sets).
		Parameters: region, exemptions
			region: Region - A region of cells to intersect with the cells of the maze
			exemptions: Regions - A collection of regions to subtract from the valid cell set
		Return: Set([Cell]) - A set of valid cells (cells that are in the intersection of the maze cell set and the region cell set, subtracting those in the exempt region sets)
		'''

		valid_cell_positions = self.m_region.to_set() & region.to_set()
		if exemptions is not None:
			for exemption in exemptions:
				valid_cell_positions -= exemption.to_set()

		return set([self.get_cell(x) for x in valid_cell_positions])

	def get_accessible_neighbor_cells(self, source_cell):
		'''
		Method: get_accessible_neighbor_cells
		Description: Gets a list of all neighboring cells which are directly-accessible from the given source cell.
		Parameters: source_cell
			source_cell: Cell - The cell to check the neighbors of
		Return: [Cell] - All neighboring cells directly-accessible from the given source cell
		'''

		accessible_neighbor_cells = []
开发者ID:DFrye333,项目名称:DynamicMaze,代码行数:69,代码来源:maze.py


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