/** * Moves the robber to the specified HexLocation, and retrieves the players that own municipals * next to that hex, excluding those that don't have resources to steal and the player that moved * the robber * * @pre canDoMoveRobberToHex != null * @param hex * @throws Exception * @return array of Players that are adjacent to the new Robber Hex, that have resources to steal. */ public Player[] moveRobberToHex(int UserId, HexLocation hexLocation) throws Exception { if (canDoMoveRobberToHex(UserId, hexLocation) == false) { throw new Exception("Cannot move Robber to that Hex"); } board.moveRobberToHex(hexLocation); Hex hex = board.getHex(hexLocation); Vertex[] adjacentVertices = hex.getAdjacentVertices(); ArrayList<Integer> adjacentPlayerIDs = new ArrayList<Integer>(); ArrayList<Player> adjacentPlayers = new ArrayList<Player>(); for (Vertex vertex : adjacentVertices) { // If the vertex has a municipal, that municipal is not owned by the player moving the robber // and the Player is not already in the list, and the Player has resources to be stolen if (vertex.getMunicipal() != null) { int municipalID = vertex.getMunicipal().getPlayer().getPlayerIndex(); Player player = vertex.getMunicipal().getPlayer(); if (vertex.hasMunicipal() && UserId != municipalID && !adjacentPlayerIDs.contains(municipalID) && player.getResourceCardHandSize() > 0) { adjacentPlayerIDs.add(municipalID); adjacentPlayers.add(player); } } } // Convert the found players into an array to return Player[] players = new Player[adjacentPlayers.size()]; return adjacentPlayers.toArray(players); }