Package net.sf.freecol.server.ai
Class ColonyPlan
- java.lang.Object
-
- net.sf.freecol.server.ai.ColonyPlan
-
public class ColonyPlan extends java.lang.Object
Objects of this class describes the plan the AI has for aColony
. AColonyPlan
contains a list ofWorkLocationPlan
s which suggests the food and non-food production of eachWorkLocation
, and a list ofBuildableType
s to build. It takes account of the available tiles and building production, but does not make decisions to claim tiles or change the current buildable. It does takes account of goods present in the colony, and overall colony size but not the exact composition of the units involved. However there is extensive structure for making a trial assignment of workers inassignWorkers(java.util.List<net.sf.freecol.common.model.Unit>, boolean, net.sf.freecol.common.util.LogBuilder)
.AIColony
is responsible for making the real decisions.- See Also:
Colony
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ColonyPlan.BuildPlan
The things to build, and their priority.private static class
ColonyPlan.ProfileType
The profile of the colony (a sort of general flavour).
-
Field Summary
Fields Modifier and Type Field Description private AIMain
aiMain
Private copy of the AIMain.private static double
BREEDING_WEIGHT
private static double
BUILDING_WEIGHT
private java.util.Set<GoodsType>
buildingGoodsTypes
private static java.util.Comparator<ColonyPlan.BuildPlan>
buildPlanComparator
Comparator to sort buildable by descending value.private java.util.List<ColonyPlan.BuildPlan>
buildPlans
private Colony
colony
The colony this AIColony manages.private static double
DEFENCE_WEIGHT
private static double
EXPORT_WEIGHT
private static double
FISH_WEIGHT
private static double
FORTIFY_WEIGHT
private static double
IMMIGRATION_WEIGHT
private java.util.Set<GoodsType>
immigrationGoodsTypes
private static double
LIBERTY_WEIGHT
private java.util.Set<GoodsType>
libertyGoodsTypes
Sets of goods types to be produced in this colony.private static java.util.logging.Logger
logger
private static int
LOW_PRODUCTION_THRESHOLD
Require production plans to always produce an amount exceeding this.private static double
MILITARY_WEIGHT
private java.util.Set<GoodsType>
militaryGoodsTypes
private java.util.Set<GoodsType>
otherRawGoodsTypes
private java.util.List<GoodsType>
produce
The goods types to produce.private static int
PRODUCTION_TURNOVER_TURNS
Number of turns to require production of without exhausting the input goods.private static double
PRODUCTION_WEIGHT
private ColonyPlan.ProfileType
profileType
private java.util.List<GoodsType>
rawBuildingGoodsTypes
private java.util.Set<GoodsType>
rawLuxuryGoodsTypes
private static double
REPAIR_WEIGHT
private static double
STORAGE_WEIGHT
private static double
TEACH_WEIGHT
private static double
TRANSPORT_WEIGHT
private java.util.List<WorkLocationPlan>
workPlans
Plans for work locations available to this colony.
-
Constructor Summary
Constructors Constructor Description ColonyPlan(AIMain aiMain, Colony colony)
Creates a newColonyPlan
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Colony
assignWorkers(java.util.List<Unit> workers, boolean preferScout, LogBuilder lb)
Tries to apply a colony plan given a list of workers.private java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>>
createProductionMap()
Creates a map of potential production of all goods types from all available work locations using the default unit type.private ColonyPlan.BuildPlan
findBuildPlan(BuildableType type)
Finds a build plan for this type.private WorkLocationPlan
findPlan(GoodsType goodsType, java.util.List<WorkLocationPlan> plans)
Finds a plan on a list that produces a given goods type.private static boolean
fullEquipUnit(Specification spec, Unit unit, Role role, Colony colony)
Equips a unit for a role, trying all possibilities if a military role was called for.private AIMain
getAIMain()
Gets the main AI-object.BuildableType
getBestBuildableType()
Gets the best buildable type from this plan that can currently be built by the colony.protected static Unit
getBestWorker(WorkLocation wl, GoodsType goodsType, java.util.List<Unit> workers)
Gets the best worker to execute a work location plan.java.lang.String
getBuildableReport()
Get a report on the build plans.java.util.List<BuildableType>
getBuildableTypes()
Gets a copy of the current list of buildable types associated with thisColonyPlan
.java.util.List<WorkLocationPlan>
getFoodPlans()
Gets the food-producing and non-autoproducing work location plans associated with thisColonyPlan
.java.util.List<GoodsType>
getPreferredProduction()
Gets the preferred goods to produce.java.util.List<WorkLocationPlan>
getWorkPlans()
Gets the non-food-producing/non-autoproducing work location plans associated with thisColonyPlan
.private java.lang.String
locationDescription(Location loc)
Gets a concise textual description of a location associated with the colony.private boolean
prioritize(BuildableType type, double weight, double support)
Adds or improves the priority of a buildable in a list.private boolean
prioritizeProduction(BuildableType type, GoodsType goodsType)
Given a buildable that improves production of a goods type, prioritize it.void
refine(BuildableType build, LogBuilder lb)
Refines this plan given the colony choice of what to build.private Specification
spec()
Gets the specification.java.lang.String
toString()
void
update()
Recreates the buildables and work location plans for this colony.private void
updateBuildableTypes()
Updates the build plans for this colony.private void
updateGoodsTypeLists(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Updates the goods type lists.private void
updatePlans(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Makes a plan for each type of possible production, that is those work locations that can use a unit or can auto-produce.private void
updateProductionList(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Add the other goods types to the production list.private void
updateRawMaterials(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Chooses the two best raw materials, updating the production map and lists.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
buildPlanComparator
private static final java.util.Comparator<ColonyPlan.BuildPlan> buildPlanComparator
Comparator to sort buildable by descending value.
-
LOW_PRODUCTION_THRESHOLD
private static final int LOW_PRODUCTION_THRESHOLD
Require production plans to always produce an amount exceeding this.- See Also:
- Constant Field Values
-
PRODUCTION_TURNOVER_TURNS
private static final int PRODUCTION_TURNOVER_TURNS
Number of turns to require production of without exhausting the input goods.- See Also:
- Constant Field Values
-
profileType
private ColonyPlan.ProfileType profileType
-
aiMain
private final AIMain aiMain
Private copy of the AIMain.
-
colony
private final Colony colony
The colony this AIColony manages.
-
buildPlans
private final java.util.List<ColonyPlan.BuildPlan> buildPlans
-
workPlans
private final java.util.List<WorkLocationPlan> workPlans
Plans for work locations available to this colony.
-
produce
private final java.util.List<GoodsType> produce
The goods types to produce.
-
libertyGoodsTypes
private final java.util.Set<GoodsType> libertyGoodsTypes
Sets of goods types to be produced in this colony. Temporary variables that do not need to be serialized. Note: food and luxury groups disabled as not currently used, but will probably be needed in due course. Raw building goods types need to be sorted so they are a list.
-
immigrationGoodsTypes
private final java.util.Set<GoodsType> immigrationGoodsTypes
-
militaryGoodsTypes
private final java.util.Set<GoodsType> militaryGoodsTypes
-
rawBuildingGoodsTypes
private final java.util.List<GoodsType> rawBuildingGoodsTypes
-
buildingGoodsTypes
private final java.util.Set<GoodsType> buildingGoodsTypes
-
rawLuxuryGoodsTypes
private final java.util.Set<GoodsType> rawLuxuryGoodsTypes
-
otherRawGoodsTypes
private final java.util.Set<GoodsType> otherRawGoodsTypes
-
BREEDING_WEIGHT
private static final double BREEDING_WEIGHT
- See Also:
- Constant Field Values
-
BUILDING_WEIGHT
private static final double BUILDING_WEIGHT
- See Also:
- Constant Field Values
-
DEFENCE_WEIGHT
private static final double DEFENCE_WEIGHT
- See Also:
- Constant Field Values
-
EXPORT_WEIGHT
private static final double EXPORT_WEIGHT
- See Also:
- Constant Field Values
-
FISH_WEIGHT
private static final double FISH_WEIGHT
- See Also:
- Constant Field Values
-
FORTIFY_WEIGHT
private static final double FORTIFY_WEIGHT
- See Also:
- Constant Field Values
-
IMMIGRATION_WEIGHT
private static final double IMMIGRATION_WEIGHT
- See Also:
- Constant Field Values
-
LIBERTY_WEIGHT
private static final double LIBERTY_WEIGHT
- See Also:
- Constant Field Values
-
MILITARY_WEIGHT
private static final double MILITARY_WEIGHT
- See Also:
- Constant Field Values
-
PRODUCTION_WEIGHT
private static final double PRODUCTION_WEIGHT
- See Also:
- Constant Field Values
-
REPAIR_WEIGHT
private static final double REPAIR_WEIGHT
- See Also:
- Constant Field Values
-
STORAGE_WEIGHT
private static final double STORAGE_WEIGHT
- See Also:
- Constant Field Values
-
TEACH_WEIGHT
private static final double TEACH_WEIGHT
- See Also:
- Constant Field Values
-
TRANSPORT_WEIGHT
private static final double TRANSPORT_WEIGHT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getAIMain
private AIMain getAIMain()
Gets the main AI-object.- Returns:
- The main AI-object.
-
spec
private Specification spec()
Gets the specification.- Returns:
- The specification.
-
getPreferredProduction
public java.util.List<GoodsType> getPreferredProduction()
Gets the preferred goods to produce.- Returns:
- A copy of the preferred goods production list in this plan.
-
getBuildableTypes
public java.util.List<BuildableType> getBuildableTypes()
Gets a copy of the current list of buildable types associated with thisColonyPlan
.- Returns:
- A copy of the of
BuildableType
s list.
-
getBestBuildableType
public BuildableType getBestBuildableType()
Gets the best buildable type from this plan that can currently be built by the colony.- Returns:
- The best current
BuildableType
.
-
getBuildableReport
public java.lang.String getBuildableReport()
Get a report on the build plans.- Returns:
- A build plan report.
-
getFoodPlans
public java.util.List<WorkLocationPlan> getFoodPlans()
Gets the food-producing and non-autoproducing work location plans associated with thisColonyPlan
.- Returns:
- A list of food producing plans.
-
getWorkPlans
public java.util.List<WorkLocationPlan> getWorkPlans()
Gets the non-food-producing/non-autoproducing work location plans associated with thisColonyPlan
.- Returns:
- A list of non-food producing plans.
-
refine
public void refine(BuildableType build, LogBuilder lb)
Refines this plan given the colony choice of what to build.- Parameters:
build
- TheBuildableType
to be built (may be null).lb
- ALogBuilder
to log to.
-
update
public void update()
Recreates the buildables and work location plans for this colony.
-
createProductionMap
private java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> createProductionMap()
Creates a map of potential production of all goods types from all available work locations using the default unit type. Includes non-workable locations (e.g. chapel, colony-center-tile) as their production can influence the choice of goods to produce.- Returns:
- The map of potential production.
-
updateGoodsTypeLists
private void updateGoodsTypeLists(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Updates the goods type lists. The categories are:- food
- liberty
- immigration
- military
- raw building
- building
- raw luxury
- luxury
- raw other
- Parameters:
production
- The production map.
-
updateRawMaterials
private void updateRawMaterials(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Chooses the two best raw materials, updating the production map and lists. FIXME: scale with colony size.- Parameters:
production
- The production map.
-
findBuildPlan
private ColonyPlan.BuildPlan findBuildPlan(BuildableType type)
Finds a build plan for this type.- Parameters:
type
- TheBuildableType
to search for.- Returns:
- A
BuildPlan
with this type, or null if not found.
-
prioritize
private boolean prioritize(BuildableType type, double weight, double support)
Adds or improves the priority of a buildable in a list.- Parameters:
type
- TheBuildableType
to use.weight
- The relative weight of this class of buildable with respect to other buildable classes.support
- The support for this buildable within its class.- Returns:
- True if this type was prioritized.
-
prioritizeProduction
private boolean prioritizeProduction(BuildableType type, GoodsType goodsType)
Given a buildable that improves production of a goods type, prioritize it.- Parameters:
type
- TheBuildableType
to consider.goodsType
- TheGoodsType
improved by the buildable.- Returns:
- True if this type was prioritized.
-
updateBuildableTypes
private void updateBuildableTypes()
Updates the build plans for this colony.
-
updatePlans
private void updatePlans(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Makes a plan for each type of possible production, that is those work locations that can use a unit or can auto-produce. Note that this will almost certainly include clashes over work locations. That gets sorted out elsewhere as ColonyPlans do not examine the units present. With the complete list of work plans, finish creating the list of goods to produce. Then filter out the auto-production plans as they are not going to be helpful for unit allocation. Finally sort by desirability.- Parameters:
production
- A map of the goods type and production.
-
updateProductionList
private void updateProductionList(java.util.Map<GoodsType,java.util.Map<WorkLocation,java.lang.Integer>> production)
Add the other goods types to the production list. When this is called the new world goods production is already present on the produce list. Ignores food which is treated separately.- Parameters:
production
- A map of the production.
-
findPlan
private WorkLocationPlan findPlan(GoodsType goodsType, java.util.List<WorkLocationPlan> plans)
Finds a plan on a list that produces a given goods type.- Parameters:
goodsType
- TheGoodsType
to produce.plans
- The list ofWorkLocationPlan
s to check.- Returns:
- The first plan found that produces the goods type, or null if none found.
-
getBestWorker
protected static Unit getBestWorker(WorkLocation wl, GoodsType goodsType, java.util.List<Unit> workers)
Gets the best worker to execute a work location plan. - The most productive one wins (which will automatically pick a relevant expert). - If they are all relevant experts, pick any. - Pick the unit that can upgrade to the required expert with the most relevant experience or least irrelevant expertise. - Pick a unit that can not upgrade at all. - Pick an otherwise upgradeable unit with the most relevant experience or least irrelevant experience. - Pick the least skillful unit. Public for the benefit of the test suite.- Parameters:
wl
- TheWorkLocation
to work at.goodsType
- TheGoodsType
to make.workers
- A list of potentialUnit
s to try.- Returns:
- The best worker for the job.
-
fullEquipUnit
private static boolean fullEquipUnit(Specification spec, Unit unit, Role role, Colony colony)
Equips a unit for a role, trying all possibilities if a military role was called for.- Parameters:
spec
- TheSpecification
defining the roles.unit
- TheUnit
to equip if possible.role
- TheRole
for the unit to take.colony
- TheColony
storing the equipment.- Returns:
- True if the unit was equipped.
-
assignWorkers
public Colony assignWorkers(java.util.List<Unit> workers, boolean preferScout, LogBuilder lb)
Tries to apply a colony plan given a list of workers.- Parameters:
workers
- A list ofUnit
s to assign.preferScout
- Prefer to make scouts rather than soldiers.lb
- ALogBuilder
to log to.- Returns:
- A scratch colony with the workers in place.
-
locationDescription
private java.lang.String locationDescription(Location loc)
Gets a concise textual description of a location associated with the colony. No i18n here, this is for debugging purposes.- Parameters:
loc
- TheLocation
to describe.- Returns:
- The text description.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-