From bc45062ad8e65edf40190e3b9edf7f711d83133a Mon Sep 17 00:00:00 2001 From: Marshall Date: Sun, 18 Mar 2012 13:42:59 -0400 Subject: [PATCH] - Implemented the reward weighting. - Fixed a balance issue with the blocks and coins on straight stretches of even length. --- src/dk/itu/mario/level/PCGLevel.java | 63 +++++++----- src/dk/itu/mario/level/PlayerProfile.java | 117 ++++++++++++++-------- 2 files changed, 111 insertions(+), 69 deletions(-) diff --git a/src/dk/itu/mario/level/PCGLevel.java b/src/dk/itu/mario/level/PCGLevel.java index e6f3844..4e5c0aa 100644 --- a/src/dk/itu/mario/level/PCGLevel.java +++ b/src/dk/itu/mario/level/PCGLevel.java @@ -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); } @@ -133,9 +140,10 @@ 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 .println("DataRecorder record is BLANK - using GamePlay metrics only."); @@ -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); } } diff --git a/src/dk/itu/mario/level/PlayerProfile.java b/src/dk/itu/mario/level/PlayerProfile.java index f8e77e8..8cb2a3a 100644 --- a/src/dk/itu/mario/level/PlayerProfile.java +++ b/src/dk/itu/mario/level/PlayerProfile.java @@ -7,90 +7,121 @@ 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 enabledComponents = new HashSet(); - + private SKILL_LEVEL skillLevel; - private Map skillVector; + private Map skillVector; private TYPE type; - - public PlayerProfile(SKILL_LEVEL skillLevel, TYPE type, Map skillVector) { + + public PlayerProfile(SKILL_LEVEL skillLevel, TYPE type, + Map 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); } } - + public boolean isEnabled(LevelComponent.TYPE type) { return enabledComponents.contains(type); } - + public SKILL_LEVEL getSkillLevel() { return skillLevel; } - + 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 : + 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; } } - + public double getProbability(LevelComponent.TYPE type) { 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 0.1; + case BLOCKS: + 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; } } - + public TYPE getType() { return type; } - + public void setDisabled(LevelComponent.TYPE type) { if (enabledComponents.contains(type)) { System.out.println("Component type disabled: " + type); enabledComponents.remove(type); } } - + public void setEnabled(LevelComponent.TYPE type) { if (!enabledComponents.contains(type)) { System.out.println("Component type enabled: " + type); enabledComponents.add(type); } } - + @Override public String toString() { return skillLevel + " " + type;