Merged with master

This commit is contained in:
Magdalena Wilczynska 2019-05-13 10:32:03 +02:00
commit e39b82b4a8
4 changed files with 28 additions and 13 deletions

View File

@ -5,6 +5,7 @@ class Dump( Cell ):
def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ):
Cell.__init__( self, x, y, max_rubbish, yellow, green, blue, dump_type )
self.dump_type = dump_type
self.unvisited = True
def return_trash(self, collector):
dump_type = self.dump_type.lower()[5:]

View File

@ -39,13 +39,17 @@ class GC(Cell):
def get_moves_count(self):
return self.moves_made
def find_houses(self,enviromnent, house_count):
def find_houses(self,enviromnent, house_count,dump_count):
x = self.x
y = self.y
result = []
for home in range(house_count):
avalible_moves = check_moves(enviromnent, x,y)
[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]])
[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],"House")
self.moves.extend(result)
for dump in range(dump_count):
avalible_moves = check_moves(enviromnent, x,y)
[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],"Dump")
self.moves.extend(result)
self.moves.reverse()
@ -71,6 +75,7 @@ class GC(Cell):
self.moves.extend(result)
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:

View File

@ -1,8 +1,10 @@
from utilities import movement,check_moves
from DataModels.House import House
from DataModels.Dump import Dump
from DataModels.Container import Container
from config import GRID_WIDTH, GRID_HEIGHT
def DFS(grid, available_movement, gc_moveset, depth=0):
def DFS(grid, available_movement, gc_moveset, mode,depth=0):
possible_goals = []
a = gc_moveset[-1][0]
b = gc_moveset[-1][1]
@ -10,18 +12,21 @@ def DFS(grid, available_movement, gc_moveset, depth=0):
possible_goals.append([a-1,b])
possible_goals.append([a,b+1])
possible_goals.append([a,b-1])
house_in_area = False
object_in_area = False
for location in possible_goals:
if location[0]>=0 and location[1]>=0:
try:
cell = grid[location[0]][location[1]]
if GRID_WIDTH>location[0]>=0 and GRID_HEIGHT>location[1]>=0:
cell = grid[location[0]][location[1]]
if mode == "House":
if(type(cell) == House and cell.container.is_full and cell.unvisited):
cell.unvisited = False
house_in_area = True
object_in_area = True
break
except:
continue
if(house_in_area):
elif mode == "Dump":
if(type(cell) == Dump and cell.unvisited):
cell.unvisited = False
object_in_area = True
break
if(object_in_area):
xy = gc_moveset[-1]
gc_moveset.append("pick_garbage")
return (xy, gc_moveset)
@ -34,6 +39,6 @@ def DFS(grid, available_movement, gc_moveset, depth=0):
available_movement_next = check_moves(grid, x_next,y_next,direction)
gc_moveset_next = gc_moveset.copy()
gc_moveset_next.append([x_next,y_next])
result = DFS(grid, available_movement_next, gc_moveset_next, depth+1)
result = DFS(grid, available_movement_next, gc_moveset_next,mode, depth+1)
if result!= None:
return result

View File

@ -17,6 +17,7 @@ pygame.init()
pygame_sprites = pygame.sprite.Group()
house_count=0
dump_count=0
FPS_CLOCK = pygame.time.Clock()
GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
@ -58,12 +59,15 @@ for y in map.readlines():
elif x is 'B':
map_objects[x_coord][y_coord] = generate(
x)(x_coord, y_coord, 100, "Dump_Blue")
dump_count+=1
elif x is 'G':
map_objects[x_coord][y_coord] = generate(
x)(x_coord, y_coord, 100, "Dump_Green")
dump_count+=1
elif x is 'Y':
map_objects[x_coord][y_coord] = generate(
x)(x_coord, y_coord, 100, "Dump_Yellow")
dump_count+=1
elif x is 'R':
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
i += 1
@ -95,7 +99,7 @@ while True:
elif event.key == pygame.K_SPACE:
gc.collect(map_objects)
elif event.key == pygame.K_0:
gc.find_houses(map_objects,house_count)
gc.find_houses(map_objects,house_count,dump_count)
elif event.key == pygame.K_9:
gc.find_houses_BestFS(map_objects,house_count)