diff --git a/src/ch/zhaw/catan/SiedlerBoard.java b/src/ch/zhaw/catan/SiedlerBoard.java index db37645..2939544 100644 --- a/src/ch/zhaw/catan/SiedlerBoard.java +++ b/src/ch/zhaw/catan/SiedlerBoard.java @@ -27,6 +27,8 @@ public class SiedlerBoard extends HexBoard { * Value: Field Object */ HashMap fields = new HashMap<>(); + Config.Faction longestRoadFaction = null; + int longestRoadLenth = 0; /** * Method to create the predefined game field from Config. @@ -141,7 +143,7 @@ public class SiedlerBoard extends HexBoard { * @return a HashMap where faction is the player with the longest road longer according to siedler game rules * and the Integer representing the length of the road */ - public void getLongestRoadFaction(HashMap currentLongestRoad, List factionList) { + public Config.Faction getLongestRoadFaction(List factionList) { List corners = getCorners(); HashMap players = new HashMap<>(); @@ -161,7 +163,7 @@ public class SiedlerBoard extends HexBoard { } } - if (currentLongestRoad.size() == 0) { + if (longestRoadFaction == null) { Config.Faction currentFaction = null; int currentRoad = 4; for (Config.Faction factionA : players.keySet()) { @@ -171,18 +173,18 @@ public class SiedlerBoard extends HexBoard { } } if (currentFaction != null) { - currentLongestRoad.put(currentFaction, currentRoad); + longestRoadFaction = currentFaction; + longestRoadLenth = currentRoad; } } else { for (Config.Faction faction : players.keySet()) { - for (Config.Faction faction1 : currentLongestRoad.keySet()) { - if (players.get(faction) >= 5 && players.get(faction) > currentLongestRoad.get(faction1)) { - currentLongestRoad.remove(faction1); - currentLongestRoad.put(faction, players.get(faction)); - } + if (players.get(faction) >= 5 && players.get(faction) > longestRoadLenth) { + longestRoadFaction = faction; + longestRoadLenth = players.get(faction); } } } + return longestRoadFaction; } /** diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 54f38d9..5100391 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -27,7 +27,6 @@ public class SiedlerGame { private final int winPointsForWin; private final Bank bank; private int activePlayer; - private final HashMap longestRoadFaction; /** * Constructs a SiedlerGame game state object. @@ -47,7 +46,6 @@ public class SiedlerGame { allPlayers = new ArrayList<>(); createPlayer(numberOfPlayers); activePlayer = 0; - longestRoadFaction = new HashMap<>(); this.winPointsForWin = winPoints; } @@ -503,8 +501,7 @@ public class SiedlerGame { winPoints += newWinPoints; } } - board.getLongestRoadFaction(longestRoadFaction, getPlayerFactions()); - if (longestRoadFaction.get(getCurrentPlayerFaction()) != null) { + if (getCurrentPlayerFaction() == board.getLongestRoadFaction(getPlayerFactions())) { winPoints += 2; } return winPoints; diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index c2e262a..468c367 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -51,9 +51,9 @@ public class SiedlerGameTest { board.setEdge(new Point(3, 9), new Point(4, 10), new Road(Config.Faction.BLUE,new Point(3, 9),new Point(4, 10))); board.setEdge(new Point(4, 10), new Point(5, 9), new Road(Config.Faction.BLUE,new Point(4, 10),new Point(5, 9))); board.setCorner(new Point(3,7),new Settlement(Config.Faction.BLUE,new Point(3,7))); - board.getLongestRoadFaction(currentLongestRoad,factionList); - assertEquals(6,currentLongestRoad.get(Config.Faction.BLUE)); - + assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList)); + //assertEquals(6,currentLongestRoad.get(Config.Faction.BLUE)); + //todo prüfen ob länge Stimmt. } /**