Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #112 from MninaTB/feat/zu_wenige_fragen
Browse files Browse the repository at this point in the history
Zu wenige Fragen
  • Loading branch information
miyunari authored Jun 7, 2021
2 parents 8943faf + 404565b commit 223dbe5
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/game/StateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,51 @@ private ArrayList<Question> limitQuestions(ArrayList<Question> input, int levelf
throws MissingQuestionsException {
ArrayList<Question> result = new ArrayList<Question>();

if (input.size() == 0 && (levelfk > 0 || levelMax > 0 || customLevel < 0)) {
if (input.size() == 0) {
throw new MissingQuestionsException();
} else if (levelfk <= 0 || levelMax <= 0) {
throw new MissingQuestionsException();
} else if (((levelMax - (customLevel - 1)) * levelfk) > input.size()) {
throw new MissingQuestionsException();
}

int counter = 0;
int difficultyCounter = 1;
int currentLevel = customLevel;
int lastDifficulty = -1;

for (int i = currentLevel; i < input.size() && currentLevel <= levelMax; i++) {
Question q = input.get(i);
for (int i = 0; i < input.size(); i++) {
Question tmpQuestion = input.get(i);
int newDifficulty = tmpQuestion.getDifficulty();

if (newDifficulty < currentLevel) {
continue;
}

if (lastDifficulty == -1) {
lastDifficulty = newDifficulty;
}

int newDifficulty = q.getDifficulty();
if (newDifficulty > lastDifficulty) {
if (counter < levelfk && i != currentLevel) {
if (difficultyCounter < levelfk) {
throw new MissingQuestionsException();
}
counter = 0;
currentLevel++;
difficultyCounter = 1;
lastDifficulty = newDifficulty;
}
if (counter >= levelfk) {

if (difficultyCounter > levelfk) {
continue;
}
counter++;
result.add(input.get(i));

if (result.size() >= ((levelMax - (customLevel - 1)) * levelfk)) {
break;
}

difficultyCounter++;
result.add(tmpQuestion);
}

if (result.size() < (levelMax - customLevel) * levelfk) {
if (((levelMax - (customLevel - 1)) * levelfk) > result.size()) {
throw new MissingQuestionsException();
}

Expand Down

0 comments on commit 223dbe5

Please sign in to comment.