2023-05-11 19:34:08 +02:00
|
|
|
from decisionTree.evaluate import evaluate
|
2023-03-29 07:13:08 +02:00
|
|
|
from domain.entities.entity import Entity
|
2023-03-28 20:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class World:
|
2023-04-10 18:43:16 +02:00
|
|
|
def __init__(self, width: int, height: int) -> object:
|
2023-03-28 20:14:23 +02:00
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2023-03-30 18:27:51 +02:00
|
|
|
self.dust = [[[] for j in range(height)] for i in range(width)]
|
|
|
|
self.obstacles = [[[] for j in range(height)] for i in range(width)]
|
2023-03-28 20:14:23 +02:00
|
|
|
|
2023-03-29 07:13:08 +02:00
|
|
|
self.vacuum = None
|
|
|
|
self.cat = None
|
2023-04-13 19:04:57 +02:00
|
|
|
self.doc_station = None
|
2023-03-29 07:13:08 +02:00
|
|
|
|
2023-03-29 11:27:59 +02:00
|
|
|
def add_entity(self, entity: Entity):
|
|
|
|
if entity.type == "PEEL":
|
|
|
|
self.dust[entity.x][entity.y].append(entity)
|
2023-05-11 19:34:08 +02:00
|
|
|
elif entity.type == "EARRING":
|
|
|
|
self.dust[entity.x][entity.y].append(entity)
|
2023-03-29 11:27:59 +02:00
|
|
|
elif entity.type == "VACUUM":
|
|
|
|
self.vacuum = entity
|
2023-04-13 19:04:57 +02:00
|
|
|
elif entity.type == "DOC_STATION":
|
|
|
|
self.doc_station = entity
|
2023-03-29 11:27:59 +02:00
|
|
|
elif entity.type == "CAT":
|
|
|
|
self.cat = entity
|
|
|
|
self.obstacles[entity.x][entity.y].append(entity)
|
|
|
|
else:
|
|
|
|
self.obstacles[entity.x][entity.y].append(entity)
|
2023-03-28 20:14:23 +02:00
|
|
|
|
2023-03-29 07:13:08 +02:00
|
|
|
def is_obstacle_at(self, x: int, y: int) -> bool:
|
|
|
|
return bool(self.obstacles[x][y])
|
2023-04-10 18:43:16 +02:00
|
|
|
|
|
|
|
def is_garbage_at(self, x: int, y: int) -> bool:
|
2023-05-11 19:34:08 +02:00
|
|
|
if len(self.dust[x][y]) == 0:
|
|
|
|
return False
|
|
|
|
tmp = evaluate([self.dust[x][y][0].props])
|
|
|
|
return bool(tmp[0])
|
2023-04-13 19:04:57 +02:00
|
|
|
|
|
|
|
def is_docking_station_at(self, x: int, y: int) -> bool:
|
|
|
|
return bool(self.doc_station.x == x and self.doc_station.y == y)
|
2023-04-20 03:38:55 +02:00
|
|
|
|
|
|
|
def accepted_move(self, checking_x, checking_y):
|
|
|
|
if (
|
|
|
|
checking_x > self.width - 1
|
|
|
|
or checking_y > self.height - 1
|
|
|
|
or checking_x < 0
|
|
|
|
or checking_y < 0
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if self.is_obstacle_at(checking_x, checking_y):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|