Added startup flags

This commit is contained in:
Magdalena Wilczyńska 2019-05-30 19:37:26 +02:00
parent 15f88b9e20
commit 635292d9f5
4 changed files with 34 additions and 5 deletions

View File

@ -2,12 +2,12 @@ from DataModels.Cell import Cell
from DataModels.Road import Road from DataModels.Road import Road
from DataModels.House import House from DataModels.House import House
from DataModels.Dump import Dump from DataModels.Dump import Dump
from config import GRID_WIDTH, GRID_HEIGHT, DELAY from config import GRID_WIDTH, GRID_HEIGHT, DELAY, CLOSE_ON_END
from utilities import movement, check_moves, save_moveset from utilities import movement, check_moves, save_moveset
from Traversal.DFS import DFS from Traversal.DFS import DFS
from Traversal.BestFS import BestFS from Traversal.BestFS import BestFS
from Traversal.BFS import BFS from Traversal.BFS import BFS
import pygame import pygame, sys
class GC(Cell): class GC(Cell):
moves_made = 0 moves_made = 0
@ -109,6 +109,9 @@ class GC(Cell):
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:
if(len(self.moves)==0 and CLOSE_ON_END):
print("DONE")
sys.exit()
return return
self.old_time = pygame.time.get_ticks() self.old_time = pygame.time.get_ticks()
if self.moves[-1] == "pick_garbage": if self.moves[-1] == "pick_garbage":

View File

@ -11,9 +11,24 @@ try:
else: else:
MAP_NAME = map_mode MAP_NAME = map_mode
except: except:
print("ERROR: Invalid map mode") print("ERROR: Invalid map mode\n Please enter \"auto\" for generated map or provide a path to an existing map.")
sys.exit() sys.exit()
if(len(sys.argv)>2):
CLOSE_ON_END = sys.argv[2]
if(CLOSE_ON_END != "true" and CLOSE_ON_END != "false"):
print("ERROR: Invalid close on end statement\n Please enter \"true\" or \"false\" to specify if app has to shut after finding solution.")
sys.exit()
else:
print("ERROR: Invalid close on end statement\n Please enter \"true\" or \"false\" to specify if app has to shut after finding solution.")
sys.exit()
ALGORITHM = None
if(len(sys.argv)>3):
ALGORITHM = sys.argv[3]
if(ALGORITHM != "bfs" and ALGORITHM != "dfs" and ALGORITHM!= "bestfs"):
print("ERROR: Invalid agorithm statement\n Please enter \"bfs\", \"dfs\" or \"bestfs\" to specify algorithm you want to use.")
sys.exit()
map = open( MAP_NAME, 'r' ) map = open( MAP_NAME, 'r' )

13
main.py
View File

@ -3,7 +3,7 @@
import pygame import pygame
import sys import sys
from random import randint from random import randint
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y, MAP_NAME from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y, MAP_NAME, ALGORITHM
from PIL import Image,ImageDraw from PIL import Image,ImageDraw
@ -21,6 +21,8 @@ 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)
algorithm = ALGORITHM
map = open(MAP_NAME, 'r') map = open(MAP_NAME, 'r')
map.readline() map.readline()
map.readline() map.readline()
@ -83,6 +85,15 @@ pygame_sprites.add(gc)
while True: while True:
if(algorithm != None):
if(algorithm == "bfs"):
gc.find_houses(map_objects,house_count,dump_count, "BFS")
elif(algorithm == "dfs"):
gc.find_houses(map_objects,house_count,dump_count, "DFS")
elif (algorithm == "bestfs"):
gc.find_houses_BestFS(map_objects)
algorithm = None
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
pygame.quit() pygame.quit()

View File

@ -3,5 +3,5 @@
) )
for($i = 1; $i -le $loop; $i++){ for($i = 1; $i -le $loop; $i++){
python main.py python main.py auto true bestfs
} }