Smieciarz wywala smieci na koniec
This commit is contained in:
parent
1963068dd6
commit
fa8cb46852
@ -5,6 +5,7 @@ class Dump( Cell ):
|
|||||||
def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ):
|
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 )
|
Cell.__init__( self, x, y, max_rubbish, yellow, green, blue, dump_type )
|
||||||
self.dump_type = dump_type
|
self.dump_type = dump_type
|
||||||
|
self.unvisited = True
|
||||||
|
|
||||||
def return_trash(self, collector):
|
def return_trash(self, collector):
|
||||||
dump_type = self.dump_type.lower()[5:]
|
dump_type = self.dump_type.lower()[5:]
|
||||||
|
@ -38,17 +38,22 @@ class GC(Cell):
|
|||||||
|
|
||||||
def get_moves_made(self):
|
def get_moves_made(self):
|
||||||
return self.moves_made
|
return self.moves_made
|
||||||
def find_houses(self,enviromnent, house_count):
|
def find_houses(self,enviromnent, house_count,dump_count):
|
||||||
x = self.x
|
x = self.x
|
||||||
y = self.y
|
y = self.y
|
||||||
result = []
|
result = []
|
||||||
for home in range(house_count):
|
for home in range(house_count):
|
||||||
avalible_moves = check_moves(enviromnent, x,y)
|
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.extend(result)
|
||||||
self.moves.reverse()
|
self.moves.reverse()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def make_actions_from_list(self,environment):
|
def make_actions_from_list(self,environment):
|
||||||
now = pygame.time.get_ticks()
|
now = pygame.time.get_ticks()
|
||||||
if len(self.moves)==0 or now - self.old_time <= DELAY:
|
if len(self.moves)==0 or now - self.old_time <= DELAY:
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from utilities import movement,check_moves
|
from utilities import movement,check_moves
|
||||||
from DataModels.House import House
|
from DataModels.House import House
|
||||||
|
from DataModels.Dump import Dump
|
||||||
from DataModels.Container import Container
|
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 = []
|
possible_goals = []
|
||||||
a = gc_moveset[-1][0]
|
a = gc_moveset[-1][0]
|
||||||
b = gc_moveset[-1][1]
|
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-1,b])
|
||||||
possible_goals.append([a,b+1])
|
possible_goals.append([a,b+1])
|
||||||
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:
|
for location in possible_goals:
|
||||||
if location[0]>=0 and location[1]>=0:
|
if GRID_WIDTH>location[0]>=0 and GRID_HEIGHT>location[1]>=0:
|
||||||
try:
|
cell = grid[location[0]][location[1]]
|
||||||
cell = grid[location[0]][location[1]]
|
if mode == "House":
|
||||||
if(type(cell) == House and cell.container.is_full and cell.unvisited):
|
if(type(cell) == House and cell.container.is_full and cell.unvisited):
|
||||||
cell.unvisited = False
|
cell.unvisited = False
|
||||||
house_in_area = True
|
object_in_area = True
|
||||||
break
|
break
|
||||||
except:
|
elif mode == "Dump":
|
||||||
continue
|
if(type(cell) == Dump and cell.unvisited):
|
||||||
if(house_in_area):
|
cell.unvisited = False
|
||||||
|
object_in_area = True
|
||||||
|
break
|
||||||
|
if(object_in_area):
|
||||||
xy = gc_moveset[-1]
|
xy = gc_moveset[-1]
|
||||||
gc_moveset.append("pick_garbage")
|
gc_moveset.append("pick_garbage")
|
||||||
return (xy, gc_moveset)
|
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)
|
available_movement_next = check_moves(grid, x_next,y_next,direction)
|
||||||
gc_moveset_next = gc_moveset.copy()
|
gc_moveset_next = gc_moveset.copy()
|
||||||
gc_moveset_next.append([x_next,y_next])
|
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:
|
if result!= None:
|
||||||
return result
|
return result
|
||||||
|
6
main.py
6
main.py
@ -17,6 +17,7 @@ pygame.init()
|
|||||||
|
|
||||||
pygame_sprites = pygame.sprite.Group()
|
pygame_sprites = pygame.sprite.Group()
|
||||||
house_count=0
|
house_count=0
|
||||||
|
dump_count=0
|
||||||
FPS_CLOCK = pygame.time.Clock()
|
FPS_CLOCK = pygame.time.Clock()
|
||||||
GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
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':
|
elif x is 'B':
|
||||||
map_objects[x_coord][y_coord] = generate(
|
map_objects[x_coord][y_coord] = generate(
|
||||||
x)(x_coord, y_coord, 100, "Dump_Blue")
|
x)(x_coord, y_coord, 100, "Dump_Blue")
|
||||||
|
dump_count+=1
|
||||||
elif x is 'G':
|
elif x is 'G':
|
||||||
map_objects[x_coord][y_coord] = generate(
|
map_objects[x_coord][y_coord] = generate(
|
||||||
x)(x_coord, y_coord, 100, "Dump_Green")
|
x)(x_coord, y_coord, 100, "Dump_Green")
|
||||||
|
dump_count+=1
|
||||||
elif x is 'Y':
|
elif x is 'Y':
|
||||||
map_objects[x_coord][y_coord] = generate(
|
map_objects[x_coord][y_coord] = generate(
|
||||||
x)(x_coord, y_coord, 100, "Dump_Yellow")
|
x)(x_coord, y_coord, 100, "Dump_Yellow")
|
||||||
|
dump_count+=1
|
||||||
elif x is 'R':
|
elif x is 'R':
|
||||||
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
|
||||||
i += 1
|
i += 1
|
||||||
@ -95,7 +99,7 @@ while True:
|
|||||||
elif event.key == pygame.K_SPACE:
|
elif event.key == pygame.K_SPACE:
|
||||||
gc.collect(map_objects)
|
gc.collect(map_objects)
|
||||||
elif event.key == pygame.K_0:
|
elif event.key == pygame.K_0:
|
||||||
gc.find_houses(map_objects,house_count)
|
gc.find_houses(map_objects,house_count,dump_count)
|
||||||
|
|
||||||
gc.make_actions_from_list(map_objects)
|
gc.make_actions_from_list(map_objects)
|
||||||
pygame_sprites.update()
|
pygame_sprites.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user