-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgalaxy_map.py
93 lines (78 loc) · 2.71 KB
/
galaxy_map.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
#!/usr/env/python
# Basic module to generate a galaxy based on passed parameters.
# Author: [email protected]
# Version: 0.1
# Modules
import galaxy_lib
import random
import planets
# Variables
# Functions
def BuildMap(num_systems, min_dist_origin, max_dist_origin, min_dist_system,
max_dist_system, x_origin, y_origin):
"""Builds Galaxy Map based on passed criteria.
Current iteration only returns a set of coordinates for planets. No names or
values around planets are determined.
Args:
num_systems: Number of systems to place on map.
min_dist_origin: Minimum allowable distance from origin.
max_dist_origin: Maximum allowable distance from origin.
min_dist_system: Minimum allowable distance from other systems.
max_dist_system: Maximum allowable distance from other systems.
x_origin: X coordinate of map origin.
y_origin: Y coordinate of map origin.
Returns:
2 dimensional array of planet coordinates.
"""
# TODO: Build class array directly in BuildMap.
# Initialize array
planets = [[0 for z in range(num_systems)] for z in range(num_systems)]
max_attempts = 1000
for x in range(0, num_systems - 1):
# Initial validator
valid_system = False
attempt = 0
while not(valid_system):
attempt += 1
if (attempt > max_attempts):
print "Unable to generate map."
print "Failed on %s" % x
quit()
# Generate random coordinates
test_x = (random.randint(0, x_origin * 2))
test_y = (random.randint(0, y_origin * 2))
dist_to_origin = galaxy_lib.Distance(test_x, test_y, x_origin, y_origin)
if (min_dist_origin < dist_to_origin < max_dist_origin):
if (x == 0):
planets[x][0] = test_x
planets[x][1] = test_y
break
for y in range(0, x):
dist_to_system = galaxy_lib.Distance(test_x, test_y, planets[y][0],
planets[y][1])
if (min_dist_system < dist_to_system < max_dist_system):
planets[x][0] = test_x
planets[x][1] = test_y
valid_system = True
return planets
def DrawMap(planets, x_origin, y_origin):
"""Draws a map of based on a set of coordinates.
Args:
planets: Array of class Planet.
x_origin: X coordinate of origin.
y_origin: Y coordinate of origin.
"""
for y in range(0, y_origin * 2):
for x in range(0, x_origin * 2):
empty = True
for z in range(0, len(planets) - 1):
if ((planets[z].x_pos == x) and (planets[z].y_pos == y)):
print(" %s" % planets[z].name),
empty = False
if ((x == x_origin) and (y == y_origin)):
print('**'),
elif (empty):
print('..'),
print('\n')
if __name__ == "__main__":
pass