diff --git a/DataModels/GC.py b/DataModels/GC.py index e19e47f..66425bc 100644 --- a/DataModels/GC.py +++ b/DataModels/GC.py @@ -38,10 +38,7 @@ class GC(Cell): 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]) + goal.append([cell.x, cell.y]) if len(self.moves) == 0: x = self.x y = self.y diff --git a/DataModels/House.py b/DataModels/House.py index 64dae2a..6d9fe1c 100644 --- a/DataModels/House.py +++ b/DataModels/House.py @@ -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]) self.update_image() + + def is_empty(self): + if(self.container.yellow == self.container.green == self.container.blue == 0): + return True + else: return False diff --git a/Traversal/DFS.py b/Traversal/DFS.py index 38ce927..8b11192 100644 --- a/Traversal/DFS.py +++ b/Traversal/DFS.py @@ -1,7 +1,29 @@ from utilities import movement,check_moves +from DataModels.House import House def DFS(grid, avaliable_movement, gc_moveset,goal): - print(gc_moveset) - if(gc_moveset[-1] in goal or len(avaliable_movement) == 0): + print("Moveset: "+str(gc_moveset)) + + 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) return gc_moveset x,y = gc_moveset[-1]