A boring overland world was generated from a grammar!

This commit is contained in:
Woody Folsom
2012-03-17 14:15:38 -04:00
parent 8bedf88fd3
commit 653c7fc3df
7 changed files with 231 additions and 18 deletions

View File

@@ -7,6 +7,8 @@ import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import dk.itu.mario.level.LevelComponent.TYPE;
public class LevelGrammar {
private Variable start;
@@ -45,6 +47,24 @@ public class LevelGrammar {
return generateRandom(new Random().nextLong());
}
//TODO: refactor to recursively add children to the current node based on production rule
public LevelParseTree generateRandomTree(long randomSeed, int width) {
System.out.println("Generating random level parameters using seed: "
+ randomSeed);
List<Variable> startRuleRHS = getRule(getStart()).getRHS();
ParseNode rootNode = new ParseNode(TYPE.FLAT,1.0);
LevelParseTree parseTree = new LevelParseTree(rootNode, 0, width);
for (Variable var : startRuleRHS) {
if (var.isTerminal()) {
rootNode.addChild(new ParseNode(TYPE.FLAT,0.5));
}
}
return parseTree;
}
public ProductionRule getRule(Variable var) {
return ruleMap.get(var);
}