Refactoring getLongestRoadFaction
This commit is contained in:
		
							parent
							
								
									ffc97a39ef
								
							
						
					
					
						commit
						187302afd5
					
				| 
						 | 
					@ -27,6 +27,8 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
     * Value: Field Object
 | 
					     * Value: Field Object
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    HashMap<Point, Field> fields = new HashMap<>();
 | 
					    HashMap<Point, Field> fields = new HashMap<>();
 | 
				
			||||||
 | 
					    Config.Faction longestRoadFaction = null;
 | 
				
			||||||
 | 
					    int longestRoadLenth = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Method to create the predefined game field from Config.
 | 
					     * Method to create the predefined game field from Config.
 | 
				
			||||||
| 
						 | 
					@ -141,7 +143,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
     * @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to siedler game rules
 | 
					     * @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to siedler game rules
 | 
				
			||||||
     * and the Integer representing the length of the road
 | 
					     * and the Integer representing the length of the road
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void getLongestRoadFaction(HashMap<Config.Faction, Integer> currentLongestRoad, List<Config.Faction> factionList) {
 | 
					    public Config.Faction getLongestRoadFaction(List<Config.Faction> factionList) {
 | 
				
			||||||
        List<Settlement> corners = getCorners();
 | 
					        List<Settlement> corners = getCorners();
 | 
				
			||||||
        HashMap<Config.Faction, Integer> players = new HashMap<>();
 | 
					        HashMap<Config.Faction, Integer> players = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -161,7 +163,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (currentLongestRoad.size() == 0) {
 | 
					        if (longestRoadFaction == null) {
 | 
				
			||||||
            Config.Faction currentFaction = null;
 | 
					            Config.Faction currentFaction = null;
 | 
				
			||||||
            int currentRoad = 4;
 | 
					            int currentRoad = 4;
 | 
				
			||||||
            for (Config.Faction factionA : players.keySet()) {
 | 
					            for (Config.Faction factionA : players.keySet()) {
 | 
				
			||||||
| 
						 | 
					@ -171,18 +173,18 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (currentFaction != null) {
 | 
					            if (currentFaction != null) {
 | 
				
			||||||
                currentLongestRoad.put(currentFaction, currentRoad);
 | 
					                longestRoadFaction = currentFaction;
 | 
				
			||||||
 | 
					                longestRoadLenth = currentRoad;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            for (Config.Faction faction : players.keySet()) {
 | 
					            for (Config.Faction faction : players.keySet()) {
 | 
				
			||||||
                for (Config.Faction faction1 : currentLongestRoad.keySet()) {
 | 
					                if (players.get(faction) >= 5 && players.get(faction) > longestRoadLenth) {
 | 
				
			||||||
                    if (players.get(faction) >= 5 && players.get(faction) > currentLongestRoad.get(faction1)) {
 | 
					                    longestRoadFaction = faction;
 | 
				
			||||||
                        currentLongestRoad.remove(faction1);
 | 
					                    longestRoadLenth = players.get(faction);
 | 
				
			||||||
                        currentLongestRoad.put(faction, players.get(faction));
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        return longestRoadFaction;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,6 @@ public class SiedlerGame {
 | 
				
			||||||
    private final int winPointsForWin;
 | 
					    private final int winPointsForWin;
 | 
				
			||||||
    private final Bank bank;
 | 
					    private final Bank bank;
 | 
				
			||||||
    private int activePlayer;
 | 
					    private int activePlayer;
 | 
				
			||||||
    private final HashMap<Config.Faction, Integer> longestRoadFaction;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructs a SiedlerGame game state object.
 | 
					     * Constructs a SiedlerGame game state object.
 | 
				
			||||||
| 
						 | 
					@ -47,7 +46,6 @@ public class SiedlerGame {
 | 
				
			||||||
        allPlayers = new ArrayList<>();
 | 
					        allPlayers = new ArrayList<>();
 | 
				
			||||||
        createPlayer(numberOfPlayers);
 | 
					        createPlayer(numberOfPlayers);
 | 
				
			||||||
        activePlayer = 0;
 | 
					        activePlayer = 0;
 | 
				
			||||||
        longestRoadFaction = new HashMap<>();
 | 
					 | 
				
			||||||
        this.winPointsForWin = winPoints;
 | 
					        this.winPointsForWin = winPoints;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -503,8 +501,7 @@ public class SiedlerGame {
 | 
				
			||||||
                winPoints += newWinPoints;
 | 
					                winPoints += newWinPoints;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        board.getLongestRoadFaction(longestRoadFaction, getPlayerFactions());
 | 
					        if (getCurrentPlayerFaction() == board.getLongestRoadFaction(getPlayerFactions())) {
 | 
				
			||||||
        if (longestRoadFaction.get(getCurrentPlayerFaction()) != null) {
 | 
					 | 
				
			||||||
            winPoints += 2;
 | 
					            winPoints += 2;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return winPoints;
 | 
					        return winPoints;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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(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.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.setCorner(new Point(3,7),new Settlement(Config.Faction.BLUE,new Point(3,7)));
 | 
				
			||||||
            board.getLongestRoadFaction(currentLongestRoad,factionList);
 | 
					            assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
 | 
				
			||||||
            assertEquals(6,currentLongestRoad.get(Config.Faction.BLUE));
 | 
					            //assertEquals(6,currentLongestRoad.get(Config.Faction.BLUE));
 | 
				
			||||||
 | 
					            //todo prüfen ob länge Stimmt.
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue