2019-04-01 13:29:13 +02:00
|
|
|
from DataModels.Cell import Cell
|
2019-04-01 14:10:14 +02:00
|
|
|
from DataModels.Road import Road
|
2019-04-01 15:45:48 +02:00
|
|
|
from DataModels.House import House
|
2019-04-02 09:47:00 +02:00
|
|
|
from DataModels.Dump import Dump
|
2019-04-23 17:15:05 +02:00
|
|
|
from config import GRID_WIDTH, GRID_HEIGHT, DELAY
|
|
|
|
from utilities import movement, check_moves
|
|
|
|
from Traversal.DFS import DFS
|
|
|
|
import pygame
|
2019-04-01 14:10:14 +02:00
|
|
|
|
|
|
|
class GC(Cell):
|
|
|
|
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
|
|
|
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
2019-04-23 17:15:05 +02:00
|
|
|
self.moves = []
|
|
|
|
self.old_time = pygame.time.get_ticks()
|
2019-04-10 11:01:20 +02:00
|
|
|
def move(self, direction, environment):
|
2019-04-23 17:15:05 +02:00
|
|
|
self.x, self.y = movement(environment, self.x, self.y)[0][direction]
|
2019-04-01 14:36:27 +02:00
|
|
|
self.update_rect(self.x, self.y)
|
2019-04-01 15:45:48 +02:00
|
|
|
|
2019-04-23 17:15:05 +02:00
|
|
|
print(check_moves(environment, self.x, self.y,direction))
|
2019-04-10 11:01:20 +02:00
|
|
|
|
2019-04-01 15:45:48 +02:00
|
|
|
def collect(self, enviromnent):
|
|
|
|
x, y = [self.x, self.y]
|
|
|
|
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
|
|
|
|
for coordinate in coordinates:
|
2019-04-02 09:47:00 +02:00
|
|
|
if coordinate[0]<0 or coordinate[1]<0:
|
|
|
|
continue
|
2019-04-01 15:45:48 +02:00
|
|
|
try:
|
|
|
|
item = enviromnent[coordinate[0]][coordinate[1]]
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
|
2019-04-02 09:47:00 +02:00
|
|
|
if(type(item) == House or type(item) == Dump):
|
2019-04-01 15:45:48 +02:00
|
|
|
item.return_trash(self)
|
|
|
|
self.update_image()
|
2019-04-23 17:15:05 +02:00
|
|
|
|
|
|
|
def find_houses(self,enviromnent):
|
|
|
|
for row in enviromnent:
|
|
|
|
for cell in row:
|
|
|
|
goal = []
|
|
|
|
if type(cell) == House and cell.container.is_full():
|
|
|
|
goal.append([cell.x-1, cell.y])
|
|
|
|
goal.append([cell.x+1, cell.y])
|
|
|
|
goal.append([cell.x, cell.y-1])
|
|
|
|
goal.append([cell.x, cell.y+1])
|
|
|
|
if len(self.moves) == 0:
|
|
|
|
x = self.x
|
|
|
|
y = self.y
|
|
|
|
else:
|
|
|
|
x,y = self.moves[-2]
|
|
|
|
avalible_moves = check_moves(enviromnent, x,y)
|
|
|
|
self.moves.extend(DFS(enviromnent,avalible_moves,[[x,y]],goal))
|
|
|
|
self.moves.append("pick_garbage")
|
|
|
|
print(self.moves)
|
|
|
|
self.moves.reverse()
|
|
|
|
|
|
|
|
|
|
|
|
def make_actions_from_list(self,environment):
|
|
|
|
now = pygame.time.get_ticks()
|
|
|
|
if len(self.moves)==0 or now - self.old_time <= DELAY:
|
|
|
|
return
|
|
|
|
self.old_time = pygame.time.get_ticks()
|
|
|
|
if self.moves[-1] == "pick_garbage":
|
|
|
|
self.collect(environment)
|
|
|
|
self.moves.pop()
|
|
|
|
return
|
|
|
|
self.x, self.y = self.moves.pop()
|
|
|
|
self.update_rect(self.x,self.y)
|