Added map functionality to planet.py. Moved and shortened some comments.

This commit is contained in:
d3rped 2018-03-19 22:42:27 +01:00
parent 068208bed8
commit 631d70aacc

View file

@ -32,51 +32,28 @@ next(x for (x, y), direction in planetmap[0])
next(y for x, y in planetmap[0] if x == (0, 0)) next(y for x, y in planetmap[0] if x == (0, 0))
planetmap[0][next((x, y) for x, y in planetmap[0] if y == 'North')] planetmap[0][next((x, y) for x, y in planetmap[0] if y == 'North')]
''' '''
class Planet:
"""
Contains the representation of the map and provides certain functions to manipulate it according to the specifications
"""
#Contains the representation of the map and provides certain functions to manipulate it according to the specifications
class Planet:
def __init__(self): def __init__(self):
""" Initializes the data structure """ """ Initializes the data structure """
self.planetmap = [{((0, 0), Direction.NORTH):((0, 1), Direction.SOUTH), "weight":1}] self._planetmap = {}
self.target = None self.target = None
#Adds a bidirectional path defined between the start and end coordinates to the map and assigns the weight to it.
def add_path(self, start: Tuple[Tuple[int, int], Direction], target: Tuple[Tuple[int, int], Direction], weight: int): def add_path(self, start: Tuple[Tuple[int, int], Direction], target: Tuple[Tuple[int, int], Direction], weight: int):
""" if(start[0] not in self._planetmap):
Adds a bidirectional path defined between the start and end coordinates to the map and assigns the weight to it self._planetmap[start[0]] = {}
if(start[1] not in self._planetmap[start[0]]):
example: self._planetmap[start[0]][start[1]] = (target[0], target[1], weight)
add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 1) if(target[0] not in self._planetmap):
""" self._planetmap[target[0]] = {}
self.planetmap.append({start:target, "weight":weight}) if(target[1] not in self._planetmap[target[0]]):
self._planetmap[target[0]][target[1]] = (start[0], start[1], weight)
def get_paths(self) -> Dict[Tuple[int, int], Dict[Direction, Tuple[Tuple[int, int], Direction, Weight]]]: def get_paths(self) -> Dict[Tuple[int, int], Dict[Direction, Tuple[Tuple[int, int], Direction, Weight]]]:
""" return self._planetmap
Returns all paths
example:
get_paths() returns: {
(0, 3): {
Direction.NORTH: ((0, 3), Direction.WEST, 1),
Direction.EAST: ((1, 3), Direction.WEST, 2)
},
(1, 3): {
Direction.WEST: ((0, 3), Direction.EAST, 2),
...
},
...
}
"""
pass
#Returns a shortest path between two nodes
def shortest_path(self, start: Tuple[int, int], target: Tuple[int, int]) -> Optional[List[Tuple[Tuple[int, int], Direction]]]: def shortest_path(self, start: Tuple[int, int], target: Tuple[int, int]) -> Optional[List[Tuple[Tuple[int, int], Direction]]]:
"""
Returns a shortest path between two nodes
examples:
shortest_path((0,0), (2,2)) returns: [((0, 0), Direction.EAST), ((1, 0), Direction.NORTH)]
shortest_path((0,0), (1,2)) returns: None
"""
pass pass