- Implemented the reward weighting.

- Fixed a balance issue with the blocks and coins on straight stretches of even length.
This commit is contained in:
Marshall
2012-03-18 13:42:59 -04:00
parent 4ce414408e
commit bc45062ad8
2 changed files with 111 additions and 69 deletions

View File

@@ -17,9 +17,9 @@ import dk.itu.mario.level.matcher.ArchetypeMatcher;
import dk.itu.mario.level.matcher.ProfileMatcher;
public class PCGLevel extends Level {
public static double POWERUP_PROBABILITY = .1;
public static double BLOCKS_PROBABILITY = .3;
public static double COINS_PROBABILITY = .5;
public double powerupProbability;
public double blocksProbability;
public double coinsProbability;
public static int COIN_REWARD = 1;
public static int POWERUP_REWARD = 2;
@@ -103,6 +103,13 @@ public class PCGLevel extends Level {
GrammarTuner.tune(grammar, profile, archetype);
System.out.println("Creating level.");
// TODO Refactor into a probability setter function so that we can set
// the challenge probabilities, too.
blocksProbability = profile.getProbability(TYPE.BLOCKS);
coinsProbability = profile.getProbability(TYPE.COINS);
powerupProbability = profile.getProbability(TYPE.POWER_UP);
create(seed, profile, archetype, grammar);
}
@@ -134,7 +141,8 @@ public class PCGLevel extends Level {
private void create(long seed, PlayerProfile profile,
LevelArchetype archetype, LevelGrammar grammar) {
System.out.println("PlayerProfile.getProbability(COINS): " + profile.getProbability(TYPE.COINS));
System.out.println("PlayerProfile.getProbability(COINS): "
+ profile.getProbability(TYPE.COINS));
if (dataRecorder == DataRecorder.BLANK_RECORD) {
System.out
@@ -486,7 +494,7 @@ public class PCGLevel extends Level {
setBlock(
xo + x,
floor - 6,
(random.nextDouble() <= POWERUP_PROBABILITY) ? Level.BLOCK_POWERUP
(random.nextDouble() <= powerupProbability) ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
}
@@ -539,7 +547,7 @@ public class PCGLevel extends Level {
setBlock(
xo + x,
floor - 7,
random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
}
}
@@ -681,9 +689,9 @@ public class PCGLevel extends Level {
private int shouldAddReward() {
double guess = random.nextDouble();
if (guess < COINS_PROBABILITY) {
if (guess < coinsProbability) {
return 1;
} else if (guess < COINS_PROBABILITY + BLOCKS_PROBABILITY) {
} else if (guess < coinsProbability + blocksProbability) {
return 2;
} else {
return 0;
@@ -1079,12 +1087,12 @@ public class PCGLevel extends Level {
setBlock(
xo + length + 1,
this.height - heightMod - 3,
random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + length + 2,
this.height - heightMod - 3,
random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
}
@@ -1152,7 +1160,8 @@ public class PCGLevel extends Level {
else {
setSpriteTemplate(xo + (length / 2), floor - 1,
new SpriteTemplate(enemyType, shouldAddChallenge(ChallengeType.HARDER_ENEMY)));
new SpriteTemplate(enemyType,
shouldAddChallenge(ChallengeType.HARDER_ENEMY)));
}
}
@@ -1175,32 +1184,34 @@ public class PCGLevel extends Level {
xo + (start - 2),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + (start - 1),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + start,
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + (start + 2),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + (start + 1),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
if (length % 2 != 0) {
setBlock(
xo + (start + 2),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
}
}
else if (length >= 5) {
@@ -1211,19 +1222,19 @@ public class PCGLevel extends Level {
xo + (start - 1),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + start,
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
setBlock(
xo + (start + 1),
floor - 3,
coins ? Level.COIN
: random.nextDouble() < POWERUP_PROBABILITY ? Level.BLOCK_POWERUP
: random.nextDouble() < powerupProbability ? Level.BLOCK_POWERUP
: Level.BLOCK_COIN);
}
}

View File

@@ -7,22 +7,29 @@ import java.util.Set;
import dk.itu.mario.level.matcher.ProfileMatcher.SKILL;
public class PlayerProfile {
//From Bartle/Yee models of player psychology: achiever, killer, explorer, manipulator
public enum TYPE { BUMPER, COLLECTOR, RUNNER, SHOOTER, JUMPER}
//Dreyfus model of skill acquisition:
public enum SKILL_LEVEL { NOVICE, BEGINNER, COMPETENT, PROFICIENT, EXPERT}
// From Bartle/Yee models of player psychology: achiever, killer, explorer,
// manipulator
public enum TYPE {
BUMPER, COLLECTOR, RUNNER, SHOOTER, JUMPER
}
// Dreyfus model of skill acquisition:
public enum SKILL_LEVEL {
NOVICE, BEGINNER, COMPETENT, PROFICIENT, EXPERT
}
private Set<LevelComponent.TYPE> enabledComponents = new HashSet<LevelComponent.TYPE>();
private SKILL_LEVEL skillLevel;
private Map<SKILL,Integer> skillVector;
private Map<SKILL, Integer> skillVector;
private TYPE type;
public PlayerProfile(SKILL_LEVEL skillLevel, TYPE type, Map<SKILL,Integer> skillVector) {
public PlayerProfile(SKILL_LEVEL skillLevel, TYPE type,
Map<SKILL, Integer> skillVector) {
this.skillLevel = skillLevel;
this .type = type;
this.type = type;
this.skillVector = skillVector;
for (LevelComponent.TYPE lcType: LevelComponent.TYPE.values()) {
for (LevelComponent.TYPE lcType : LevelComponent.TYPE.values()) {
setEnabled(lcType);
}
}
@@ -37,22 +44,22 @@ public class PlayerProfile {
public int getJumpSkill() {
switch (type) {
case JUMPER :
case JUMPER:
switch (skillLevel) {
case NOVICE :
case NOVICE:
return 20;
case BEGINNER :
case BEGINNER:
return 40;
case COMPETENT :
case COMPETENT:
return 60;
case PROFICIENT :
case PROFICIENT:
return 80;
case EXPERT :
case EXPERT:
return 100;
default :
default:
return 0;
}
default :
default:
return 0;
}
}
@@ -61,14 +68,38 @@ public class PlayerProfile {
if (!isEnabled(type)) {
return 0.0;
}
// SKILLs: { BUMP, COLLECT, JUMP, RUN, SHOOT, STOMP }
// TYPEs: { BUMPER, COLLECTOR, RUNNER, SHOOTER, JUMPER}
switch (type) {
case BLOCKS:
return 0.3;
case COINS :
return 0.5;
case POWER_UP :
return 0.1;
default :
return (.5) * (skillVector.get(SKILL.BUMP) / 100.0);
case COINS:
return (.5) * (skillVector.get(SKILL.COLLECT) / 100.0);
case POWER_UP:
double skillMod = 0;
switch (skillLevel) {
case BEGINNER:
skillMod = .8;
break;
case COMPETENT:
skillMod = .6;
break;
case PROFICIENT:
skillMod = .4;
break;
case EXPERT:
skillMod = .2;
break;
default:
skillMod = 1;
}
skillMod = (skillMod + (skillVector.get(SKILL.SHOOT) / 100.0)) / 2.0;
return (.3) * skillMod;
default:
return 0.1;
}
}