From 7c6cc737e17ff905c51040af7f41d682eb94e06c Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sun, 17 May 2020 00:27:53 +0200 Subject: [PATCH] Added execution parameters --- Run.py | 4 ++-- src/game/Game.py | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Run.py b/Run.py index cb169de..e530fcd 100644 --- a/Run.py +++ b/Run.py @@ -1,7 +1,7 @@ from pathlib import Path - +import sys from src.game.Game import Game # TODO: Paths are still retarded programPath = Path(".").resolve() -game = Game(programPath) +game = Game(programPath, sys.argv) diff --git a/src/game/Game.py b/src/game/Game.py index d740e34..5204c31 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -15,15 +15,14 @@ from src.game.Timer import Timer # Main Game class class Game: - def __init__(self, filesPath, gamemode="ga"): + def __init__(self, filesPath, argv): """ Game script initialization. Loads all files, creates screen, map, tiles, entities and a player. Starts the main game loop at the end. :param filesPath: Absolute path to the root of the gamefiles - :param gamemode: Mode to run. Currently, there's only test gamemode. + :param argv: Runnable arguments """ - # If set to true, gameloop will run self.running = False # Config dict @@ -48,10 +47,19 @@ class Game: self.initializePygame() # Runnable selection - if gamemode == "test": + if len(argv) < 2: + print("No arguments specified.") + exit(1) + if argv[1] == "test": self.testRun(filesPath) - elif gamemode == "ga": - self.gaRun(filesPath) + elif argv[1] == "ga": + if len(argv) == 3 and argv[2] == "-t": + print("Running Genetic Algorithm in multithreaded mode") + self.gaRun(filesPath, multithread=True) + else: + print("Running Genetic Algorithm in singlethreaded mode") + self.gaRun(filesPath) + else: print("Invalid gamemode. \n Possible options: test, ga") exit(1) @@ -136,7 +144,7 @@ class Game: # Start game loop self.mainLoop() - def gaRun(self, filesPath): + def gaRun(self, filesPath, multithread=False): """ Runs the game in GA mode - runs genetic algorithm in headless mode. @@ -162,7 +170,9 @@ class Game: self.initializeMap(filesPath) # Run GA: - geneticAlgorithm(self.map, 200, 8, 0.05) + self.pgTimer.tick() + geneticAlgorithm(self.map, 30, 10, 0.1, multithread) + print("Time elapsed: ", self.pgTimer.tick() // 1000) def mainLoop(self): """