Merge branch 'master' of woodyfolsom.net:/opt/git/cs8803p3
Conflicts: src/dk/itu/mario/level/matcher/ProfileMatcher.java
This commit is contained in:
@@ -9,7 +9,8 @@ import java.io.Serializable;
|
||||
public class GamePlay implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final GamePlay DEFAULT_PROFILE = new GamePlay();
|
||||
|
||||
public int completionTime; // counts only the current run on the level,
|
||||
// excluding death games
|
||||
public int totalTime;// sums all the time, including from previous games if
|
||||
@@ -96,6 +97,7 @@ public class GamePlay implements Serializable {
|
||||
// TODO Auto-generated catch block
|
||||
//e.printStackTrace();
|
||||
System.out.println("Unable to read from GamePlay file: " + fileName + ", initializing a new GamePlay instance.");
|
||||
gp = GamePlay.DEFAULT_PROFILE;
|
||||
}
|
||||
return gp;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class MarioComponent extends JComponent implements Runnable,
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
//while (true) {
|
||||
graphicsConfiguration = getGraphicsConfiguration();
|
||||
|
||||
Art.init(graphicsConfiguration, sound);
|
||||
@@ -191,7 +191,7 @@ public class MarioComponent extends JComponent implements Runnable,
|
||||
Mario.fire = false;
|
||||
Mario.large = false;
|
||||
Mario.coins = 0;
|
||||
Mario.lives = 3;
|
||||
Mario.lives = 1;
|
||||
|
||||
randomLevel.init();
|
||||
randomLevel.setSound(sound);
|
||||
@@ -262,6 +262,7 @@ public class MarioComponent extends JComponent implements Runnable,
|
||||
}
|
||||
|
||||
Art.stopMusic();
|
||||
//}
|
||||
}
|
||||
|
||||
private void drawString(Graphics g, String text, int x, int y, int c) {
|
||||
|
||||
@@ -8,7 +8,23 @@ public class FitnessEvaluator {
|
||||
public static boolean isFit(LevelParseTree parseTree, PlayerProfile playerProfile, LevelArchetype levelArchetype) {
|
||||
System.out.println("Evaluating LevelParseTree for fitness");
|
||||
List<LevelComponent> levelTemplate = parseTree.getLevelTemplate();
|
||||
//a good level has 8-16 components, plus some additional complexity depending on the player's skill level
|
||||
return levelTemplate.size() > 9 && levelTemplate.size() < 25;
|
||||
//a good level has 8-24 components, plus some additional complexity depending on the player's skill level
|
||||
|
||||
if (levelTemplate.size() < 8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (levelTemplate.size() > 24) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (LevelComponent lc : levelTemplate) {
|
||||
if (!playerProfile.isEnabled(lc.getType())) {
|
||||
System.out.println("Level is not fit: " + lc.getType() + " is not enabled.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ public class PCGLevel extends Level {
|
||||
|
||||
setSpriteTemplate(xo + 2, floor - 1, new SpriteTemplate(
|
||||
SpriteTemplate.RED_TURTLE, false));
|
||||
ENEMIES++;
|
||||
|
||||
for (int x = 5; x < 26; x++) {
|
||||
for (int y = floor - 3; y < height; y++) {
|
||||
@@ -216,30 +217,37 @@ public class PCGLevel extends Level {
|
||||
&& x >= 11 && x <= 23) {
|
||||
if (x == 15) {
|
||||
setBlock(xo + x, floor - 6, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 16) {
|
||||
setBlock(xo + x, floor - 7, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 18) {
|
||||
setBlock(xo + x, floor - 8, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 19) {
|
||||
setBlock(xo + x, floor - 8, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 20) {
|
||||
setBlock(xo + x, floor - 8, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 22) {
|
||||
setBlock(xo + x, floor - 7, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (x == 23) {
|
||||
setBlock(xo + x, floor - 6, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,21 +255,30 @@ public class PCGLevel extends Level {
|
||||
&& reward == PlayerProfile.ChallengeRewardType.COIN
|
||||
&& x >= 10 && x <= 20) {
|
||||
setBlock(xo + x, floor - 6, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (reward == PlayerProfile.ChallengeRewardType.BLOCK
|
||||
&& x >= 13 && x <= 17) {
|
||||
setBlock(
|
||||
xo + x,
|
||||
floor - 6,
|
||||
(random.nextDouble() <= probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP)) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
byte tile = (random.nextDouble() <= probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP)) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
|
||||
setBlock(xo + x, floor - 6, tile);
|
||||
|
||||
if (tile == Level.BLOCK_COIN) {
|
||||
BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
BLOCKS_POWER++;
|
||||
}
|
||||
}
|
||||
|
||||
if (x >= 26 - numEnemies) {
|
||||
setSpriteTemplate(xo + x, floor - 4, new SpriteTemplate(
|
||||
enemyType, false));
|
||||
ENEMIES++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,16 +329,22 @@ public class PCGLevel extends Level {
|
||||
|
||||
if (x > 2 && x < 6) {
|
||||
setBlock(xo + x, floor - 3, Level.BLOCK_EMPTY);
|
||||
this.BLOCKS_EMPTY++;
|
||||
} else if (x > 2 && x < 11) {
|
||||
setBlock(xo + x, floor - 5, Level.BLOCK_EMPTY);
|
||||
this.BLOCKS_EMPTY++;
|
||||
} else if (x == 11 || x == 12) {
|
||||
setBlock(xo + x, floor - 6, Level.COIN);
|
||||
COINS++;
|
||||
} else if (x == 13) {
|
||||
setBlock(xo + x, floor - 5, Level.COIN);
|
||||
COINS++;
|
||||
} else if (x == 14) {
|
||||
setBlock(xo + x, floor - 4, Level.COIN);
|
||||
COINS++;
|
||||
} else if (x == 15) {
|
||||
setBlock(xo + x, floor - 3, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,11 +372,14 @@ public class PCGLevel extends Level {
|
||||
|
||||
setSpriteTemplate(xo + 6, floor - 1, new SpriteTemplate(
|
||||
SpriteTemplate.GREEN_TURTLE, false));
|
||||
|
||||
this.BLOCKS_EMPTY++;
|
||||
this.BLOCKS_POWER++;
|
||||
this.ENEMIES++;
|
||||
}
|
||||
|
||||
else {
|
||||
int powerupLoc = random.nextInt(5);
|
||||
|
||||
setBlock(xo + 2, floor - 3,
|
||||
powerupLoc == 0 ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
@@ -369,6 +395,9 @@ public class PCGLevel extends Level {
|
||||
setBlock(xo + 6, floor - 3,
|
||||
powerupLoc == 4 ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
|
||||
this.BLOCKS_COINS += 4;
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
return 9;
|
||||
@@ -387,12 +416,18 @@ public class PCGLevel extends Level {
|
||||
setBlock(xo, floor - 1, Level.BLOCK_EMPTY);
|
||||
setBlock(xo + 4, floor - 1, Level.BLOCK_POWERUP);
|
||||
|
||||
this.BLOCKS_EMPTY++;
|
||||
this.BLOCKS_POWER++;
|
||||
|
||||
setSpriteTemplate(xo + 3, floor - 1, new SpriteTemplate(
|
||||
SpriteTemplate.GREEN_TURTLE, false));
|
||||
|
||||
this.ENEMIES++;
|
||||
}
|
||||
|
||||
else {
|
||||
setBlock(xo + 2, floor - 3, Level.BLOCK_POWERUP);
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
return 5;
|
||||
@@ -427,21 +462,30 @@ public class PCGLevel extends Level {
|
||||
if (x > 6 && x % 2 == 0) {
|
||||
setSpriteTemplate(xo + x, floor - 5, new SpriteTemplate(
|
||||
enemyType, flying));
|
||||
ENEMIES++;
|
||||
}
|
||||
|
||||
if (reward == PlayerProfile.ChallengeRewardType.COIN && x >= 7
|
||||
&& x <= 16) {
|
||||
setBlock(xo + x, floor - 7, Level.COIN);
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (reward == PlayerProfile.ChallengeRewardType.BLOCK
|
||||
&& x >= 10 && x <= 13) {
|
||||
setBlock(
|
||||
xo + x,
|
||||
floor - 7,
|
||||
random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
byte tile = random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
|
||||
setBlock(xo + x, floor - 7, tile);
|
||||
|
||||
if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 18;
|
||||
@@ -589,6 +633,7 @@ public class PCGLevel extends Level {
|
||||
setSpriteTemplate(xo + soFar + x, this.height
|
||||
- heightMod, new SpriteTemplate(enemyType,
|
||||
false));
|
||||
ENEMIES++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -652,6 +697,7 @@ public class PCGLevel extends Level {
|
||||
setSpriteTemplate(xo + length, height - localHeight,
|
||||
new SpriteTemplate(SpriteTemplate.JUMP_FLOWER,
|
||||
false));
|
||||
ENEMIES++;
|
||||
}
|
||||
|
||||
length += 2;
|
||||
@@ -821,11 +867,13 @@ public class PCGLevel extends Level {
|
||||
enemyType,
|
||||
(enemyType == SpriteTemplate.RED_TURTLE && shouldAddChallenge(PlayerProfile.ChallengeRewardType.HARDER_ENEMY))
|
||||
|| enemyType != SpriteTemplate.RED_TURTLE));
|
||||
ENEMIES++;
|
||||
}
|
||||
|
||||
reward = shouldAddReward();
|
||||
if (reward == PlayerProfile.ChallengeRewardType.COIN
|
||||
&& hold != LevelComponent.PlatformLevel.TOP) {
|
||||
|
||||
setBlock(xo + length, this.height - heightMod - 3,
|
||||
Level.COIN);
|
||||
setBlock(xo + length + 1, this.height - heightMod - 3,
|
||||
@@ -834,22 +882,38 @@ public class PCGLevel extends Level {
|
||||
Level.COIN);
|
||||
setBlock(xo + length + 3, this.height - heightMod - 3,
|
||||
Level.COIN);
|
||||
|
||||
COINS += 4;
|
||||
}
|
||||
|
||||
else if (reward == PlayerProfile.ChallengeRewardType.BLOCK
|
||||
&& hold != LevelComponent.PlatformLevel.TOP) {
|
||||
setBlock(
|
||||
xo + length + 1,
|
||||
this.height - heightMod - 3,
|
||||
random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + length + 2,
|
||||
this.height - heightMod - 3,
|
||||
random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
|
||||
byte tile = random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + length + 1, this.height - heightMod - 3, tile);
|
||||
|
||||
if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + length + 2, this.height - heightMod - 3, tile);
|
||||
|
||||
if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
}
|
||||
|
||||
length += 4 + gapLength;
|
||||
@@ -953,10 +1017,12 @@ public class PCGLevel extends Level {
|
||||
new SpriteTemplate(
|
||||
enemyType,
|
||||
shouldAddChallenge(PlayerProfile.ChallengeRewardType.HARDER_ENEMY)));
|
||||
ENEMIES++;
|
||||
}
|
||||
}
|
||||
|
||||
if (reward != null) {
|
||||
byte tile;
|
||||
if (length >= 13) {
|
||||
setBlock(xo + (length - 11), floor - 3, Level.COIN);
|
||||
setBlock(xo + (length - 10), floor - 4, Level.COIN);
|
||||
@@ -965,48 +1031,104 @@ public class PCGLevel extends Level {
|
||||
setBlock(xo + (length - 6), floor - 5, Level.COIN);
|
||||
setBlock(xo + (length - 4), floor - 4, Level.COIN);
|
||||
setBlock(xo + (length - 3), floor - 3, Level.COIN);
|
||||
|
||||
COINS += 7;
|
||||
}
|
||||
|
||||
else if (length >= 7) {
|
||||
int start = length / 2;
|
||||
boolean coins = (reward == PlayerProfile.ChallengeRewardType.COIN);
|
||||
|
||||
setBlock(
|
||||
xo + (start - 2),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + (start - 1),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + start,
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + (start + 1),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start - 2), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start - 1), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + start, floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start + 1), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
if (length % 2 != 0) {
|
||||
setBlock(
|
||||
xo + (start + 2),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start + 2), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1014,27 +1136,59 @@ public class PCGLevel extends Level {
|
||||
int start = length / 2;
|
||||
boolean coins = (reward == PlayerProfile.ChallengeRewardType.COIN);
|
||||
|
||||
setBlock(
|
||||
xo + (start - 1),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + start,
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
setBlock(
|
||||
xo + (start + 1),
|
||||
floor - 3,
|
||||
coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN);
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start - 1), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + start, floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
|
||||
tile = coins ? Level.COIN
|
||||
: random.nextDouble() < probability
|
||||
.get(PlayerProfile.ChallengeRewardType.POWERUP) ? Level.BLOCK_POWERUP
|
||||
: Level.BLOCK_COIN;
|
||||
setBlock(xo + (start + 1), floor - 3, tile);
|
||||
|
||||
if (coins) {
|
||||
COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_COIN) {
|
||||
this.BLOCKS_COINS++;
|
||||
}
|
||||
|
||||
else if (tile == Level.BLOCK_POWERUP) {
|
||||
this.BLOCKS_POWER++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,7 +1265,7 @@ public class PCGLevel extends Level {
|
||||
System.out.println("Generating level for component list: ");
|
||||
LevelParseTree parseTree = grammar.generateRandomTree(seed, width);
|
||||
|
||||
int MAX_REGENS = 10;
|
||||
int MAX_REGENS = 30;
|
||||
int nRegens = 0;
|
||||
while (!FitnessEvaluator.isFit(parseTree, profile, archetype)
|
||||
&& nRegens < MAX_REGENS) {
|
||||
@@ -1121,58 +1275,70 @@ public class PCGLevel extends Level {
|
||||
nRegens++;
|
||||
}
|
||||
|
||||
List<LevelComponent> levelTemplate = parseTree.getLevelTemplate();
|
||||
|
||||
if (nRegens == MAX_REGENS) {
|
||||
System.out.println("Failed to generate a fit level after "
|
||||
+ nRegens + " attempts. Proceeding with unfit level.");
|
||||
} else {
|
||||
System.out.println("Found fit level:");
|
||||
for (LevelComponent lc : levelTemplate) {
|
||||
System.out.println(lc);
|
||||
}
|
||||
}
|
||||
|
||||
List<LevelComponent> levelTemplate = parseTree.getLevelTemplate();
|
||||
|
||||
for (LevelComponent lcomp : levelTemplate) {
|
||||
LevelComponent.TYPE lctype = lcomp.getType();
|
||||
System.out.println("Building for: " + lcomp);
|
||||
while (length < Math.min(width - 64, lcomp.getEnd())) {
|
||||
int lcLength;
|
||||
switch (lctype) {
|
||||
case FLAT_LO:
|
||||
case FLAT_HI:
|
||||
length += buildStraight(length, lcomp.getEnd(), true);
|
||||
lcLength = buildStraight(length, lcomp.getEnd(), true);
|
||||
break;
|
||||
case PIPE_JUMP:
|
||||
length += buildPipeJump(length, width - 64 - length);
|
||||
lcLength = buildPipeJump(length, width - 64 - length);
|
||||
break;
|
||||
case PLATFORM_JUMP:
|
||||
length += buildPlatformJump(length, width - 64 - length);
|
||||
lcLength = buildPlatformJump(length, width - 64
|
||||
- length);
|
||||
break;
|
||||
case MAZE:
|
||||
length += buildMaze(length, width - 64 - length);
|
||||
lcLength = buildMaze(length, width - 64 - length);
|
||||
break;
|
||||
case BLOCKS:
|
||||
length += buildMaze(length, width - 64 - length);
|
||||
lcLength = buildMaze(length, width - 64 - length);
|
||||
break;
|
||||
case BOWLING_ALLEY :
|
||||
length += buildBowlingAlley(length, width - 64 - length);
|
||||
case BOWLING_ALLEY:
|
||||
lcLength = buildBowlingAlley(length, width - 64
|
||||
- length);
|
||||
break;
|
||||
case CANNON_LINE :
|
||||
length += buildCannonLine(length, width - 64 - length);
|
||||
case CANNON_LINE:
|
||||
lcLength = buildCannonLine(length, width - 64 - length);
|
||||
break;
|
||||
case COIN_DIVE :
|
||||
length += buildCoinDive(length, width - 64 - length);
|
||||
case COIN_DIVE:
|
||||
lcLength = buildCoinDive(length, width - 64 - length);
|
||||
break;
|
||||
case LEMMING_TRAP :
|
||||
length += buildLemmingTrap(length, width - 64 - length);
|
||||
case LEMMING_TRAP:
|
||||
lcLength = buildLemmingTrap(length, width - 64 - length);
|
||||
break;
|
||||
case POWER_UP :
|
||||
length += buildFreebie(length, width - 64 - length);
|
||||
//length += buildStraight(length, lcomp.getEnd(), true);
|
||||
case POWER_UP:
|
||||
lcLength = buildFreebie(length, width - 64 - length);
|
||||
break;
|
||||
case SINGLE_PIT :
|
||||
length += buildSinglePit(length, width - 64 - length);
|
||||
case SINGLE_PIT:
|
||||
lcLength = buildSinglePit(length, width - 64 - length);
|
||||
break;
|
||||
default:
|
||||
lcLength = 0;
|
||||
System.out
|
||||
.println("Cannot build level segment for unrecognized LevelComponent type: "
|
||||
+ type);
|
||||
}
|
||||
if (lcLength == 0) {
|
||||
lcLength = buildStraight(length, lcomp.getEnd(), true);
|
||||
}
|
||||
length += lcLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1243,8 +1409,8 @@ public class PCGLevel extends Level {
|
||||
playerMetrics, dataRecorder);
|
||||
System.out.println("PlayerProfile: " + profile);
|
||||
|
||||
LevelArchetype archetype = ArchetypeMatcher.getMatchingArchetype(
|
||||
playerMetrics, dataRecorder);
|
||||
LevelArchetype archetype = ArchetypeMatcher
|
||||
.getMatchingArchetype(profile);
|
||||
System.out.println("LevelArchetype: " + archetype);
|
||||
|
||||
System.out.println("Creating level grammar");
|
||||
|
||||
@@ -52,33 +52,26 @@ public class PlayerProfile {
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
public int getBumpSkill() {
|
||||
return skillVector.get(SKILL.BUMP);
|
||||
}
|
||||
public int getCollectSkill() {
|
||||
return skillVector.get(SKILL.COLLECT);
|
||||
}
|
||||
public int getJumpSkill() {
|
||||
switch (type) {
|
||||
case JUMPER:
|
||||
switch (skillLevel) {
|
||||
case NOVICE:
|
||||
return 20;
|
||||
case BEGINNER:
|
||||
return 40;
|
||||
case COMPETENT:
|
||||
return 60;
|
||||
case PROFICIENT:
|
||||
return 80;
|
||||
case EXPERT:
|
||||
return 100;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return skillVector.get(SKILL.JUMP);
|
||||
}
|
||||
public int getRunSkill() {
|
||||
return skillVector.get(SKILL.RUN);
|
||||
}
|
||||
public int getShootSkill() {
|
||||
return skillVector.get(SKILL.SHOOT);
|
||||
}
|
||||
public int getStompSkill() {
|
||||
return skillVector.get(SKILL.STOMP);
|
||||
}
|
||||
|
||||
public double getProbability(ChallengeRewardType crt) {
|
||||
// if (!isEnabled(type)) {
|
||||
// return 0.0;
|
||||
// }
|
||||
|
||||
public double getProbability(ChallengeRewardType crt) {
|
||||
switch (crt) {
|
||||
case GAP:
|
||||
return Math.min(.5, (.5) * (skillVector.get(SKILL.JUMP) / 100.0)
|
||||
|
||||
@@ -7,7 +7,11 @@ import dk.itu.mario.MarioInterface.LevelGenerator;
|
||||
import dk.itu.mario.MarioInterface.LevelInterface;
|
||||
import dk.itu.mario.engine.DataRecorder;
|
||||
import dk.itu.mario.level.Level;
|
||||
import dk.itu.mario.level.LevelArchetype;
|
||||
import dk.itu.mario.level.PCGLevel;
|
||||
import dk.itu.mario.level.PlayerProfile;
|
||||
import dk.itu.mario.level.matcher.ArchetypeMatcher;
|
||||
import dk.itu.mario.level.matcher.ProfileMatcher;
|
||||
|
||||
public class PCGLevelGenerator implements
|
||||
LevelGenerator {
|
||||
@@ -20,7 +24,21 @@ public class PCGLevelGenerator implements
|
||||
@Override
|
||||
public int generateLevelType(GamePlay playerMetrics, DataRecorder dataRecorder) {
|
||||
System.out.println("Generating level type based on playerMetrics, dataRecorder: TYPE_OVERGROUND");
|
||||
return Level.TYPE_OVERGROUND;
|
||||
PlayerProfile profile = ProfileMatcher.getMatchingProfile(
|
||||
playerMetrics, dataRecorder);
|
||||
System.out.println("PlayerProfile: " + profile);
|
||||
|
||||
LevelArchetype archetype = ArchetypeMatcher.getMatchingArchetype(profile);
|
||||
switch (archetype.getType()) {
|
||||
case CASTLE :
|
||||
return LevelInterface.TYPE_CASTLE;
|
||||
case OVERGROUND :
|
||||
return LevelInterface.TYPE_OVERGROUND;
|
||||
case UNDERGROUND :
|
||||
return LevelInterface.TYPE_UNDERGROUND;
|
||||
default :
|
||||
return LevelInterface.TYPE_OVERGROUND;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,48 @@
|
||||
package dk.itu.mario.level.matcher;
|
||||
|
||||
import dk.itu.mario.MarioInterface.GamePlay;
|
||||
import dk.itu.mario.engine.DataRecorder;
|
||||
import dk.itu.mario.level.LevelArchetype;
|
||||
import dk.itu.mario.level.LevelArchetype.TYPE;
|
||||
import dk.itu.mario.level.PlayerProfile;
|
||||
|
||||
public class ArchetypeMatcher {
|
||||
public static LevelArchetype getMatchingArchetype(GamePlay playerMetrics, DataRecorder detailedInfo) {
|
||||
System.out.println("Selecting PlayerProfile based on GamePlay metrics, DataRecorder logs.");
|
||||
return new LevelArchetype(TYPE.OVERGROUND,1);
|
||||
public static LevelArchetype getMatchingArchetype(
|
||||
PlayerProfile playerProfile) {
|
||||
System.out
|
||||
.println("Selecting PlayerProfile based on GamePlay metrics, DataRecorder logs.");
|
||||
|
||||
TYPE levelType;
|
||||
int primarySkill;
|
||||
|
||||
switch (playerProfile.getType()) {
|
||||
case BUMPER:
|
||||
levelType = TYPE.OVERGROUND;
|
||||
primarySkill = (int) Math
|
||||
.round(playerProfile.getBumpSkill() / 10.0);
|
||||
break;
|
||||
case COLLECTOR:
|
||||
levelType = TYPE.UNDERGROUND;
|
||||
primarySkill = (int) Math
|
||||
.round(playerProfile.getCollectSkill() / 10.0);
|
||||
break;
|
||||
case JUMPER:
|
||||
levelType = TYPE.CASTLE;
|
||||
primarySkill = (int) Math
|
||||
.round(playerProfile.getJumpSkill() / 10.0);
|
||||
break;
|
||||
case RUNNER:
|
||||
levelType = TYPE.OVERGROUND;
|
||||
primarySkill = (int) Math.round(playerProfile.getRunSkill() / 10.0);
|
||||
break;
|
||||
case SHOOTER:
|
||||
levelType = TYPE.UNDERGROUND;
|
||||
primarySkill = (int) Math
|
||||
.round(playerProfile.getShootSkill() / 10.0);
|
||||
break;
|
||||
default:
|
||||
levelType = TYPE.CASTLE;
|
||||
primarySkill = 1;
|
||||
}
|
||||
|
||||
return new LevelArchetype(levelType, Math.max(primarySkill,1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ public class ProfileMatcher {
|
||||
DataRecorder detailedInfo) {
|
||||
System.out
|
||||
.println("Selecting PlayerProfile based on GamePlay metrics, DataRecorder logs.");
|
||||
|
||||
// GAP comes from jump skill and jumper type.
|
||||
// ENEMY comes from run skill and runner type and stomp skill.
|
||||
// HARDER_ENEMY comes from shooting skill and shooting type.
|
||||
@@ -123,7 +122,7 @@ public class ProfileMatcher {
|
||||
// Relevant to: ENEMY.
|
||||
skillHolder = (int) (100 * ((((double) playerMetrics.timeSpentRunning)
|
||||
/ playerMetrics.totalTime + (playerMetrics.timesPressedRun / 75 > 1 ? 0
|
||||
: 1 - (playerMetrics.timesPressedRun / 75.0))) / 2));
|
||||
: 1 - (playerMetrics.timesPressedRun / 200))) / 2));
|
||||
skillVector.put(SKILL.RUN, new Integer(skillHolder));
|
||||
|
||||
// Get shoot skills.
|
||||
@@ -174,6 +173,8 @@ public class ProfileMatcher {
|
||||
|
||||
skillHolder /= skillVector.size();
|
||||
|
||||
skillHolder = (skillHolder + ((int) (100 * ((double) playerMetrics.timesSwichingPower / (playerMetrics.totalpowerBlocks * 2))))) / 2;
|
||||
|
||||
if (skillHolder >= 80) {
|
||||
skillLevel = SKILL_LEVEL.EXPERT;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class LevelSceneCustom extends LevelScene {
|
||||
|
||||
int levelType = clg.generateLevelType(gp,dataRecorder);
|
||||
currentLevel = (Level) clg.generateLevel(gp,dataRecorder);
|
||||
|
||||
|
||||
try {
|
||||
level = currentLevel.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
|
||||
Reference in New Issue
Block a user