Class 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 route
      boolean contractExists​(java.lang.String cID)
      checks whether a contract actually exists
      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)
      static boolean distancePossibleWithType​(City a, City b, CableConfig thisType)
      checks if distance is possible with this specific cable type
      Board getBoard()
      getter for board
      java.lang.String getName()
      getter for name
      int getPlayerId()
      getter for playerID
      int getScore​(boolean applyEndgameScoring)
      getter for Score
      static boolean illegalBorderCrossing​(City a, City b, CableConfig thisType, Region regA, Region regB)
      Method to check illegal border Crossings
      static boolean illegalCableCrossings​(CableConfig thisType, City cityA, City cityB, Board board)
      Method for checking the new Cable crossing any old cables
      void 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 config
      static 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 methods
      void update​(breitband.preset.Move opponentMove)
      update class verifies move of other player
      void 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 also getPlayerId())
        name - name of the player (see also getName())
        read - XML parser (see also Config)
        con - available Contracts in board (see also Board.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 Route
        b - "ending" City of this Route
        type - the cable-type which is used
        availableCables - 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 cable
        regA - region of city a
        regB - 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 checked
        regB - 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 route
        b - "ending" City of route
        thisType - 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 type
        cityA - "starting" point of city
        cityB - "ending" point of city
        board - 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 route
        cityB - "ending" point of route
        board - 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 route
        cityB - "ending" city of route
        regionA - region of cityA
        regionB - region of cityB
        cableType - cable(-type) of route
        board - the board upon which the route gets checked
        cableNum - 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 interface breitband.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 interface breitband.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 interface breitband.preset.Player
        Parameters:
        gameConfigurationXML - XML-Parser (see also Config)
        availableContracts - available Contracts in board (see also Board.getContracts())
        num - number of players
        playerID - id of player (see also getPlayerId())
        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 interface breitband.preset.Player
      • update

        public void update​(breitband.preset.Move opponentMove)
                    throws IllegalTurnException
        update class verifies move of other player
        Specified by:
        update in interface breitband.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 interface breitband.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