當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。