public void RunGame(VGDLGameAndLevel gameToRun, int randomSeed = -1) { if (numberOfRunsToEvaluate > 0 && runs >= numberOfRunsToEvaluate) { return; } InitializeGame(gameToRun, randomSeed); started = true; StartTime = new ElapsedCpuTimer(); ticks = 0; renderTicks = 0; }
public void InitializeGame(VGDLGameAndLevel gameToRun, int randomSeed = -1) { VGDLParser.verbose = verbose; //Try to remove all the old reference stuff... game?.reset(); game = null; game = LoadGame(gameToRun); if (players == null || players.Length < game.no_players) { var playerArr = new VGDLPlayerInterface[game.no_players]; for (int i = 0; i < playerArr.Length; i++) { if (players.Length > i) { playerArr[i] = players[i]; } else { var agent = new VGDLHumanAgent(); agent.PlayerID = i; playerArr[i] = agent; } } } game.prepareGame(players, randomSeed); started = false; ended = false; Time.captureFramerate = frameRateTarget; }
public static VGDLGame LoadGame(VGDLGameAndLevel gameToLoad, bool loadLevelsFromGameTree = false) { var exampleToLoad = ""; BasicGame game = null; switch (gameToLoad.type) { case VGDLExampleTypes.Unspecified: exampleToLoad += gameToLoad.filename; //File.ReadAllText break; case VGDLExampleTypes.GridPhysics: exampleToLoad += Path.Combine("gridphysics", gameToLoad.filename); game = LoadFromExampleString(exampleToLoad, loadLevelsFromGameTree); break; case VGDLExampleTypes.ContinuousPhysics: exampleToLoad += Path.Combine("contphysics", gameToLoad.filename); game = LoadFromExampleString(exampleToLoad, loadLevelsFromGameTree); break; case VGDLExampleTypes.TwoPlayer: exampleToLoad += Path.Combine("2player", gameToLoad.filename); game = LoadFromExampleString(exampleToLoad, loadLevelsFromGameTree); break; default: throw new ArgumentOutOfRangeException(); } //NOTE: Something went wrong if (game == null) { return(null); } game.name = exampleToLoad; if (loadLevelsFromGameTree) { if (game.levelList.Count > gameToLoad.level) { game.buildLevelFromLines(game.levelList[gameToLoad.level]); } else { Debug.LogError("Level " + gameToLoad.level + " not defined (levels are indexed from Zero)"); } } else { if (gameToLoad.type == VGDLExampleTypes.Unspecified) { //NOTE: we expect the levels to be located next to the game specification and named filename_lvl[#level].txt LoadLevelFromFile(game, gameToLoad.filename + "_lvl" + gameToLoad.level + ".txt"); } else { LoadLevelFromExampleString(game, exampleToLoad, gameToLoad.level); } } return(game); }