From 161dec226e8ee82419783190b9932cf42403cdc1 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Tue, 7 Dec 2021 17:36:29 +0100 Subject: [PATCH] adjust countRoad in SiedlerGame --- src/ch/zhaw/catan/SiedlerGame.java | 47 ++++++++++++------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index c2b612b..6999147 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -372,7 +372,7 @@ public class SiedlerGame { * This Method is used to check if the chosen position for a road is valid or not. * @param roadStart the coordinates where the road begins. * @param roadEnd the coordinates where the roads ends. - * @return + * @return true if road position is valid otherwise false */ private boolean validPositionForRoad(Point roadStart, Point roadEnd){ //1. Check if Edge @@ -389,17 +389,14 @@ public class SiedlerGame { return true; } //4.Check if roadStart or roadEnd is Settlement of current player - if((board.getCorner(roadStart)!=null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction()) - ||(board.getCorner(roadEnd)!=null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction())) { - return true; - } - return false; + return (board.getCorner(roadStart) != null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction()) + || (board.getCorner(roadEnd) != null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction()); } /** * Can be used for both initial Settlement and normal Phase. - * @param position - * @return + * @param position the position on the board to check for valid settlement position + * @return true if valid position for settlement */ private boolean validPositionForSettlement(Point position){ //1. Check if Corner @@ -415,10 +412,7 @@ public class SiedlerGame { return false; } //3. Check if neighbourCorners are empty - if(!checkAdjacentCornerList(position)) { - return false; - } - return true; + return checkAdjacentCornerList(position); } private boolean checkIfWater(Point point) { @@ -433,13 +427,13 @@ public class SiedlerGame { /** * This method checks if there are Roads build by active Player on adjacent edges - * @param point - * @return + * @param point point to check on + * @return true if there is a road build next to the point. */ private boolean checkAdjacentEdgesList(Point point) { List results = board.getAdjacentEdges(point); - for(int i = 0; i < results.size(); i++) { - if(results.get(i).getFaction() == allPlayers.get(activePlayer).getFaction()) { + for (Road result : results) { + if (result.getFaction() == allPlayers.get(activePlayer).getFaction()) { return true; } } @@ -453,10 +447,7 @@ public class SiedlerGame { */ private boolean checkAdjacentCornerList(Point point) { List results = board.getNeighboursOfCorner(point); - if(results.size() > 0) { - return false; - } - return true; + return results.size() <= 0; } /** @@ -503,7 +494,7 @@ public class SiedlerGame { newWinPoints = 1; } if(structure.getFaction() == getCurrentPlayerFaction()){ - winPoints ++; + winPoints += newWinPoints; } } longestRoadFaction = getLongestRoadFaction(longestRoadFaction); @@ -515,14 +506,14 @@ public class SiedlerGame { /** - * This method returns the faction of the player with the longest road longer than 5. - * @return null if there is no player with a road longer than 5 otherwise it returns the faction of the specific player + * This method checks for the player with the longest road according to the catan game rules. + * @return a HashMap where faction is the player with the longest road longer according to catan game rules + * and the Integer representing the length of the road */ private HashMap getLongestRoadFaction(HashMap currentLongestRoad) { List corners = board.getCorners(); List factionList = getPlayerFactions(); HashMap players = new HashMap<>(); - int highest = 0; for(Config.Faction faction : factionList) { int count = 0; @@ -563,12 +554,12 @@ public class SiedlerGame { return roads; } - Iterator it2 = roads.iterator(); + Iterator it2 = roads.iterator(); while(it2.hasNext()) { - Road roadsroad = (Road) it2.next(); - Iterator it3 = roadslist.iterator(); + Road roadsroad = it2.next(); + Iterator it3 = roadslist.iterator(); while (it3.hasNext()){ - Road roadslistRoad = (Road) it3.next(); + Road roadslistRoad = it3.next(); if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) { it3.remove(); }