Question
Create the Galaxy Map Before exploration can even commence, you need to create map of the known galaxy. In order to do , you are
Create the Galaxy Map
Before exploration can even commence, you need to create map of the known galaxy. In order to do , you are given the size of the galaxy to explore through the MAP_SIZE variable. For example, if the MAP_SIZE global variable is equal to 10, then this means that the galaxy to explore is a 10 x 10 grid. Since the MAP_SIZE = 100, this implies that the galaxy is a 100 x 100 grid for this challenge. Each square in this grid can be uniquely identified by a tuple, which is an (x,y) coordinate. As an example, a 3 x 3 grid will look like this:
In this project, since this is a 100 x 100 grid, the grid will look like this:
Best Practices to Follow:
- Write detailed comments where necessary.
- Organize and structure code for readability.
- Write test cases in order to check for correctness.
Complete the generate_available_coordinates(map_size)
Complete the generate_available_coordinates(map_size) function in order to generate and return a list of all possible coordinates in the grid, remembering that each coordinate is a tuple of the form of (x,y). The function takes the size of the map.
Task
Implement the generate_available_coordinatesfunction to return a specified grid of coordinates
2
Complete the generate_empty_map(available_coordinates) function
The input to this function is a list of all the possible coordinates that you created from the previous task. This function needs to create dictionary that maps a given coordinate with the symbol occupying that space. At the beginning, every coordinate should be initialized with a space (' '), with the exception of the (0,0) coordinate, which should be the initial position of the spacecraft (marked with an 'S'). The function should return the dictionary.
For example, a 3 x 3 grid is initialized as follows:
Task
Implement the generate_empty_map function to create dictionary that maps a given coordinate with the symbol occupying that space.
2
Complete the get_unique_objects(galaxy_map) function
The input to the function should be the galaxy map dictionary (that is, the grid). The grid starts off unpopulated. This function needs to return a frozen set of unique objects in the galaxy (that is, the symbols, including the spacecraft). So, as an example, the unique objects in the following grid are {'S', '^', '*'}:
Task
The get_unique_objects function returns a frozenset of unique objects on the grid.
2
Complete the display_galaxy(galaxy_map) function
The input for this function is the galaxy map dictionary. This function needs to return a string representation of the galaxy map according to the (x,y) coordinates in the dictionary. The best way to this is to iterate over all of the coordinates and concatenate the string stored at the coordinate in the grid into a large string, and then return the string. For example, the output of the following galaxy would be 'S ^ * '. Take note that the spaces are also captured:
The next part of the galaxy exploration is to populate the galaxy map with information received from the space agency.
The space agency has a station that sweeps outer space and detects nearby objects and their coordinates. The next group of tasks are focused on receiving information from the station and then populating the galaxy map accordingly. The generate_object() function provided for you receives information from the space agency in the form of symbol, coordinate.
Task
Implement the display_galaxy function to return a string representation of the galaxy map according to the (x,y) coordinates in the dictionary
2
Complete the calculate_euclidean_distance() function
In order to be able to complete the populate_galaxy_map() function, you must first complete the calculate_euclidean_distance() function. This function takes a coordinate as an input and calculates the Euclidian distance from the starting position of the spacecraft, (0,0), to the input coordinates.
Currently, the function just returns 0, but this needs to be replaced with your own code for the distance calculation. Additionally, ensure that the return type is an integer.
The formula for the Euclidean distance is distance(x,y) = sqrt(x^2 + y^2).
As an example, the Euclidean distance between the following points is sqrt(1^2 + 2^2) = sqrt(5) = 2.24, which, when put through the int function in Python, gives int(2.24) = 2:
Task
Implement the calculate_euclidean_distance method to calculate Euclidian distance from the starting position of the spacecraft to the input coordinates.
Update the populate_galaxy_map() function
Next, we will be updating the populate_galaxy_map() function. The next task is to keep track of the data given to you by the generate_object() function, which will include information about the distance, the coordinates, and the symbol used to represent the object. The list should store the encountered objects as tuples in the form of (distance, coordinates, symbol).
Ensure that the list returned by the populate_galaxy_map() function is sorted by distance in ascending order.
The last step in completing the populate_galaxy_map() function is to continue to receive object information from the generate_object() function. Each object received needs to be added to the objects_encountered list, and the galaxy map needs to be updated accordingly. Keep doing this until you encounter a symbol of 'G' (which is the goal). At this point, break from the loop and return the sorted list of objects encountered so far.
Task
Implement the populate_galaxy_map function to return a list of objects sorted by distance in ascending order.
2
Complete the calculate_path_to_goal() function
The final task is to complete the calculate_path_to_goal() function. The aim of this function is to list all the objects of interest and their coordinates that are closer to the spaceship than the goal. The objects of interest include fuel, which is marked with 'F', and treasure, which is marked with 'T'. The input into this function is the list of objects encountered, which was determined in task 7. The output of the function is a list, which is sorted by the distance value in ascending order, of objects that are represented as tuples in the form of (distance, coordinates, symbol).
Analyze two exploration missions.
The run_exploration() function has been set up in such a way that two exploration missions are executed. Now we can focus on the similarities and differences between the missions.
Task
Implement the calculate_path_to_goal function to return the coordinates of objects of interest that are closer to the space ship than the goal.
1
Complete the symbols_not_used_in_galaxy() function
Use the get_unique_objects() function to get the unique objects encountered for each of the missions. Complete the symbols_not_used_in_galaxy() function to find the symbols that were not used in the mission. The function takes the frozen set returned by the get_unique_objects() function completed in task 3.
Task
Implement the symbols_not_used_in_galaxy function to find the symbols that were not used in the mission.
2
Complete the objects_encountered_in_galaxy1_not_galaxy2() function
Complete the objects_encountered_in_galaxy1_not_galaxy2() function. This function takes in as input the frozen sets of the unique symbols encountered in each galaxy, and outputs the symbols that were encountered in galaxy 1, but not in galaxy 2.
Complete the objects_encountered_in_galaxy2_not_galaxy1() function
Complete the objects_encountered_in_galaxy2_not_galaxy1() function. This function takes in as input the frozensets of the unique symbols encountered in each galaxy, and outputs the symbols that were encountered in galaxy 2, but not in galaxy 1
Tasks
Implement the function objects_encountered_in_galaxy1_not_galaxy2 outputs the symbols that were encountered in galaxy 1, but not in galaxy 2.
2
Implement the function objects_encountered_in_galaxy2_not_galaxy1 outputs the symbols that were encountered in galaxy 1, but not in galaxy 2.
2
Complete the common_objects_encountered() function
Complete the common_objects_encountered() function, which takes in as input the frozen sets of the unique symbols encountered in each galaxy, and outputs the symbols that are encountered in both galaxy 1 and galaxy 2 (that is, common to both galaxies).
Task
Implement the common_objects_encountered function which outputs the symbols that are encountered in both galaxy 1 and galaxy 2 .
2
Complete the objects_encountered_in_both_galaxys() function
Complete the objects_encountered_in_both_galaxys() function which, takes in as input the frozen sets of the unique symbols encountered in each galaxy, and outputs the symbols that are encountered in either galaxy 1 or galaxy 2 (that is, all the symbols encountered in either galaxy).
Task
Implement the function objects_encountered_in_both_galaxys which outputs all the symbols that are encountered in either galaxy 1 or galaxy 2 .
this is what i have so far...
from random import seed, sample, choice
from os import linesep
from string import punctuation
from math import sqrt
from itertools import product
SEED_NUMBER = 1024
seed(SEED_NUMBER)
MAP_SIZE = 100
all_possible_symbols = frozenset(punctuation+'GSFT ')
def define_possible_objects(choices=punctuation):
chars = choices
chars += 'G'
chars += 'T'*3
chars += 'F'*3
return chars
def generate_object(itera, available_coordinates, occupied_coordinates):
symbol = sample(itera, 1)
coordinates = choice(available_coordinates)
available_coordinates.remove(coordinates)
occupied_coordinates.append(coordinates)
return symbol, coordinates
def set_up():
symbols1 = define_possible_objects(punctuation)
symbols2 = define_possible_objects('^&*'*5)
return symbols1, symbols2
def generate_available_coordinates(map_size):
# insert your code here
pass
def generate_empty_map(available_coordinates):
# insert your code here
pass
def get_unique_objects(galaxy_map):
# insert your code here
pass
def symbols_not_used_in_galaxy(symbols_in_galaxy):
# insert your code here
pass
def common_objects_encountered(galaxy_1_objects, galaxy_2_objects):
# insert your code here
pass
def objects_encountered_in_galaxy1_not_galaxy2(galaxy_1_objects, galaxy_2_objects):
# insert your code here
pass
def objects_encountered_in_galaxy2_not_galaxy1(galaxy_1_objects, galaxy_2_objects):
# insert your code here
pass
def objects_encountered_in_both_galaxys(galaxy1_objects, galaxy2_objects):
# insert your code here
pass
def calculate_path_to_goal(sorted_object_list):
# insert your code here
pass
def display_galaxy(galaxy_map):
# insert your code here
pass
def calculate_euclidean_distance(coordinates):
# insert your code here
pass
def populate_galaxy_map(available_symbols, available_coordinates, occupied_coordinates, galaxy_map):
objects_encountered_list = list()
while True:
symbol, coordinates = generate_object(available_symbols, available_coordinates, occupied_coordinates)
distance = calculate_euclidean_distance(coordinates)
# insert your code here
# insert your code here
pass
def run_exploration():
available_symbols1, available_symbols2 = set_up()
available_coordinates1 = generate_available_coordinates(MAP_SIZE)
available_coordinates2 = generate_available_coordinates(MAP_SIZE)
occupied_coordinates1 = list()
occupied_coordinates2 = list()
galaxy_map_1 = generate_empty_map(available_coordinates1)
galaxy_map_2 = generate_empty_map(available_coordinates2)
explorer1_list = populate_galaxy_map(available_symbols1, available_coordinates1, occupied_coordinates1, galaxy_map_1)
explorer2_list = populate_galaxy_map(available_symbols2, available_coordinates2, occupied_coordinates2, galaxy_map_2)
print(explorer1_list)
print(explorer2_list)
path_list1 = calculate_path_to_goal(explorer1_list)
print(path_list1)
path_list2 = calculate_path_to_goal(explorer2_list)
print(path_list2)
display_galaxy(galaxy_map_1)
display_galaxy(galaxy_map_2)
galaxy2_symbols = get_unique_objects(galaxy_map_2)
galaxy1_symbols = get_unique_objects(galaxy_map_1)
print(galaxy1_symbols)
print(galaxy2_symbols)
if __name__ == '__main__':
run_exploration()
Step by Step Solution
3.38 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
To complete the missing functions and tasks lets start implementing the required functionalities 1 generateavailablecoordinatesmapsize python def generateavailablecoordinatesmapsize Generates all poss...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started