-
Notifications
You must be signed in to change notification settings - Fork 2
/
filing.py
42 lines (34 loc) · 1.03 KB
/
filing.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
def load_file():
fh = open('game.txt', 'r')
lines = fh.readlines()
for line in lines:
lines[lines.index(line)] = line.replace('\n', '')
return lines
def load_size(info):
coords = info[1].split(' ')
size = [int(coords[0]), int(coords[1])]
return size
def load_portals(info):
portals = info[info.index('portals:') + 1:info.index('asteroids:')]
portals_pos = []
for portal in portals:
coords = portal.split(' ')
pos = [int(coords[0]), int(coords[1])]
portals_pos.append(pos)
return portals_pos
def load_asteroids(info):
asteroids = info[info.index('asteroids:') + 1:]
asteroids_info = []
for asteroid in asteroids:
infos = asteroid.split(' ')
aster = {
'pos': [int(infos[0]), int(infos[1])],
'ore': int(infos[2]),
'rate': int(infos[3])
}
asteroids_info.append(aster)
return asteroids_info
info = load_file()
print(load_size(info))
print(load_portals(info))
print(load_asteroids(info))