Class NativeAIPlayer

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • MAX_DISTANCE_TO_BRING_GIFTS

        public static final int MAX_DISTANCE_TO_BRING_GIFTS
        See Also:
        Constant Field Values
      • MAX_NUMBER_OF_GIFTS_BEING_DELIVERED

        public static final int MAX_NUMBER_OF_GIFTS_BEING_DELIVERED
        See Also:
        Constant Field Values
      • MAX_DISTANCE_TO_MAKE_DEMANDS

        public static final int MAX_DISTANCE_TO_MAKE_DEMANDS
        See Also:
        Constant Field Values
      • reasons

        private final java.util.Map<Unit,​java.lang.String> reasons
        Debug helper to keep track of why/what the units are doing. Do not serialize.
    • Constructor Detail

      • NativeAIPlayer

        public NativeAIPlayer​(AIMain aiMain,
                              Player player)
        Creates a new AIPlayer.
        Parameters:
        aiMain - The main AI-class.
        player - The player that should be associated with this AIPlayer.
      • NativeAIPlayer

        public NativeAIPlayer​(AIMain aiMain,
                              FreeColXMLReader xr)
                       throws javax.xml.stream.XMLStreamException
        Creates a new AIPlayer.
        Parameters:
        aiMain - The main AI-object.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
    • Method Detail

      • initializeMissions

        private void initializeMissions​(LogBuilder lb)
        Simple initialization of AI missions given that we know the starting conditions.
        Parameters:
        lb - A LogBuilder to log to.
      • determineStances

        private void determineStances​(LogBuilder lb)
        Determines the stances towards each player. That is: should we declare war?
        Parameters:
        lb - A LogBuilder to log to.
      • secureSettlements

        private void secureSettlements​(int[] randoms,
                                       LogBuilder lb)
        Takes the necessary actions to secure the settlements. This is done by making new military units or to give existing units new missions.
        Parameters:
        randoms - An array of random settlement indexes.
        lb - A LogBuilder to log to.
      • equipBraves

        public void equipBraves​(IndianSettlement is,
                                LogBuilder lb)
        Greedily equips braves with horses and muskets. Public for the test suite.
        Parameters:
        is - The IndianSettlement where the equipping occurs.
        lb - A LogBuilder to log to.
      • secureIndianSettlement

        public void secureIndianSettlement​(IndianSettlement is,
                                           LogBuilder lb)
        Takes the necessary actions to secure an indian settlement Public for the test suite.
        Parameters:
        is - The IndianSettlement to secure.
        lb - A LogBuilder to log to.
      • giveNormalMissions

        private void giveNormalMissions​(LogBuilder lb)
        Gives a mission to all units.
        Parameters:
        lb - A LogBuilder to log to.
      • bringGifts

        private void bringGifts​(int[] randoms,
                                LogBuilder lb)
        Brings gifts to nice players with nearby colonies.
        Parameters:
        randoms - An array of random percentages.
        lb - A LogBuilder to log to.
      • demandTribute

        private void demandTribute​(int[] randoms,
                                   LogBuilder lb)
        Demands tribute from nasty players with nearby colonies.
        Parameters:
        randoms - An array of random percentages.
        lb - A LogBuilder to log to.
      • getShipTradePenalties

        private java.util.List<Modifier> getShipTradePenalties​(boolean sense)
        Gets the appropriate ship trade penalties.
        Parameters:
        sense - The sense to apply the modifiers.
        Returns:
        The ship trade penalties.
      • abortInvalidMissions

        public void abortInvalidMissions()
        Aborts all the missions which are no longer valid. Public for the test suite.
      • indianDemand

        public Constants.IndianDemandAction indianDemand​(Unit unit,
                                                         Colony colony,
                                                         GoodsType type,
                                                         int amount,
                                                         Constants.IndianDemandAction accept)
        Decide whether to accept an Indian demand, or not. Or for native players, return the result of the demand.
        Overrides:
        indianDemand in class AIPlayer
        Parameters:
        unit - The Unit making demands.
        colony - The Colony where demands are being made.
        type - The GoodsType demanded.
        amount - The amount of gold demanded.
        accept - The acceptance state of the demand.
        Returns:
        The result of the demand.
      • startWorking

        public void startWorking()
        Tells this AIPlayer to make decisions. The AIPlayer is done doing work this turn when this method returns.
        Specified by:
        startWorking in class AIPlayer
      • adjustMission

        public int adjustMission​(AIUnit aiUnit,
                                 PathNode path,
                                 java.lang.Class type,
                                 int value)
        Adjusts the score of this proposed mission for this player type. Subclasses should override and refine this.
        Specified by:
        adjustMission in class MissionAIPlayer
        Parameters:
        aiUnit - The AIUnit to perform the mission.
        path - A PathNode to the target of this mission.
        type - The mission type.
        value - The proposed value.
        Returns:
        A score representing the desirability of this mission.
      • updateTrade

        private void updateTrade​(NativeTrade nt,
                                 int anger)
        Price the goods to buy.
        Parameters:
        nt - The NativeTrade to update.
        anger - A penalty to the native prices due to anger.
      • getNeededWagons

        public int getNeededWagons​(Tile tile)
        Gets the needed wagons for a tile/contiguity.
        Specified by:
        getNeededWagons in class AIPlayer
        Parameters:
        tile - The Tile to derive the contiguity from.
        Returns:
        The number of wagons needed.
      • pioneersNeeded

        public int pioneersNeeded()
        How many pioneers should we have? This is the desired total number, not the actual number which would take into account the number of existing PioneeringMissions.
        Specified by:
        pioneersNeeded in class AIPlayer
        Returns:
        The desired number of pioneers for this player.
      • scoutsNeeded

        public int scoutsNeeded()
        How many scouts should we have? This is the desired total number, not the actual number which would take into account the number of existing ScoutingMissions. Current scheme for European AIs is to use up to three scouts in the early part of the game, then one.
        Specified by:
        scoutsNeeded in class AIPlayer
        Returns:
        The desired number of scouts for this player.
      • completeWish

        public void completeWish​(Wish w)
        Notify that a wish has been completed. Called from AIColony.
        Specified by:
        completeWish in class AIPlayer
        Parameters:
        w - The Wish to complete.