Class RandomAIPlayer

  • All Implemented Interfaces:
    breitband.preset.Player
    Direct Known Subclasses:
    CheatingAIPlayer

    public class RandomAIPlayer
    extends SPlayer
    This class provides an Ai-player which makes random moves.

    The Main-Method is request() which gives back a random move generated by the ai. (see also request()) This is a child-class from SPlayer (see SPlayer)

    Author:
    Benjamin Richter
    • Constructor Detail

      • RandomAIPlayer

        public RandomAIPlayer​(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 Random Ai player with default percentages.

        Uses the constructor of the SPlayer class. (see SPlayer) Initializes takeContractPer with 10% Initializes buildRoutePer with 75%

        Parameters:
        id - id of the player
        name - name of the player
        read - XML parser
        con - available Contracts in board (see also Board.getContracts())
        num - number of players
        Throws:
        java.lang.Exception - if a turn from other players is illegal
      • RandomAIPlayer

        public RandomAIPlayer​(int id,
                              java.lang.String name,
                              java.io.Reader read,
                              breitband.preset.ImmutableList<java.lang.String> con,
                              int num,
                              int takeContractPer,
                              int buildRoutePer)
                       throws java.lang.Exception
        constructs a new Random Ai player with percentages as parameters. Uses the constructor of the SPlayer class. (see SPlayer)
        Parameters:
        id - id of the player
        name - name of the player
        read - XML parser
        con - available Contracts in board (see also Board.getContracts())
        num - number of players
        takeContractPer - The percentage by which the AI wil take up a contract
        buildRoutePer - The percentage by which the AI will build a route
        Throws:
        java.lang.Exception - if a turn from other players is illegal
      • RandomAIPlayer

        public RandomAIPlayer​(int id,
                              java.lang.String name,
                              Board board,
                              int num)
        This is a constructor for debugging purposes, used without a parser.
        Parameters:
        id - id of the player
        name - name of the player
        board - the board object upon which this AI plays
        num - number of players
    • Method Detail

      • randomContract

        public Contract randomContract()
        Generates a random Contract. The contract is a random contract from the available Contracts in the Board.
        Returns:
        random contract
      • pickedUpCables

        public java.util.HashMap<java.lang.String,​java.lang.Integer> pickedUpCables​(int money)
        generates a random Map of Cables given a certain amount of money.

        (This represents the amounts of cables the ai/player wants to pick up this turn). It uses getCableConfig() (see also Board.getCableConfig()) to get a new array of all CableTypes and to get the cost of each.

        Parameters:
        money - the amount of money that can be spent
        Returns:
        random Map (String, Integer) with the picked up cables
      • randomCity

        public City randomCity()
        generates a random city of the country. The chances are equally distributed
        Returns:
        random city
      • randomCable

        public CableConfig randomCable()
        generates a random cable-typ. The cable-types are equally distributed
        Returns:
        random cable-typ