- Created a GameGoal class to encapsulate the expected computer behavior/target score for a game. The PlayerModel.java function getTargetScore() now returns a GameGoal object.
This commit is contained in:
@@ -8,7 +8,6 @@ import model.playerModel.node.SigmoidNode;
|
||||
|
||||
public class PlayerModel {
|
||||
|
||||
public static final int FIRST_SCORE = 50;
|
||||
public static final Random rand = new Random();
|
||||
|
||||
private final SigmoidNode[] hiddenLayer;
|
||||
@@ -18,8 +17,7 @@ public class PlayerModel {
|
||||
// One node for each tile-color combination, plus one for each upcoming
|
||||
// tile-color combination.
|
||||
private final InputNode[] inputNode = new InputNode[(Board.NUM_COLS
|
||||
* Board.NUM_ROWS * (Board.TileColor.values().length - 1))
|
||||
+ (4 * 2)];
|
||||
* Board.NUM_ROWS * (Board.TileColor.values().length - 1))];
|
||||
|
||||
private int nextHighInGames = 0;
|
||||
|
||||
@@ -28,6 +26,10 @@ public class PlayerModel {
|
||||
* Board.NUM_ROWS];
|
||||
|
||||
public PlayerModel() {
|
||||
for (int i = 0; i < highScore.length; i++) {
|
||||
highScore[i] = -1;
|
||||
}
|
||||
|
||||
hiddenLayer = new SigmoidNode[inputNode.length
|
||||
+ ((inputNode.length * 2) / 3)];
|
||||
|
||||
@@ -70,18 +72,19 @@ public class PlayerModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTargetScore() {
|
||||
public GameGoal getTargetScore() {
|
||||
GameGoal goal;
|
||||
int targetScore;
|
||||
int highScore = getHighScore();
|
||||
|
||||
if (highScoresAchieved == 0) {
|
||||
targetScore = FIRST_SCORE;
|
||||
goal = new GameGoal(0, true);
|
||||
nextHighInGames = 1;
|
||||
}
|
||||
|
||||
else if (nextHighInGames == 0) {
|
||||
// Set next game for high score.
|
||||
nextHighInGames = (int) Math.pow(highScoresAchieved, 2);
|
||||
nextHighInGames = (int) (Math.pow(highScoresAchieved + 1, 2) / 2);
|
||||
|
||||
// Return high score times increase percentage.
|
||||
targetScore = highScore / (2 * (highScoresAchieved + 1));
|
||||
@@ -89,6 +92,8 @@ public class PlayerModel {
|
||||
if (targetScore <= highScore) {
|
||||
targetScore = highScore + 1;
|
||||
}
|
||||
|
||||
goal = new GameGoal(targetScore, true);
|
||||
}
|
||||
|
||||
else {
|
||||
@@ -98,21 +103,29 @@ public class PlayerModel {
|
||||
if (targetScore >= highScore) {
|
||||
targetScore = highScore - 1;
|
||||
}
|
||||
|
||||
goal = new GameGoal(targetScore, false);
|
||||
}
|
||||
|
||||
return targetScore;
|
||||
return goal;
|
||||
}
|
||||
|
||||
public void logGame(int score) {
|
||||
loop: for (int i = 0; i < highScore.length; i++) {
|
||||
if (score > highScore[i]) {
|
||||
for (int j = i; j < highScore.length - 1; j++) {
|
||||
highScore[j + 1] = highScore[j];
|
||||
if (highScore[0] == -1) {
|
||||
highScore[0] = score;
|
||||
}
|
||||
|
||||
else {
|
||||
loop: for (int i = 0; i < highScore.length; i++) {
|
||||
if (score > highScore[i]) {
|
||||
for (int j = i; j < highScore.length - 1; j++) {
|
||||
highScore[j + 1] = highScore[j];
|
||||
}
|
||||
|
||||
highScore[i] = score;
|
||||
|
||||
break loop;
|
||||
}
|
||||
|
||||
highScore[i] = score;
|
||||
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user