-
Notifications
You must be signed in to change notification settings - Fork 0
/
citys_geo.py
executable file
·64 lines (49 loc) · 1.52 KB
/
citys_geo.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
import random
import math
import time
from settings import WIDTH, HEIGHT, n_city
#### ГЕНЕРАЦИЯ МИРА
#### Города отступы от края карты
h = int((HEIGHT - 2) * 100)
w = int((WIDTH - 2) * 100)
#### Названия городов
min_dist = 400
def dist(x1, y1, x2, y2):
return math.hypot((x1 - x2), (y1 - y2))
def citys_geo(n):
def city_x():
r_x = random.randint(1, (HEIGHT - 2)) * 100
# print("r_x ", r_x)
return r_x
def city_y():
r_y = random.randint(1, (WIDTH - 2)) * 100
# print("r_y ", r_y)
return r_y
def chek_dist():
list_coor = []
while len(list_coor) != n:
if len(list_coor) >= n:
return list_coor
for _ in range(n):
list_coor.append((list([city_x(), city_y()])))
for i in list_coor:
if list_coor.count(i) != 1:
return None
for ii in list_coor:
if i == ii:
continue
d = dist(i[0] + 50, i[1] + 50, ii[0] + 50, ii[1] + 50)
# print(d)
if d < min_dist:
return None
return list_coor
while True:
list_coor = chek_dist()
if list_coor is not None:
return list_coor
if __name__ == "__main__":
t_start = time.time()
print(n_city)
list_coor = citys_geo(n_city)
print(list_coor)
print((t_start - time.time()) * -1)