A boring overland world was generated from a grammar!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user