Basic FitnessEvaluator tries 10x to generate a level containing between 8 and 16 level components.

This commit is contained in:
Woody Folsom
2012-03-18 11:33:18 -04:00
parent d6516388ad
commit 7b6baaa538
3 changed files with 33 additions and 3 deletions

View File

@@ -82,6 +82,9 @@ public class PCGLevel extends Level {
String grammarFileName = "grammars/overland.grm";
grammar = LevelGrammarFactory.createGrammar(new File(grammarFileName));
System.out.println("Read grammar from file: " + grammarFileName);
System.out.println("==== LEVEL GRAMMAR ====");
System.out.println(grammar);
System.out.println("=======================");
} catch (Exception ex) {
System.out.println("Failed to parse grammar file due to exception: " + ex.getMessage());
System.out.println("Defaulting to basic overland grammar.");
@@ -185,6 +188,19 @@ public class PCGLevel extends Level {
else {
System.out.println("Generating level for component list: ");
LevelParseTree parseTree = grammar.generateRandomTree(seed, width);
int MAX_REGENS = 10;
int nRegens = 0;
while (!FitnessEvaluator.isFit(parseTree,profile,archetype) && nRegens < MAX_REGENS) {
System.out.println("Generated level is NOT fit. Regenerating...");
parseTree = grammar.generateRandomTree(seed, width);
nRegens++;
}
if (nRegens == MAX_REGENS) {
System.out.println("Failed to generate a fit level after " + nRegens + " attempts. Proceeding with unfit level.");
}
List<LevelComponent> levelTemplate = parseTree.getLevelTemplate();
for (LevelComponent lcomp : levelTemplate) {