From d4cbe19f6e651727cf754892a5c94bbcf09582ab Mon Sep 17 00:00:00 2001 From: Magdalena Wilczynska Date: Mon, 13 May 2019 10:29:34 +0200 Subject: [PATCH] Added missing files --- DataModels/GC.py | 24 +++++++++++++++++++++++- main.py | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/DataModels/GC.py b/DataModels/GC.py index e7d1015..7db3d9e 100644 --- a/DataModels/GC.py +++ b/DataModels/GC.py @@ -5,6 +5,7 @@ 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.BestFS import BestFS import pygame class GC(Cell): @@ -36,7 +37,7 @@ class GC(Cell): item.return_trash(self) self.update_image() - def get_moves_made(self): + def get_moves_count(self): return self.moves_made def find_houses(self,enviromnent, house_count): x = self.x @@ -48,6 +49,27 @@ class GC(Cell): self.moves.extend(result) self.moves.reverse() + def find_houses_BestFS(self,enviromnent, house_count): + x = self.x + y = self.y + result = [] + + houses_list = [] + a = 0 + for row in enviromnent: + b = 0 + for col in row: + print(col) + if (type(col) is House): + houses_list.append([col,[a,b]]) + b += 1 + a += 1 + + for home in range(house_count): + avalible_moves = check_moves(enviromnent, x,y) + [x,y],result = BestFS(enviromnent,avalible_moves,[[x,y]],houses_list) + self.moves.extend(result) + self.moves.reverse() def make_actions_from_list(self,environment): now = pygame.time.get_ticks() diff --git a/main.py b/main.py index 7cb7292..081fb7f 100755 --- a/main.py +++ b/main.py @@ -96,6 +96,8 @@ while True: gc.collect(map_objects) elif event.key == pygame.K_0: gc.find_houses(map_objects,house_count) + elif event.key == pygame.K_9: + gc.find_houses_BestFS(map_objects,house_count) gc.make_actions_from_list(map_objects) pygame_sprites.update() @@ -107,7 +109,7 @@ while True: GAME_WINDOW.blit(bg_rect, (0, WINDOW_HEIGHT-30)) font = pygame.font.SysFont("monospace", 15) - gc_moves = font.render("Moves: " + str(gc.get_moves_made()), 1, (255,255,255)) + gc_moves = font.render("Moves: " + str(gc.get_moves_count()), 1, (255,255,255)) GAME_WINDOW.blit(gc_moves, (10, WINDOW_HEIGHT - 25)) pygame.display.flip()