From 7175a51eda8ab5052cf644daed17a96f005d2179 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 15 Feb 2022 11:58:30 +0100 Subject: [PATCH] Fix getUsableFigures for Home --- src/main/java/Game.java | 15 ++++++++++----- src/test/java/GameTest.java | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 9e3704a..2b4b4b7 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -126,7 +126,7 @@ public class Game { if(p.checkFigureInBase(p.figures) > 0 && dice == 6){ if(g.checkFieldClear(p.startPos, p, g) == 2) { - return f.getPosition() == p.startPos; //TODO Wenn Figur auf Startpos von anderer Figur blockiert ist + return f.getPosition() == p.startPos; } return f.getPosition() == -1; } else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) { @@ -135,7 +135,9 @@ public class Game { } else { return false; } - } else if(f.getPosition() != -1) { + } else if(f.getPosition() >= p.startHome && (f.getPosition() + dice) < p.startHome + 4) { + return g.checkFieldClear(f.getPosition() + dice, p, g) == 0; + } else if(f.getPosition() != -1 && f.getPosition() < 40) { return g.checkFieldClear((f.getPosition() + dice) % 40, p, g) != 2; } return false; @@ -153,19 +155,22 @@ public class Game { int preCalculated; if(p.figures.get(figId).getPosition() == -1) { preCalculated = p.startPos; + } else if (p.figures.get(figId).getPosition() <= p.jumpToHome && (p.figures.get(figId).getPosition() + dice) > p.jumpToHome) { + System.out.println(p.startHome); + System.out.println(dice); + System.out.println(p.jumpToHome); + preCalculated = p.startHome + (dice - (p.jumpToHome - p.figures.get(figId).getPosition()) - 1); } else { preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; } - int kicked = 0; for(Player currentPlayer : g.players) { for(Figure currentFigure : currentPlayer.figures) { if(currentFigure.getPosition() == preCalculated) { currentFigure.setPosition(-1); - kicked = 1; } } } p.figures.get(figId).setPosition(preCalculated); - return kicked; + return preCalculated; } } \ No newline at end of file diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index 27d63dc..2b0c43d 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -24,9 +24,6 @@ public class GameTest { g2 = new Game(); p2 = g2.players.get(0); - p2.figures.get(0).setPosition(5); - p2.figures.get(1).setPosition(10); - g2.players.get(3).figures.get(1).setPosition(14); } @ParameterizedTest @@ -162,21 +159,29 @@ public class GameTest { 6, Arrays.asList(-1, -1, -1, 0), new ArrayList<>(List.of(3)) + ), + Arguments.of( //Würfel 6 - 1 Figur auf dem Spielfeld - StartFeld besetzt + "Figur auf Startfeld", + 5, + Arrays.asList(-1, 41, -1, 0), + new ArrayList<>(List.of(3)) ) ); } @ParameterizedTest @MethodSource("setFigureData") - void setFigureTest(String testname, int figId, int dice, int expectedResult) { - int calculatedResult = g.setFigure(figId, dice, p2, g2); + void setFigureTest(String testname, int figId, int dice, int currentPosition, int expectedResult) { + p2.figures.get(figId).setPosition(currentPosition); + int calculatedResult = g2.setFigure(figId, dice, p2, g2); assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); } static Stream setFigureData () { return Stream.of( - Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 0), - Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 1) + Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 5, 9), + Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 10, 14), + Arguments.of("Figur wird ins Haus gesetzt", 3, 4, 38, 42) ); } }