-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapGenerator.py
136 lines (107 loc) · 2.55 KB
/
mapGenerator.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
125
126
127
128
129
130
131
132
133
134
135
136
import matplotlib
import pylab as pl
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
def bigMap(w,h):
source=[]
hole=[]
sy=1
for i in range(h):
source.append([0,sy])
source.append([w-1,sy])
sy+=2+i%2
if sy>h:
break
if w%3==1:
xbias=1
else:
xbias=0
if h%3==2:
ybias=1
else:
ybias=0
hx = 2+xbias
hy = 1+ybias
while hy<h-1:
while hx<w-2:
hole.append([hx,hy])
hx+=3
hx=2+xbias
hy+=3
return source, hole
def smallMap(w,h):
source = []
hole = []
sy = 1
for i in range(h):
source.append([0, sy])
source.append([w-1, sy])
sy += 2
if sy > h:
break
hx = 2
hy = 1
while hy < h-1:
while hx < w - 2:
hole.append([hx, hy])
hx += 2
hx = 2
hy += 2
return source, hole
def generateMap(w,h):
if w<=13 and h<=13:
return smallMap(w,h)
else:
return bigMap(w,h)
# still have some problem
def randomCity(cityNum, holeNum):
hole_city=[]
for i in range(holeNum):
hole_city.append(np.random.randint(0,cityNum))
city_dis=[]
for j in range(cityNum):
city_dis.append(np.random.random())
dis_sum = sum(city_dis)
for j in range(cityNum):
city_dis[j]/=dis_sum
return hole_city, city_dis
def show_map(mapsize, conveyors, hole_pos):
# only for test
fig = plt.figure()
ax = plt.subplot2grid((3, 3), (0, 0), colspan=3, rowspan=3)
ax.grid(True, color="black", alpha=0.25, linestyle='-')
for k in range(len(conveyors)):
p = patches.Wedge(
((conveyors[k][0]), (conveyors[k][1])),
1,
0,
60,
width=1,
facecolor='r',
linewidth=0.5,
linestyle='-',
alpha=0.5
)
ax.add_patch(p)
for i in range(len(hole_pos)):
p = patches.Rectangle(
((hole_pos[i][0]), (hole_pos[i][1])),
1,
1,
linewidth=0.5,
linestyle='-'
)
ax.add_patch(p)
# set ticks and spines
ax.set_xticks(np.arange(0, mapsize[0]+1, 1))
ax.set_xticklabels(())
ax.set_yticks(np.arange(0, mapsize[1]+1, 1))
ax.set_yticklabels(())
plt.show()
# if __name__ == "__main__":
# edge=10
# a,b=bigMap(edge,edge)
# randomCity(4,6)
# a,b=generateMap(edge,edge)
# show_map((edge,edge),a,b)