Skip to content

Commit 84da2dd

Browse files
committed
Randomized path example in main.py
1 parent b2b0586 commit 84da2dd

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

main.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import map_generator
2-
from movement_cost import linear_cost
2+
from movement_cost import linear_cost, randomized_cost
33
from path_finding import PathFinder
44

55
map_data = None
@@ -12,15 +12,16 @@ def is_valid_pos(cur_pos):
1212

1313
if __name__ == "__main__":
1414
map_data = map_generator.generate_map(100, 100, seed=25)
15-
start = (0, 0)
16-
end = (99, 99)
15+
start = (59, 45)
16+
end = (86, 40)
1717
moves = [
1818
(0, 1),
1919
(1, 0),
2020
(0, -1),
2121
(-1, 0)
2222
]
23-
path_finder = PathFinder(linear_cost(), linear_cost(), is_valid_pos)
23+
cost_func = linear_cost()
24+
path_finder = PathFinder(linear_cost(), randomized_cost(1, 0.3, cost_func), is_valid_pos)
2425
path = path_finder.find_path(moves, start, end)
2526
map_generator.view_path(map_data, path)
2627

movement_cost.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def cost(start, end):
2323

2424
return cost
2525

26+
2627
def euclidean_cost(scale=1):
2728
"""
2829
Euclidean distance, linear and diagonal movement is allowed,
@@ -87,6 +88,7 @@ def cost(start, end):
8788

8889
return cost
8990

91+
9092
def randomized_cost(sigma, mu, h_func):
9193
"""
9294
Generates random number with normal distribution based on given sigma and mu.

0 commit comments

Comments
 (0)