Skip to content

Commit

Permalink
Apply some changes and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Aug 27, 2024
1 parent d807dcd commit dec6113
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/sIArena/terrain/Terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def is_valid_path(self, path: Path) -> Tuple[bool, str]:
return True, "Valid path"


def get_destination(self):
def get_destinations(self) -> List[Coordinate]:
return None

class Terrain (NoPathTerrain):
Expand Down Expand Up @@ -184,8 +184,6 @@ def __init__(
if self.destination[1] < 0 and self.destination[1] >= self.m:
raise AttributeError(f"Destination column is out of bounds: {self.destination[1]}")

self.destinations = [destination]


def is_complete_path(self, path: Path) -> Tuple[bool, str]:
"""Returns True if the given path goes from the origin to the destination"""
Expand Down Expand Up @@ -223,6 +221,9 @@ def __str__(self):
return s


def get_destinations(self) -> List[Coordinate]:
return [self.destination]


class DestinationSetTerrain (NoPathTerrain):
"""
Expand Down Expand Up @@ -311,3 +312,7 @@ def __str__(self):
s += "|\n"
s += "+" + ("-" * (max_length + 3) + "+") * self.m + "\n"
return s


def get_destinations(self) -> List[Coordinate]:
return self.destinations
17 changes: 15 additions & 2 deletions src/sIArena/terrain/generator/MazeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ def visit(self):
self.visited = True


def weigthed_distrubution(n, r=10):
choices = [i for i in range(n)]
weights = [1 for i in range(n)]

x = 0
for i in range(n):
weights[i] *= n-1
weights[i] += x
x += r - 1

return random.choices(choices, weights=weights, k=1)[0]


class Maze:

Expand All @@ -120,8 +132,9 @@ def __init__(self, n, m, start_point=None):

while to_visit:

# Get a random tile from to_visit list
r = random.randint(0, len(to_visit) - 1)
# Get a random number from 0 to n being the last ones more probable
n = len(to_visit)
r = weigthed_distrubution(n)
next_tile = to_visit.pop(r)

if self.tile(next_tile).visited:
Expand Down
2 changes: 1 addition & 1 deletion src/sIArena/terrain/plot/plot_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def plot_terrain_2D(

# Mark with red the origin and destination
plt.plot(terrain.origin[1], terrain.origin[0], 'r+')
for dest in terrain.destinations:
for dest in terrain.get_destinations():
plt.plot(dest[1], dest[0], 'rx')

# Set path legends if unset
Expand Down

0 comments on commit dec6113

Please sign in to comment.