Implemented stochastic grammar. Work in progress.

This commit is contained in:
Woody Folsom
2012-03-17 22:23:38 -04:00
parent 1790d48393
commit 7d747765ef
9 changed files with 244 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
package dk.itu.mario.level.grammar;
import dk.itu.mario.level.LevelArchetype;
import dk.itu.mario.level.LevelComponent;
import dk.itu.mario.level.PlayerProfile;
@@ -8,16 +9,61 @@ public class LevelGrammarFactory {
public static LevelGrammar createGrammar(PlayerProfile playerProfile, LevelArchetype archetype) {
LevelGrammar grammar = new LevelGrammar();
Variable v_S = new Variable("S");
Variable v_level_start = new Variable("level_start");
Variable v_level_end = new Variable("level_end");
Variable v_START = new Variable("S", LevelComponent.TYPE.LEVEL);
Variable v_LAND_SEGMENT = new Variable("HALF_LVL", LevelComponent.TYPE.LEVEL_SEGMENT);
Variable v_LO_HI = new Variable("LO_HI", LevelComponent.TYPE.LO_HI);
Variable v_HI_LO = new Variable("HI_LO", LevelComponent.TYPE.HI_LO);
Variable v_LO_PATH = new Variable("LO_PATH", LevelComponent.TYPE.LO_PATH);
Variable v_HI_PATH = new Variable("HI_PATH", LevelComponent.TYPE.HI_PATH);
Variable v_lo_path = new Variable("lo_path", LevelComponent.TYPE.LO_PATH);
Variable v_hi_path = new Variable("hi_path", LevelComponent.TYPE.HI_PATH);
grammar.addVariable(v_S);
grammar.addVariable(v_level_start);
grammar.addVariable(v_level_end);
grammar.addVariable(v_START);
grammar.addVariable(v_LAND_SEGMENT);
grammar.addVariable(v_LO_HI);
grammar.addVariable(v_HI_LO);
grammar.addVariable(v_LO_PATH);
grammar.addVariable(v_HI_PATH);
grammar.addProductionRule(new ProductionRule(v_S,v_level_start,v_level_end));
grammar.setStart(v_S);
grammar.addProductionRule(new ProductionRule(v_START,v_LAND_SEGMENT,v_LAND_SEGMENT));
grammar.addProductionRule(
new ProductionRule(v_LAND_SEGMENT,
new OrClause( new double[] {0.25,0.65,0.10},
new AndClause(v_LO_HI,v_HI_LO),
v_LO_PATH,
new AndClause(v_LAND_SEGMENT,v_LAND_SEGMENT)
)
)
);
grammar.addProductionRule(
new ProductionRule(v_LO_HI, v_LO_PATH, v_HI_PATH)
);
grammar.addProductionRule(
new ProductionRule(v_HI_LO, v_HI_PATH, v_LO_PATH)
);
grammar.addProductionRule(
new ProductionRule(v_HI_PATH,
new OrClause( new double[] {0.25,0.75},
new AndClause(v_HI_PATH,v_HI_PATH),
v_hi_path
)
)
);
grammar.addProductionRule(
new ProductionRule(v_LO_PATH,
new OrClause( new double[] {0.25,0.75},
new AndClause(v_LO_PATH,v_LO_PATH),
v_lo_path
)
)
);
grammar.setStart(v_START);
return grammar;
}