GC now recognizes houses as he passes

This commit is contained in:
Magdalena Wilczyńska 2019-04-23 20:48:14 +02:00
parent b93d49fa96
commit e2e09e4537
3 changed files with 30 additions and 6 deletions

View File

@ -38,10 +38,7 @@ class GC(Cell):
for cell in row: for cell in row:
goal = [] goal = []
if type(cell) == House and cell.container.is_full(): if type(cell) == House and cell.container.is_full():
goal.append([cell.x-1, cell.y]) goal.append([cell.x, 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: if len(self.moves) == 0:
x = self.x x = self.x
y = self.y y = self.y

View File

@ -9,3 +9,8 @@ class House(Cell):
self.container.yellow, self.container.green, self.container.blue = collector.container.add( self.container.yellow, self.container.green, self.container.blue = collector.container.add(
[self.container.yellow, self.container.green, self.container.blue]) [self.container.yellow, self.container.green, self.container.blue])
self.update_image() self.update_image()
def is_empty(self):
if(self.container.yellow == self.container.green == self.container.blue == 0):
return True
else: return False

View File

@ -1,7 +1,29 @@
from utilities import movement,check_moves from utilities import movement,check_moves
from DataModels.House import House
def DFS(grid, avaliable_movement, gc_moveset,goal): def DFS(grid, avaliable_movement, gc_moveset,goal):
print(gc_moveset) print("Moveset: "+str(gc_moveset))
if(gc_moveset[-1] in goal or len(avaliable_movement) == 0):
possible_goals = []
a = gc_moveset[-1][0]
b = gc_moveset[-1][1]
possible_goals.append([a+1,b])
possible_goals.append([a-1,b])
possible_goals.append([a,b+1])
possible_goals.append([a,b-1])
house_in_area = False
for location in possible_goals:
try:
if(type(grid[location[0]][location[1]]) == House):
house_in_area = True
break
except:
continue
print(str(house_in_area) + " possible goals: " + str(possible_goals) + " gc_moveset: " + str(gc_moveset[-1]))
if(house_in_area or len(avaliable_movement) == 0):
print("Do zwrocenia: ",gc_moveset) print("Do zwrocenia: ",gc_moveset)
return gc_moveset return gc_moveset
x,y = gc_moveset[-1] x,y = gc_moveset[-1]