-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
127 lines (80 loc) · 2.85 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
## Built in modules
import numpy as np
import numpy.random as rd
import matplotlib.pyplot as plt
import time
import matplotlib.cm as cm
import os
import sys
## Project modules
main_dir_path = os.getcwd()
modules_path = main_dir_path + "\\modules"
# On ajoute le dossier modules aux dossiers de recherche des modules
if modules_path not in sys.path:
sys.path.append(modules_path)
import map_modules
import params
def main():
## Init
start_time = time.time()
sim_folder_path = "sim\\" + time.strftime("%y%m%d %Hh%Mm%Ss", time.gmtime())
if params.SAVE_SIM:
os.mkdir(sim_folder_path)
## Run
# Map creation
m = map_modules.Map(params.MAP_LENGTH, params.MAP_WIDTH)
m.add_obstacles(params.OBSTACLES)
map = m.grid
# Cells creation
all_cells = [ [2,2] , [3,3], [7,6], [7,6], [9,9] ]
def accessible(x,y) :
return not (x<0 or y<0 or x >= params.MAP_LENGTH or y>=params.MAP_WIDTH or map[x,y] == params.WALLS_VALUE)
for i in range(params.STEPS_NUMBER):
cell_map = np.zeros((params.MAP_LENGTH, params.MAP_WIDTH))
for cell in all_cells :
b = True
while b :
b = False
theta = rd.randint(4)
if theta == 0 :
if accessible(cell[0]+1,cell[1]) :
cell[0] += 1
else :
b = True
elif theta == 1 :
if accessible(cell[0]-1,cell[1]) :
cell[0] -= 1
else :
b = True
elif theta == 2 :
if accessible(cell[0],cell[1]+1) :
cell[1] += 1
else :
b = True
else :
if accessible(cell[0],cell[1]-1) :
cell[1] -= 1
else :
b = True
cell_map[cell[0],cell[1]] += 100
## Display
print(all_cells)
print(map + cell_map)
input("")
print ("\n" * 100)
## Save sim as images
if params.SAVE_SIM:
fig, ax = plt.subplots()
# ax.imshow(map + cell_map, interpolation='bilinear', cmap=cm.Greys_r)
ax.imshow(map + cell_map, interpolation='nearest', cmap=cm.Greys_r)
fig.savefig(sim_folder_path + "\\{:04d}".format(i))
fig.clear()
## End
end_time = time.time()
if __name__ == "__main__" :
print("Execution time : ",end_time-start_time)
## Run
if __name__ == "__main__":
main()