Added execution parameters
This commit is contained in:
parent
4b75bebf5a
commit
7c6cc737e1
4
Run.py
4
Run.py
@ -1,7 +1,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
from src.game.Game import Game
|
from src.game.Game import Game
|
||||||
|
|
||||||
# TODO: Paths are still retarded
|
# TODO: Paths are still retarded
|
||||||
programPath = Path(".").resolve()
|
programPath = Path(".").resolve()
|
||||||
game = Game(programPath)
|
game = Game(programPath, sys.argv)
|
||||||
|
@ -15,15 +15,14 @@ from src.game.Timer import Timer
|
|||||||
|
|
||||||
# Main Game class
|
# Main Game class
|
||||||
class Game:
|
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.
|
Game script initialization. Loads all files, creates screen, map, tiles, entities and a player.
|
||||||
Starts the main game loop at the end.
|
Starts the main game loop at the end.
|
||||||
|
|
||||||
:param filesPath: Absolute path to the root of the gamefiles
|
: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
|
# If set to true, gameloop will run
|
||||||
self.running = False
|
self.running = False
|
||||||
# Config dict
|
# Config dict
|
||||||
@ -48,10 +47,19 @@ class Game:
|
|||||||
self.initializePygame()
|
self.initializePygame()
|
||||||
|
|
||||||
# Runnable selection
|
# Runnable selection
|
||||||
if gamemode == "test":
|
if len(argv) < 2:
|
||||||
|
print("No arguments specified.")
|
||||||
|
exit(1)
|
||||||
|
if argv[1] == "test":
|
||||||
self.testRun(filesPath)
|
self.testRun(filesPath)
|
||||||
elif gamemode == "ga":
|
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)
|
self.gaRun(filesPath)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Invalid gamemode. \n Possible options: test, ga")
|
print("Invalid gamemode. \n Possible options: test, ga")
|
||||||
exit(1)
|
exit(1)
|
||||||
@ -136,7 +144,7 @@ class Game:
|
|||||||
# Start game loop
|
# Start game loop
|
||||||
self.mainLoop()
|
self.mainLoop()
|
||||||
|
|
||||||
def gaRun(self, filesPath):
|
def gaRun(self, filesPath, 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.
|
||||||
|
|
||||||
@ -162,7 +170,9 @@ class Game:
|
|||||||
self.initializeMap(filesPath)
|
self.initializeMap(filesPath)
|
||||||
|
|
||||||
# Run GA:
|
# 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):
|
def mainLoop(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user