Commit 838af146 authored by Aneta Steimarova's avatar Aneta Steimarova

#928 Repair protocol tests to make correct position at the end

parent 2862643c
TestGameKidnappingEasyNoneStar
TestGameKidnappingEasyOneStar
TestGameKidnappingEasyTwoStar
TestGameKidnappingEasyThreeStar
TestGameKidnappingMediumNoneStar
TestGameKidnappingMediumOneStar
TestGameKidnappingMediumTwoStar
TestGameKidnappingMediumThreeStar
TestGameKidnappingHardNoneStar
TestGameKidnappingHardOneStar
TestGameKidnappingHardTwoStar
TestGameKidnappingHardThreeStar
\ No newline at end of file
TestGameProtocolEasyNoneStar
TestGameProtocolEasyOneStar
TestGameProtocolEasyTwoStar
TestGameProtocolEasyThreeStar
TestGameProtocolMediumNoneStar
TestGameProtocolMediumOneStar
TestGameProtocolMediumTwoStar
TestGameProtocolMediumThreeStar
TestGameProtocolHardNoneStar
TestGameProtocolHardOneStar
TestGameProtocolHardTwoStar
TestGameProtocolHardThreeStar
\ No newline at end of file
......@@ -99,14 +99,18 @@ TestGameRunesHardNoneStar
TestGameRunesHardOneStar
TestGameRunesHardTwoStar
TestGameRunesHardThreeStar
TestGameProtocolEasyOneStar
TestGameProtocolEasyNoneStar
TestGameProtocolEasyOneStar
TestGameProtocolEasyTwoStar
TestGameProtocolEasyThreeStar
TestGameProtocolMediumNoneStar
TestGameProtocolMediumOneStar
TestGameProtocolMediumTwoStar
TestGameProtocolHardThreeStar
TestGameProtocolHardOneStar
TestGameProtocolMediumThreeStar
TestGameProtocolHardNoneStar
TestGameProtocolHardOneStar
TestGameProtocolHardTwoStar
TestGameProtocolHardThreeStar
TestGameSafeEasyNoneStars
TestGameSafeEasyOneStars
TestGameSafeEasyTwoStars
......
......@@ -80,7 +80,6 @@ public class TestGameProtocol extends AbstractTestGame {
private int gameScore = 0;
private int objectsCnt = 0;
private int sumObjectsCnt = 0;
private int mistakeCnt = 0;
public TestGameProtocol(Tablexia tablexia) {
......@@ -160,8 +159,6 @@ public class TestGameProtocol extends AbstractTestGame {
int playedRound = 0;
sumObjectsCnt = LevelDefinition.DifficultyDefinition.getDefinitionByDifficulty(difficulty).getSumObjectCount();
while (playedRound < ProtocolGame.MAX_ROUNDS) {
playRound();
......@@ -180,6 +177,7 @@ public class TestGameProtocol extends AbstractTestGame {
}
private void playRound() {
recountCorrectObjects();
takeScreenShot();
ProtocolGenerator generator = gameState.getProtocolGenerator();
......@@ -220,6 +218,14 @@ public class TestGameProtocol extends AbstractTestGame {
}
private void recountCorrectObjects() {
Game game = loadGameFromDao(1);
int actualGameScore = Integer.valueOf(game.getGameScore(ProtocolScoreResolver.SCORE_COUNT, "0"));
logInfo("Default correct item position/undefined item position: game score = " + gameScore + " changed to actual score = " + actualGameScore);
if(gameScore!=actualGameScore) gameScore = actualGameScore;
}
/////////////////////////////// ROOM ACTION
/**
......@@ -271,11 +277,11 @@ public class TestGameProtocol extends AbstractTestGame {
}
private void moveObjectToFurniture(GameObject gameObject, FurnitureType furnitureType) {
if (doMistake()) {
if (doCorrect()) {
correct();
} else {
furnitureType = getDifferentFurniture(furnitureType);
mistake();
} else {
correct();
}
Furniture furniture = (Furniture) findGameActor(ProtocolGame.FURNITURE + furnitureType);
......@@ -291,11 +297,11 @@ public class TestGameProtocol extends AbstractTestGame {
}
private void moveObjectToWall(GameObject gameObject, WallType wallType) {
if (doMistake()) {
if (doCorrect()) {
correct();
} else {
wallType = getDifferentWallType(wallType);
mistake();
} else {
correct();
}
float[] fixRatio = wallType.getFixRatio(difficulty);
......@@ -323,27 +329,26 @@ public class TestGameProtocol extends AbstractTestGame {
GameObjectType objectType = (GameObjectType) positionPair.getObjectType();
GameObject gameObject = findGameObjectInMenu(objectType);
boolean needMistake = doMistake();
boolean needCorrect = doCorrect();
//Set move preposition
Preposition preposition;
if (positionPair.getPreposition() == Preposition.BETWEEN) {
preposition = getOppositePreposition(getPrepositionForBetweenPosition(objectType, solution.get(processed), inRoom, needMistake));
preposition = getOppositePreposition(getPrepositionForBetweenPosition(objectType, solution.get(processed), inRoom, needCorrect));
} else {
preposition = getOppositePreposition(positionPair.getPreposition());
}
if (needMistake) {
moveGameObjectToFailPosition(gameObject, new PositionPair(preposition, processed));
} else {
if (needCorrect) {
moveGameObjectByPreposition(gameObject, new PositionPair(preposition, processed));
} else {
moveGameObjectToFailPosition(gameObject, new PositionPair(preposition, processed));
}
typeStack.push(objectType);
inRoom.add(objectType);
menuObjects.remove(objectType);
addScore(needMistake);
addScore(needCorrect);
}
}
}
......@@ -365,26 +370,26 @@ public class TestGameProtocol extends AbstractTestGame {
GameObject gameObject = findGameObjectInMenu(objectType);
boolean needMistake = doMistake();
boolean needCorrect = doCorrect();
//Set move preposition
Preposition preposition;
if (pair.getPreposition() == Preposition.BETWEEN) {
preposition = getPrepositionForBetweenPosition(processed, pairList, inRoom, needMistake);
preposition = getPrepositionForBetweenPosition(processed, pairList, inRoom, needCorrect);
} else {
preposition = pair.getPreposition();
}
if (needMistake) {
moveGameObjectToFailPosition(gameObject, new PositionPair(preposition, processed));
} else {
if (needCorrect) {
moveGameObjectByPreposition(gameObject, new PositionPair(preposition, processed));
} else {
moveGameObjectToFailPosition(gameObject, new PositionPair(preposition, processed));
}
typeStack.add(objectType);
inRoom.add(objectType);
menuObjects.remove(objectType);
addScore(needMistake);
addScore(needCorrect);
}
}
}
......@@ -541,8 +546,8 @@ public class TestGameProtocol extends AbstractTestGame {
/////////////////////////////// PROTOCOL ACTION
private void addScore(boolean needMistake) {
if (needMistake) mistake();
private void addScore(boolean needCorrect) {
if (!needCorrect) mistake();
else correct();
}
......@@ -556,14 +561,14 @@ public class TestGameProtocol extends AbstractTestGame {
objectsCnt++;
}
private boolean doMistake() {
private boolean doCorrect() {
int sumObjectsCnt = LevelDefinition.DifficultyDefinition.getDefinitionByDifficulty(difficulty).getSumObjectCount();
int[] scoreResult = ProtocolScoreResolver.ResultStars.values()[difficulty.ordinal() - 1].getScoreResult();
if (expectedResult == AbstractTablexiaGame.GameResult.TWO_STAR && mistakeCnt <= (sumObjectsCnt - scoreResult[2]))
return true;
else if (expectedResult == AbstractTablexiaGame.GameResult.ONE_STAR && mistakeCnt <= (sumObjectsCnt - scoreResult[1]))
if (expectedResult == AbstractTablexiaGame.GameResult.TWO_STAR && objectsCnt >= (sumObjectsCnt - scoreResult[1]+ gameScore))
return true;
else if (expectedResult == AbstractTablexiaGame.GameResult.NO_STAR && mistakeCnt <= (sumObjectsCnt - scoreResult[0]))
else if (expectedResult == AbstractTablexiaGame.GameResult.ONE_STAR && objectsCnt >= (sumObjectsCnt - scoreResult[0]+ gameScore))
return true;
else if (expectedResult == AbstractTablexiaGame.GameResult.THREE_STAR) return true;
return false;
}
......@@ -597,17 +602,18 @@ public class TestGameProtocol extends AbstractTestGame {
return preposition;
}
private Preposition getPrepositionForBetweenPosition(GameObjectType objectType, List<PositionPair> positionPairs, List<GameObjectType> inRoom, boolean needMistake) {
if(needMistake)
return Preposition.LEFT;
for (PositionPair pair : positionPairs) {
if (pair.getPreposition() == Preposition.BETWEEN && pair.getObjectType() != objectType) {
return inRoom.contains(pair.getObjectType()) ? Preposition.LEFT : Preposition.RIGHT;
private Preposition getPrepositionForBetweenPosition(GameObjectType objectType, List<PositionPair> positionPairs, List<GameObjectType> inRoom, boolean needCorrect) {
if(needCorrect) {
for (PositionPair pair : positionPairs) {
if (pair.getPreposition() == Preposition.BETWEEN && pair.getObjectType() != objectType) {
return inRoom.contains(pair.getObjectType()) ? Preposition.LEFT : Preposition.RIGHT;
}
}
return Preposition.RIGHT;
}
return Preposition.RIGHT;
else return Preposition.LEFT;
}
private void returnToFirstCard() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment