Browse Source

Merge branch 'develop' into AIPlayer

AIPlayer
FelixKrull 3 years ago
parent
commit
c86fad4f33
  1. 25
      src/main/java/Game.java
  2. 14
      src/test/java/GameTest.java

25
src/main/java/Game.java

@ -33,7 +33,7 @@ public class Game {
clearScreen();
System.out.println(g.printGameboard(g,p,dice));
}
} while (g.checkDice(dice, p, c));
} while (g.checkDice(dice, p, c, g));
if(p.checkGameWin(p.figures)) {
winner = p;
System.out.println("Spieler " + winner.name + " gewinnt!");
@ -67,18 +67,21 @@ public class Game {
* @param dice Value of dice got from rolldice()
* @param p active Player
* @param countRolls Counter how often the Player already rolled the dice
* @param g game instance
* @return true if Player can roll the dice another time
*/
public boolean checkDice(int dice, Player p, int countRolls) {
boolean figuresOnBoard = false;
for(Figure f : p.figures) {
if (f.getPosition() > -1 && f.getPosition() < 40) {
figuresOnBoard = true;
break;
}
}
if(!figuresOnBoard) {
return countRolls < 3;
public boolean checkDice(int dice, Player p, int countRolls, Game g) {
int figuresInBase = p.checkFigureInBase(p.figures);
if(countRolls >= 3) return false;
if(figuresInBase == 4) {
return true;
} else if (figuresInBase < 4) {
for(int i = 0; i < 4 - figuresInBase; i++) {
if(checkFieldClear(p.startHome+3-i,p,g) == 0) {
return dice == 6;
}
}
return true;
} else return dice == 6;
}

14
src/test/java/GameTest.java

@ -34,7 +34,7 @@ public class GameTest {
while(it.hasNext()) {
it.next().setPosition(it2.next());
}
boolean calculatedResult = g.checkDice(dice, p1, c);
boolean calculatedResult = g.checkDice(dice, p1, c, g);
assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult);
}
@ -75,6 +75,18 @@ public class GameTest {
6,
1,
true
),
Arguments.of("Figures on Field - d: 6 - c: 1",
Arrays.asList(42, -1, -1, -1),
5,
1,
false
),
Arguments.of("Figures on Field - d: 6 - c: 1",
Arrays.asList(42, 43, -1, -1),
5,
1,
true
)
);
}

Loading…
Cancel
Save