-
Notifications
You must be signed in to change notification settings - Fork 8
/
ta_world.py
67 lines (60 loc) · 2.29 KB
/
ta_world.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
"""
Created on Sat Apr 18 10:49:17 2020
@author: Pieter Cawood
"""
from enum import Enum
from ta_agent import *
from ta_state import *
class MAPNODETYPES(Enum):
PARKING = 0
PATH = 1
WALL = 2
TASK_ENDPOINT = 3
# Loads map. parking and endpoints are numbered in sequence loaded.
# Task endpoints numbered from agent_number + 1
class World(dict):
def __init__(self, world_file_path, max_path_time):
self.agents = dict()
self.endpoints = dict()
self.parking_locations = dict()
self.width = 0 # Map width
self.height = 0 # Map height
self.load_file(world_file_path, max_path_time)
def load_file(self, world_file_path, max_path_time):
file = open(world_file_path, "r")
if not file.mode == 'r':
print("Could not open " + world_file_path)
else:
print("Loading map file")
world_data = file.readlines()
col = 0
row = 0
parking_count = 0
endpoint_count = 0
for line in world_data:
col = 0
for char in line:
node = None
if char == '.':
node = MAPNODETYPES.PATH
elif char == 'r':
node = MAPNODETYPES.PARKING
# Assign new agent at this parking
parking_count += 1
self.agents[parking_count] = Agent(parking_count, Location(col, row), max_path_time)
self.agents[parking_count].path[0] = Location(col, row)
self.parking_locations[parking_count] = Location(col, row)
elif char == '@':
node = MAPNODETYPES.WALL
elif char == 'e':
node = MAPNODETYPES.TASK_ENDPOINT
self.endpoints[endpoint_count] = Location(col, row)
endpoint_count += 1
if node is not None:
# Add node to this collection
self[col, row] = node
col += 1
row += 1
self.width = col
self.height = row
file.close()