Package breitband.game.players
Class SPlayer
- java.lang.Object
-
- breitband.game.players.SPlayer
-
- All Implemented Interfaces:
breitband.preset.Player
- Direct Known Subclasses:
HumanPlayer
,RandomAIPlayer
public abstract class SPlayer extends java.lang.Object implements breitband.preset.Player
Class containing all the information and methods needed for players regardless of type- Author:
- Klara Schöbel
-
-
Constructor Summary
Constructors Constructor Description SPlayer(int id, java.lang.String name, java.io.Reader read, breitband.preset.ImmutableList<java.lang.String> con, int num)
Constructs a new SPlayer with and id, a name, an XML, available contracts and the number of players
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
cityOnRoute(City cityA, City cityB, Board board)
Checks if there is a city on the routeboolean
contractExists(java.lang.String cID)
checks whether a contract actually existsstatic boolean
distanceNotPossibleWithAvailableResources(City a, City b, CableConfig type, int availableCables)
Method to check if distance is possible with the cables currently available to player (Inventory+picked upCables)static boolean
distancePossibleWithType(City a, City b, CableConfig thisType)
checks if distance is possible with this specific cable typeBoard
getBoard()
getter for boardjava.lang.String
getName()
getter for nameint
getPlayerId()
getter for playerIDint
getScore(boolean applyEndgameScoring)
getter for Scorestatic boolean
illegalBorderCrossing(City a, City b, CableConfig thisType, Region regA, Region regB)
Method to check illegal border Crossingsstatic boolean
illegalCableCrossings(CableConfig thisType, City cityA, City cityB, Board board)
Method for checking the new Cable crossing any old cablesvoid
init(java.io.Reader gameConfigurationXML, breitband.preset.ImmutableList<java.lang.String> availableContracts, int num, int playerID)
initialize method parsing the XML file and creating board from the configstatic boolean
inSameRegion(Region regA, Region regB)
Checks if to regions are the same, intersect (i.e.abstract breitband.preset.Move
request()
abstract class for request (will be implemented in child classes)static boolean
routePossible(City cityA, City cityB, Region regionA, Region regionB, CableConfig cableType, Board board, int cableNum)
checks if the route is possible by using combining all checking methodsvoid
update(breitband.preset.Move opponentMove)
update class verifies move of other playervoid
verifyGame(breitband.preset.ImmutableList<java.lang.Integer> endScores)
method to only be used in the very end once which verifies if the endscore is synchronized
-
-
-
Constructor Detail
-
SPlayer
public SPlayer(int id, java.lang.String name, java.io.Reader read, breitband.preset.ImmutableList<java.lang.String> con, int num) throws java.lang.Exception
Constructs a new SPlayer with and id, a name, an XML, available contracts and the number of players- Parameters:
id
- id of player (see alsogetPlayerId()
)name
- name of the player (see alsogetName()
)read
- XML parser (see alsoConfig
)con
- available Contracts in board (see alsoBoard.getContracts()
)num
- number of players- Throws:
java.lang.Exception
- if config is invalid
-
-
Method Detail
-
distanceNotPossibleWithAvailableResources
public static boolean distanceNotPossibleWithAvailableResources(City a, City b, CableConfig type, int availableCables)
Method to check if distance is possible with the cables currently available to player (Inventory+picked upCables)- Parameters:
a
- "starting" City of this Routeb
- "ending" City of this Routetype
- the cable-type which is usedavailableCables
- total number of available Cables- Returns:
- if this distance is possible with the player Cables
-
illegalBorderCrossing
public static boolean illegalBorderCrossing(City a, City b, CableConfig thisType, Region regA, Region regB)
Method to check illegal border Crossings- Parameters:
a
- City a (start of route)b
- City b (end of route)thisType
- type of cableregA
- region of city aregB
- region of city b- Returns:
- returns if any illegal border Crossing happened
-
inSameRegion
public static boolean inSameRegion(Region regA, Region regB)
Checks if to regions are the same, intersect (i.e. Bremen and Lower Saxony) or are roughly close- Parameters:
regA
- one of the regions to be checkedregB
- other region to be checked- Returns:
- true if regions are equal or the bounds of the polygons intersect
-
distancePossibleWithType
public static boolean distancePossibleWithType(City a, City b, CableConfig thisType)
checks if distance is possible with this specific cable type- Parameters:
a
- "stating" City of routeb
- "ending" City of routethisType
- cable(-type) of route- Returns:
- if distance is possible
-
illegalCableCrossings
public static boolean illegalCableCrossings(CableConfig thisType, City cityA, City cityB, Board board)
Method for checking the new Cable crossing any old cables- Parameters:
thisType
- used cable typecityA
- "starting" point of citycityB
- "ending" point of cityboard
- the board upon which the illegal-cable-crossing gets checked- Returns:
- if any cable was crossed illegally
-
cityOnRoute
public static boolean cityOnRoute(City cityA, City cityB, Board board)
Checks if there is a city on the route- Parameters:
cityA
- "starting" point of routecityB
- "ending" point of routeboard
- the board upon which the method checks if a city is on route- Returns:
- returns if there is a city on the round by checking all the cities in all the regions the line crosses
-
routePossible
public static boolean routePossible(City cityA, City cityB, Region regionA, Region regionB, CableConfig cableType, Board board, int cableNum)
checks if the route is possible by using combining all checking methods- Parameters:
cityA
- "starting" city of routecityB
- "ending" city of routeregionA
- region of cityAregionB
- region of cityBcableType
- cable(-type) of routeboard
- the board upon which the route gets checkedcableNum
- total number of Cables of cableType available to player (pickedUp of this type + cables already in inventory)- Returns:
- if the route is possible to be built this way
-
getBoard
public Board getBoard()
getter for board- Returns:
- board of this player
-
getName
public java.lang.String getName()
getter for name- Specified by:
getName
in interfacebreitband.preset.Player
- Returns:
- name of the player
-
getPlayerId
public int getPlayerId()
getter for playerID- Returns:
- if of the player (which is only given from 0-4 corresponding to the index of the player in board (see
Board
))
-
getScore
public int getScore(boolean applyEndgameScoring)
getter for Score- Specified by:
getScore
in interfacebreitband.preset.Player
- Parameters:
applyEndgameScoring
- if the endgame scoring rules (contacts) should be adapted- Returns:
- score of the player (see
Board
)
-
init
public void init(java.io.Reader gameConfigurationXML, breitband.preset.ImmutableList<java.lang.String> availableContracts, int num, int playerID) throws java.lang.Exception
initialize method parsing the XML file and creating board from the config- Specified by:
init
in interfacebreitband.preset.Player
- Parameters:
gameConfigurationXML
- XML-Parser (see alsoConfig
)availableContracts
- available Contracts in board (see alsoBoard.getContracts()
)num
- number of playersplayerID
- id of player (see alsogetPlayerId()
)- Throws:
java.lang.Exception
-
request
public abstract breitband.preset.Move request()
abstract class for request (will be implemented in child classes)- Specified by:
request
in interfacebreitband.preset.Player
-
update
public void update(breitband.preset.Move opponentMove) throws IllegalTurnException
update class verifies move of other player- Specified by:
update
in interfacebreitband.preset.Player
- Parameters:
opponentMove
- move of other player (player who is currently active)- Throws:
IllegalTurnException
- if config is invalid
-
verifyGame
public void verifyGame(breitband.preset.ImmutableList<java.lang.Integer> endScores) throws InvalidGameResultException
method to only be used in the very end once which verifies if the endscore is synchronized- Specified by:
verifyGame
in interfacebreitband.preset.Player
- Parameters:
endScores
- receives the checked score from game- Throws:
InvalidGameResultException
- if end scores don't match
-
contractExists
public boolean contractExists(java.lang.String cID)
checks whether a contract actually exists- Parameters:
cID
- id of the contract to be checked- Returns:
- if the code exists
-
-