Class Board
- java.lang.Object
-
- breitband.game.board.Board
-
public class Board extends java.lang.Object
Class for the board logic.This class contains the structure of the board and the inventory of the players. It provides methods for the editing and the retrieving of info from the board. The Main Method is updateBoard (see also
updateBoard(Move)
)- Author:
- Benjamin Richter
-
-
Constructor Summary
Constructors Constructor Description Board(Region[] regions, java.util.Map<java.lang.String,Contract> contracts, CableConfig[] cableConfig, int amountPlayer)
Constructs a new board with given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contractIsFulfilled(Contract contract)
Checks if a specific city- or region-contract is fulfilled.java.util.Map<java.lang.String,CableConfig>
getCableConfig()
Getter for the whole cableConfig.City[]
getCities()
Getter for all cities.City[]
getCitiesInRange(City cityA, float range)
Getter for all cities in range of one specific City.City[]
getCitiesInRange(City cityA, float range, int border)
Getter for all cities in range of one specific City limited by the border parameter.City
getCityByName(java.lang.String name)
Getter for a specific city.Contract
getContractByName(java.lang.String contractName)
Getter for a specific available contract.java.util.Map<java.lang.String,Contract>
getContracts()
Getter for the available contracts.java.util.Map<java.lang.String,Contract>
getContractsDoneByPlayer(int playerId)
Getter for the finished contracts of a specific player.int
getCurrentPlayer()
Getter for current player.java.util.Vector<CableRoute>
getDirectConnections()
Getter for all build direct Connections.int
getEndScoreByID(int id)
Getter for the endgame score of one specific player.breitband.preset.ImmutableList<java.lang.Integer>
getEndScores()
Getter for the endgame scores of all players.java.util.LinkedList<City>
getGroupOfCity(City city)
Getter for the group of a specific city.int
getMaxCableCost()
Getter for the max cable cost over all cable-types.int
getMaxCableDistanceOfAll()
Getter for the max distance over all cable-types.java.util.HashMap<java.lang.String,java.lang.Integer>
getPlayerCables()
Getter for all amounts of cables of the current player.java.util.HashMap<java.lang.String,java.lang.Integer>
getPlayerCables(int id)
Gets the cable inventory of a player by their IDint
getPlayerCables(java.lang.String cableType)
Getter for the amount of cables of one specific cable-type of the current player.int
getPlayerCablesById(java.lang.String cableType, int playerId)
Getter for the amount of cables of one specific cable-type of a specific player.Contract
getPlayerContract(java.lang.String contractName)
Getter for a specific Contract of the player.java.util.Map<java.lang.String,Contract>
getPlayerContracts()
Getter for the contracts of the current player.java.util.Map<java.lang.String,Contract>
getPlayerContractsByPlayer(int playerId)
Getter for the player contracts of a specific player.int[]
getPlayerScores()
Getter for all playerScores.Region
getRegionOfCity(java.lang.String cityName)
Getter for the region of a specific city.Region[]
getRegions()
Getter for regions.int
getScoreByID(int id)
Getter for the score of a player by the id of the player.int
getTurn()
Getter for the current turn.boolean
hasAvailableContracts()
Checks if any available contracts exist.boolean
hasContract(int playerId)
checks if a specific player has a contractboolean
isFulfilledCity(CityContract cityContract)
Checks if a specific city-contract is fulfilled.boolean
isFulfilledRegion(RegionContract regionContract)
Checks if a specific region-contract is fulfilled.boolean
isLastRound()
checks if it is the last round of the game.java.lang.String
toString()
debug method which prints out some information about the current status of the board.void
updateBoard(breitband.preset.Move move)
Processes a move and changes the board accordingly.
-
-
-
Constructor Detail
-
Board
public Board(Region[] regions, java.util.Map<java.lang.String,Contract> contracts, CableConfig[] cableConfig, int amountPlayer) throws InvalidBoardAccessException
Constructs a new board with given parameters.- Parameters:
regions
- the region of the country (see alsogetRegions()
)contracts
- all available contracts (see alsogetContracts()
)cableConfig
- the configuration of the cable-types (see alsogetCableConfig()
)amountPlayer
- the amount of all players- Throws:
InvalidBoardAccessException
- if the Board was accessed incorrectly
-
-
Method Detail
-
getEndScoreByID
public int getEndScoreByID(int id)
Getter for the endgame score of one specific player.The current score of the player gets taken. Then the values of all contracts of this player which they have not finished get subtracted from the score. If this player is one of the players with the most connected cities they get an extra 10 points.
- Parameters:
id
- players id- Returns:
- end-score of the specific player
-
getEndScores
public breitband.preset.ImmutableList<java.lang.Integer> getEndScores()
Getter for the endgame scores of all players.This method uses getEndScoreByID() (see also
getEndScoreByID(int)
). It asks the endScore for each player and puts it in an ImmutableList. This is used to verify the Game in the end (see alsoSPlayer.verifyGame(ImmutableList)
).- Returns:
- endScores of all player
-
getScoreByID
public int getScoreByID(int id)
Getter for the score of a player by the id of the player.- Parameters:
id
- players id- Returns:
- score of the player
-
getPlayerScores
public int[] getPlayerScores()
Getter for all playerScores.- Returns:
- scores of the players
-
getPlayerContracts
public java.util.Map<java.lang.String,Contract> getPlayerContracts()
Getter for the contracts of the current player.- Returns:
- contracts of the current player
-
getPlayerContract
public Contract getPlayerContract(java.lang.String contractName)
Getter for a specific Contract of the player.- Parameters:
contractName
- name of the contract- Returns:
- the specif contract or null if the contract doesn't exist
-
getPlayerContractsByPlayer
public java.util.Map<java.lang.String,Contract> getPlayerContractsByPlayer(int playerId) throws InvalidBoardAccessException
Getter for the player contracts of a specific player.- Parameters:
playerId
- the id of the player- Returns:
- contracts of the specific player
- Throws:
InvalidBoardAccessException
- if player ID was invalid
-
getContracts
public java.util.Map<java.lang.String,Contract> getContracts()
Getter for the available contracts.- Returns:
- all available contracts
-
getContractByName
public Contract getContractByName(java.lang.String contractName)
Getter for a specific available contract.- Parameters:
contractName
- name of the specific contract- Returns:
- the specific available contract
-
hasAvailableContracts
public boolean hasAvailableContracts()
Checks if any available contracts exist.- Returns:
- true when at least one contract is available
-
getContractsDoneByPlayer
public java.util.Map<java.lang.String,Contract> getContractsDoneByPlayer(int playerId) throws InvalidBoardAccessException
Getter for the finished contracts of a specific player.- Parameters:
playerId
- id of the specific player- Returns:
- finished contracts of the specific player
- Throws:
InvalidBoardAccessException
- if player ID was invalid
-
getPlayerCables
public java.util.HashMap<java.lang.String,java.lang.Integer> getPlayerCables()
Getter for all amounts of cables of the current player.- Returns:
- the amounts of the respective cables
-
getPlayerCables
public int getPlayerCables(java.lang.String cableType)
Getter for the amount of cables of one specific cable-type of the current player.- Parameters:
cableType
- the specific cable-type- Returns:
- the amount of cables of the specific cable-typ
-
getPlayerCables
public java.util.HashMap<java.lang.String,java.lang.Integer> getPlayerCables(int id)
Gets the cable inventory of a player by their ID- Parameters:
id
- The ID of the player whose cables will be returned- Returns:
- The cable amounts
-
getPlayerCablesById
public int getPlayerCablesById(java.lang.String cableType, int playerId) throws InvalidBoardAccessException
Getter for the amount of cables of one specific cable-type of a specific player.- Parameters:
cableType
- the specific cableTypeplayerId
- the id of the specific player- Returns:
- the amount of cables of one specific cable-typ of one specific player
- Throws:
InvalidBoardAccessException
- if the player ID is invalid
-
getCableConfig
public java.util.Map<java.lang.String,CableConfig> getCableConfig()
Getter for the whole cableConfig.- Returns:
- a Map of CableConfig
-
getMaxCableCost
public int getMaxCableCost()
Getter for the max cable cost over all cable-types.- Returns:
- max cable cost
-
getMaxCableDistanceOfAll
public int getMaxCableDistanceOfAll()
Getter for the max distance over all cable-types.- Returns:
- max cable distance
-
getRegions
public Region[] getRegions()
Getter for regions.- Returns:
- an array of regions
-
getDirectConnections
public java.util.Vector<CableRoute> getDirectConnections()
Getter for all build direct Connections.- Returns:
- a vector of the direct connections
-
getCities
public City[] getCities()
Getter for all cities.- Returns:
- the cities array
-
getCityByName
public City getCityByName(java.lang.String name)
Getter for a specific city.Returns null if no city was found.
- Parameters:
name
- name of the specific city- Returns:
- the specific city
-
getCitiesInRange
public City[] getCitiesInRange(City cityA, float range, int border)
Getter for all cities in range of one specific City limited by the border parameter.This method finds the index of the given City in the city array. Then goes in both directions along the x-axis limited by the range and the border parameter. Range limits by breaking the loop, when the difference in the x-coordinate between the cities are greater than the range. Border limits by breaking the loop, after border-amount of cities got tested. It adds the cities to the citiesOut Vector if the cities are also in range given their y-position.
- Parameters:
cityA
- the specific Cityrange
- the rangeborder
- limits the search for cities- Returns:
- all cities in range in form of a new Array
-
getCitiesInRange
public City[] getCitiesInRange(City cityA, float range)
Getter for all cities in range of one specific City.This method overloads getCitiesInRange() (see also
getCitiesInRange(City,float,int)
) It uses getCitiesInRange() with cities.length as the border parameter to truly get all cities in range.- Parameters:
cityA
- the specific Cityrange
- the range- Returns:
- all cities in range in form of a new Array
-
getRegionOfCity
public Region getRegionOfCity(java.lang.String cityName)
Getter for the region of a specific city.- Parameters:
cityName
- the specific city- Returns:
- the region of the specific city
-
getGroupOfCity
public java.util.LinkedList<City> getGroupOfCity(City city)
Getter for the group of a specific city.This method iterates through the citiesConnect Linked List. (see also
initCitesConnect()
) If the specific city is contained in the group, the group gets returned.- Parameters:
city
- the specific city- Returns:
- group of the specific city
-
getCurrentPlayer
public int getCurrentPlayer()
Getter for current player.- Returns:
- current player
-
getTurn
public int getTurn()
Getter for the current turn.- Returns:
- The turn number
-
hasContract
public boolean hasContract(int playerId)
checks if a specific player has a contract- Parameters:
playerId
- ths id of the specific player- Returns:
- true if the specific player has a contract
-
isLastRound
public boolean isLastRound()
checks if it is the last round of the game.True if: - 5 or less available contracts, - endingLength is reached by a player - Turn count bigger 100 for a player, - no player can build a route
- Returns:
- true if it is the last round of the game
-
isFulfilledCity
public boolean isFulfilledCity(CityContract cityContract)
Checks if a specific city-contract is fulfilled.checks if the groups of cityA and cityB are the same.
- Parameters:
cityContract
- the specific city-contract- Returns:
- true if fulfilled
-
isFulfilledRegion
public boolean isFulfilledRegion(RegionContract regionContract)
Checks if a specific region-contract is fulfilled.This method gets the region of the region-contract. This method then gets the group of the first city of this region. Every City of the region has to be contained in this group if the contract should be fulfilled.
- Parameters:
regionContract
- the specific region-contract- Returns:
- true if fulfilled
-
contractIsFulfilled
public boolean contractIsFulfilled(Contract contract) throws InvalidBoardAccessException
Checks if a specific city- or region-contract is fulfilled.uses isFulfilledCity() to check cityContracts (see also
isFulfilledCity(CityContract)
) uses isFulfilledRegion() to check regionContracts (see alsoisFulfilledRegion(RegionContract)
)- Parameters:
contract
- the specific contract- Returns:
- true if fulfilled
- Throws:
InvalidBoardAccessException
- if the contract is null
-
updateBoard
public void updateBoard(breitband.preset.Move move) throws InvalidBoardAccessException
Processes a move and changes the board accordingly.If a contract was accepted the method uses updateContract() to process the new contract. (see also
updateContract(String)
) It adds the picked up cables using addPlayerCables(). (see alsoaddPlayerCables(String, int)
) If a route was build it processes it. Both Cities get updated. The groups of both Cities merge using mergeCities() (see alsomergeCities(City, City)
). A Cable Route gets build. The Score and the amount of cables get adjusted. The possibly affected contracts get checked if they are fulfilled using checkContractsInGroup() (see alsocheckContractsInGroup(LinkedList)
)- Parameters:
move
- the to be processed move- Throws:
InvalidBoardAccessException
-
toString
public java.lang.String toString()
debug method which prints out some information about the current status of the board.- Overrides:
toString
in classjava.lang.Object
-
-