コード例 #1
0
ファイル: tests.py プロジェクト: mossblaser/Gollywhomper
	def test_hexagon_edge_link(self):
		# Get the set of edge nodes for a 4-layer hexagon
		all_nodes   = set(topology.hexagon(4))
		inner_nodes = set(topology.hexagon(3))
		outer_nodes = all_nodes - inner_nodes
		
		directions = [
			topology.EAST,
			topology.NORTH_EAST,
			topology.NORTH,
			topology.WEST,
			topology.SOUTH_WEST,
			topology.SOUTH
		]
		
		edges = [
			topology.EDGE_TOP_LEFT,
			topology.EDGE_TOP,
			topology.EDGE_TOP_RIGHT,
			topology.EDGE_BOTTOM_RIGHT,
			topology.EDGE_BOTTOM,
		  topology.EDGE_BOTTOM_LEFT,
		]
		
		# Get the set of outward-facing links as (node_xy,direction) pairs
		outward_facing_links = []
		for node in all_nodes:
			for direction in directions:
				# Get the node that this link would connect to
				facing_node = topology.to_xy(
					topology.add_direction(topology.zero_pad(node), direction))
				# If that node isn't part of our set, it is an edge link
				if facing_node not in all_nodes:
					outward_facing_links.append((node, direction))
		
		# Get the set of outward facing links according to the function under test
		all_links = []
		for edge in edges:
			for num in range(8):
				all_links.append(topology.hexagon_edge_link(edge, num, 4))
		
		# No duplicates
		self.assertEqual(len(all_links), len(set(all_links)))
		
		# The algorithm gets every outward facing edge
		self.assertEqual(set(all_links), set(outward_facing_links))
コード例 #2
0
ファイル: top.py プロジェクト: mossblaser/Gollywhomper
	def get_out_link(self, edge, num):
		"""
		Get the link specified.
		"""
		position, direction = topology.hexagon_edge_link(edge, num, 4)
		return self.chips[position].get_out_link(direction)
コード例 #3
0
ファイル: top.py プロジェクト: mossblaser/Gollywhomper
	def set_out_link(self, edge, num, link):
		"""
		Set the link on the given edge and num.
		"""
		position, direction = topology.hexagon_edge_link(edge, num, 4)
		self.chips[position].set_out_link(direction, link)