84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
from DataModels.Cell import Cell
|
|
from DataModels.Road import Road
|
|
from DataModels.House import House
|
|
from DataModels.Dump import Dump
|
|
from config import GRID_WIDTH, GRID_HEIGHT, DELAY
|
|
from utilities import movement, check_moves
|
|
from Traversal.DFS import DFS
|
|
from Traversal.BFS import BFS
|
|
import pygame
|
|
class GC(Cell):
|
|
moves_made = 0
|
|
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
|
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
|
self.moves = []
|
|
self.old_time = pygame.time.get_ticks()
|
|
def move(self, direction, environment):
|
|
self.x, self.y = movement(environment, self.x, self.y)[0][direction]
|
|
self.update_rect(self.x, self.y)
|
|
self.moves_made = self.moves_made + 1 #moves counter
|
|
|
|
print(check_moves(environment, self.x, self.y,direction))
|
|
|
|
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:
|
|
if coordinate[0]<0 or coordinate[1]<0:
|
|
continue
|
|
try:
|
|
item = enviromnent[coordinate[0]][coordinate[1]]
|
|
except:
|
|
continue
|
|
|
|
if(type(item) == House or type(item) == Dump):
|
|
item.return_trash(self)
|
|
self.update_image()
|
|
|
|
def get_moves_made(self):
|
|
return self.moves_made
|
|
|
|
def find_houses(self,enviromnent, house_count,dump_count, mode):
|
|
x = self.x
|
|
y = self.y
|
|
result = []
|
|
element_list=[]
|
|
house_count_after_search=house_count
|
|
for home in range(house_count):
|
|
avalible_moves = check_moves(enviromnent, x,y)
|
|
if mode == "DFS":
|
|
house,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],House)
|
|
elif mode == "BFS":
|
|
house,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],House)
|
|
result = result[1::]
|
|
self.moves.extend(result)
|
|
element_list.append(house)
|
|
|
|
for dump in range(dump_count):
|
|
avalible_moves = check_moves(enviromnent, x,y)
|
|
if mode == "DFS":
|
|
dump,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
|
elif mode == "BFS":
|
|
dump,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],Dump)
|
|
self.moves.extend(result)
|
|
element_list.append(dump)
|
|
for x in element_list:
|
|
x.unvisited = True
|
|
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.moves_made = self.moves_made + 1 #moves counter
|
|
self.update_rect(self.x,self.y)
|