Class RandomAIPlayer
- java.lang.Object
-
- breitband.game.players.SPlayer
-
- breitband.game.players.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 (seeSPlayer
)- Author:
- Benjamin Richter
-
-
Constructor Summary
Constructors Constructor Description RandomAIPlayer(int id, java.lang.String name, Board board, int num)
This is a constructor for debugging purposes, used without a parser.RandomAIPlayer(int id, java.lang.String name, java.io.Reader read, breitband.preset.ImmutableList<java.lang.String> con, int num)
constructs a new Random Ai player with default percentages.RandomAIPlayer(int id, java.lang.String name, java.io.Reader read, breitband.preset.ImmutableList<java.lang.String> con, int num, int takeContractPer, int buildRoutePer)
constructs a new Random Ai player with percentages as parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.HashMap<java.lang.String,java.lang.Integer>
pickedUpCables(int money)
generates a random Map of Cables given a certain amount of money.CableConfig
randomCable()
generates a random cable-typ.City
randomCity()
generates a random city of the country.Contract
randomContract()
Generates a random Contract.breitband.preset.Move
request()
Generates a random legal move.-
Methods inherited from class breitband.game.players.SPlayer
cityOnRoute, contractExists, distanceNotPossibleWithAvailableResources, distancePossibleWithType, getBoard, getName, getPlayerId, getScore, illegalBorderCrossing, illegalCableCrossings, init, inSameRegion, routePossible, update, verifyGame
-
-
-
-
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 playername
- name of the playerread
- XML parsercon
- available Contracts in board (see alsoBoard.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. (seeSPlayer
)- Parameters:
id
- id of the playername
- name of the playerread
- XML parsercon
- available Contracts in board (see alsoBoard.getContracts()
)num
- number of playerstakeContractPer
- The percentage by which the AI wil take up a contractbuildRoutePer
- 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 playername
- name of the playerboard
- the board object upon which this AI playsnum
- number of players
-
-
Method Detail
-
request
public breitband.preset.Move request() throws InvalidBoardAccessException
Generates a random legal move.Overrides the request method of SPlayer. This method uses randomContract() (see also
randomContract()
) to get a random Contract This method uses pickedUpCables() (see alsopickedUpCables(int)
) to get a map of random cables Building a route takes multiple steps: -get a randomCableType using randomCable() (see alsorandomCable()
) and checking if the player has some amount of it -get a randomCity using randomCity() ((see alsorandomCity()
)) -get Cities in building Range using getCitiesInRange() (see alsoBoard.getCitiesInRange(City, float)
) and picking one of them at random It then checks to see if this route is really possible using routePossible() (see alsoSPlayer.routePossible(City, City, Region, Region, CableConfig, Board, int)
) If the route checks out it uses this route. If it is not legal it goes through this circle again up to 10 times- Specified by:
request
in interfacebreitband.preset.Player
- Specified by:
request
in classSPlayer
- Returns:
- a random move
- Throws:
InvalidBoardAccessException
-
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
-
-