Added GA iteration run param

This commit is contained in:
Marcin Kostrzewski 2020-05-17 00:43:24 +02:00
parent 0225eda1eb
commit eed7d2ea82

View File

@ -50,15 +50,15 @@ class Game:
if len(argv) < 2: if len(argv) < 2:
print("No arguments specified.") print("No arguments specified.")
exit(1) exit(1)
if argv[1] == "test": elif argv[1] == "test":
self.testRun(filesPath) self.testRun(filesPath)
elif argv[1] == "ga": elif argv[1] == "ga" and len(argv) >= 3:
if len(argv) == 3 and argv[2] == "-t": if len(argv) >= 4 and argv[3] == "-t":
print("Running Genetic Algorithm in multithreaded mode") print("Running Genetic Algorithm in multithreaded mode, iter = ", argv[2])
self.gaRun(filesPath, multithread=True) self.gaRun(filesPath, int(argv[2]), multithread=True)
else: else:
print("Running Genetic Algorithm in singlethreaded mode") print("Running Genetic Algorithm in singlethreaded mode, iter = ", argv[2])
self.gaRun(filesPath) self.gaRun(filesPath, int(argv[2]))
else: else:
print("Invalid gamemode. \n Possible options: test, ga") print("Invalid gamemode. \n Possible options: test, ga")
@ -144,7 +144,7 @@ class Game:
# Start game loop # Start game loop
self.mainLoop() self.mainLoop()
def gaRun(self, filesPath, multithread=False): def gaRun(self, filesPath, iter, multithread=False):
""" """
Runs the game in GA mode - runs genetic algorithm in headless mode. Runs the game in GA mode - runs genetic algorithm in headless mode.
@ -171,7 +171,7 @@ class Game:
# Run GA: # Run GA:
self.pgTimer.tick() self.pgTimer.tick()
geneticAlgorithm(self.map, 30, 10, 0.1, multithread) geneticAlgorithm(self.map, iter, 10, 0.1, multithread)
print("Time elapsed: ", self.pgTimer.tick() // 1000) print("Time elapsed: ", self.pgTimer.tick() // 1000)
def mainLoop(self): def mainLoop(self):