Exemplo n.º 1
0
def navigate2_m(state, agent, source, sink, rand=False):
	possible_decomp = []
	source_y, source_x = state.loc[source]
	sink_y, sink_x = state.loc[sink]

	if state.at[agent] == sink:
		# already at destination
		possible_decomp.append([])
	elif can_traverse(state, source, sink):
		# Next to the destination
		possible_decomp.append([('navigate_op', agent, source, sink)])
	else:
		# Look for possible neighbors
		neighbors = []
		for n in navigation.get_neighbors(state, source):
			if n not in state.visited[agent]: 
				neighbors.append(n)

		sorted_n = sorted(neighbors, key=lambda n: navigation.heuristic(state, n, sink))

		for mid in sorted_n:
			possible_decomp.append([('navigate_op', agent, source, mid), ('visit', agent, mid), ('navigate2', agent, mid, sink), ('unvisit',agent, mid)])

	if possible_decomp == []: return [False]

	return possible_decomp
Exemplo n.º 2
0
def get_rock_data_m(state, agent, rand=False):
	keys = []
	to_return = []
	for (key, val) in state.at.items():
		if val != None:
			if (key in state.rocks):
				# Using heapq
				keys.append(key)

	if state.has_rock_sample[agent]:
		to_return = [[('get_a_rock_data', agent, state.rock_sample[agent])]]

	if rand: 
		random.shuffle(keys)
	sorted_keys = sorted(keys, key=lambda n: navigation.heuristic(state, state.at[agent], state.at[n]))
	for k in sorted_keys:
		to_return.append([('get_a_rock_data', agent, k)])

	if len(to_return) == 0: return [False] # If there is no soil anywhere
	return to_return