adjust countRoad in SiedlerGame

This commit is contained in:
Andrin Fassbind 2021-12-07 17:36:29 +01:00
parent 99a8feca03
commit 161dec226e
1 changed files with 19 additions and 28 deletions

View File

@ -372,7 +372,7 @@ public class SiedlerGame {
* This Method is used to check if the chosen position for a road is valid or not. * 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 roadStart the coordinates where the road begins.
* @param roadEnd the coordinates where the roads ends. * @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){ private boolean validPositionForRoad(Point roadStart, Point roadEnd){
//1. Check if Edge //1. Check if Edge
@ -389,17 +389,14 @@ public class SiedlerGame {
return true; return true;
} }
//4.Check if roadStart or roadEnd is Settlement of current player //4.Check if roadStart or roadEnd is Settlement of current player
if((board.getCorner(roadStart)!=null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction()) 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())) { || (board.getCorner(roadEnd) != null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction());
return true;
}
return false;
} }
/** /**
* Can be used for both initial Settlement and normal Phase. * Can be used for both initial Settlement and normal Phase.
* @param position * @param position the position on the board to check for valid settlement position
* @return * @return true if valid position for settlement
*/ */
private boolean validPositionForSettlement(Point position){ private boolean validPositionForSettlement(Point position){
//1. Check if Corner //1. Check if Corner
@ -415,10 +412,7 @@ public class SiedlerGame {
return false; return false;
} }
//3. Check if neighbourCorners are empty //3. Check if neighbourCorners are empty
if(!checkAdjacentCornerList(position)) { return checkAdjacentCornerList(position);
return false;
}
return true;
} }
private boolean checkIfWater(Point point) { 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 * This method checks if there are Roads build by active Player on adjacent edges
* @param point * @param point point to check on
* @return * @return true if there is a road build next to the point.
*/ */
private boolean checkAdjacentEdgesList(Point point) { private boolean checkAdjacentEdgesList(Point point) {
List<Road> results = board.getAdjacentEdges(point); List<Road> results = board.getAdjacentEdges(point);
for(int i = 0; i < results.size(); i++) { for (Road result : results) {
if(results.get(i).getFaction() == allPlayers.get(activePlayer).getFaction()) { if (result.getFaction() == allPlayers.get(activePlayer).getFaction()) {
return true; return true;
} }
} }
@ -453,10 +447,7 @@ public class SiedlerGame {
*/ */
private boolean checkAdjacentCornerList(Point point) { private boolean checkAdjacentCornerList(Point point) {
List<Settlement> results = board.getNeighboursOfCorner(point); List<Settlement> results = board.getNeighboursOfCorner(point);
if(results.size() > 0) { return results.size() <= 0;
return false;
}
return true;
} }
/** /**
@ -503,7 +494,7 @@ public class SiedlerGame {
newWinPoints = 1; newWinPoints = 1;
} }
if(structure.getFaction() == getCurrentPlayerFaction()){ if(structure.getFaction() == getCurrentPlayerFaction()){
winPoints ++; winPoints += newWinPoints;
} }
} }
longestRoadFaction = getLongestRoadFaction(longestRoadFaction); 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. * This method checks for the player with the longest road according to the catan game rules.
* @return null if there is no player with a road longer than 5 otherwise it returns the faction of the specific player * @return a HashMap<Faction,Integer> 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<Config.Faction, Integer> getLongestRoadFaction(HashMap<Config.Faction,Integer> currentLongestRoad) { private HashMap<Config.Faction, Integer> getLongestRoadFaction(HashMap<Config.Faction,Integer> currentLongestRoad) {
List<Settlement> corners = board.getCorners(); List<Settlement> corners = board.getCorners();
List<Config.Faction> factionList = getPlayerFactions(); List<Config.Faction> factionList = getPlayerFactions();
HashMap<Config.Faction,Integer> players = new HashMap<>(); HashMap<Config.Faction,Integer> players = new HashMap<>();
int highest = 0;
for(Config.Faction faction : factionList) { for(Config.Faction faction : factionList) {
int count = 0; int count = 0;
@ -563,12 +554,12 @@ public class SiedlerGame {
return roads; return roads;
} }
Iterator it2 = roads.iterator(); Iterator<Road> it2 = roads.iterator();
while(it2.hasNext()) { while(it2.hasNext()) {
Road roadsroad = (Road) it2.next(); Road roadsroad = it2.next();
Iterator it3 = roadslist.iterator(); Iterator<Road> it3 = roadslist.iterator();
while (it3.hasNext()){ while (it3.hasNext()){
Road roadslistRoad = (Road) it3.next(); Road roadslistRoad = it3.next();
if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) { if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) {
it3.remove(); it3.remove();
} }