• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java GoalDecider类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中net.sf.freecol.common.model.pathfinding.GoalDecider的典型用法代码示例。如果您正苦于以下问题:Java GoalDecider类的具体用法?Java GoalDecider怎么用?Java GoalDecider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

GoalDecider类属于net.sf.freecol.common.model.pathfinding包,在下文中一共展示了GoalDecider类的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a {@code GoalDecider} for this mission.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @param deferOK Enable colony fallback (not implemented).
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    return new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;

            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:30,
代码来源:PrivateerMission.java

示例2: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Makes a goal decider that checks pioneering sites.
 *
 * @param aiUnit The {@code AIUnit} to search with.
 * @param deferOK Keep track of the nearest colonies to use as a
 *     fallback destination.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          final boolean deferOK) {
    final GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;

            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(false, gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:34,
代码来源:PioneeringMission.java

示例3: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a {@code GoalDecider} for finding the best colony
 * {@code Tile}, optionally falling back to the nearest colony.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit) {
    return new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;
            
            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:29,
代码来源:DefendSettlementMission.java

示例4: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a {@code GoalDecider} for finding the best colony
 * {@code Tile}, optionally falling back to the nearest colony.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @param deferOK Not used in this mission.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    return new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;
        
            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:31,
代码来源:UnitSeekAndDestroyMission.java

示例5: searchCircle

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Searches for a tile within a radius of a starting tile.
 *
 * Does not use a unit, and thus does not consider movement validity.
 *
 * @param start The starting {@code Tile}.
 * @param goalDecider A {@code GoalDecider} that chooses the goal,
 *     which must be capable of tolerating a null unit.
 * @param radius The maximum radius of tiles to search from the start.
 * @return The goal tile as determined by the, or null if none found.
 */
public Tile searchCircle(final Tile start, final GoalDecider goalDecider,
    final int radius) {
    if (start == null || goalDecider == null || radius <= 0) return null;

    for (Tile t : getCircleTiles(start, true, radius)) {
        PathNode path = new PathNode(t, 0, start.getDistanceTo(t), false,
            null, null);
        if (goalDecider.check(null, path)
            && !goalDecider.hasSubGoals())
            break;
    }
    
    PathNode best = goalDecider.getGoal();
    return (best == null) ? null : best.getTile();
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:27,
代码来源:Map.java

示例6: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a <code>GoalDecider</code> for this mission.
 *
 * @param aiUnit The <code>AIUnit</code> that is searching.
 * @param deferOK Enable colony fallback (not implemented).
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    return new GoalDecider() {
        private PathNode bestPath = null;
        private int bestValue = 0;

        public PathNode getGoal() { return bestPath; }
        public boolean hasSubGoals() { return true; }
        public boolean check(Unit u, PathNode path) {
            int value = scorePath(aiUnit, path);
            if (bestValue < value) {
                bestValue = value;
                bestPath = path;
                return true;
            }
            return false;
        }
    };
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:27,
代码来源:PrivateerMission.java

示例7: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Makes a goal decider that checks pioneering sites.
 *
 * @param aiUnit The <code>AIUnit</code> to search with.
 * @param deferOK Keep track of the nearest colonies to use as a
 *     fallback destination.
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          final boolean deferOK) {
    final Player owner = aiUnit.getUnit().getOwner();
    final GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = 0;

            public PathNode getGoal() { return bestPath; }
            public boolean hasSubGoals() { return true; }
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:32,
代码来源:PioneeringMission.java

示例8: findTargetPath

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a suitable pioneering target for the supplied unit.
 *
 * @param aiUnit The <code>AIUnit</code> to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Tile startTile = unit.getPathStartTile();
    if (startTile == null) return null;

    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();

    // Try for something sensible nearby.
    return unit.search(startTile, gd, standardCd, range, carrier);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:24,
代码来源:PioneeringMission.java

示例9: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Makes a goal decider that checks for potential missions.
 *
 * @param aiUnit The <code>AIUnit</code> to find a mission with.
 * @param deferOK Keep track of the nearest of our colonies, to use
 *     as a fallback destination.
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          final boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
        private PathNode bestPath = null;
        private int bestValue = 0;

        public PathNode getGoal() { return bestPath; }
        public boolean hasSubGoals() { return true; }
        public boolean check(Unit u, PathNode path) {
            int value = scorePath(aiUnit, path);
            if (bestValue < value) {
                bestValue = value;
                bestPath = path;
                return true;
            }
            return false;
        }
    };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:31,
代码来源:MissionaryMission.java

示例10: findTargetPath

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Find a suitable mission location for this unit.
 *
 * @param aiUnit The <code>AIUnit</code> to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
private static PathNode findTargetPath(AIUnit aiUnit, int range,
                                       boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Tile startTile = unit.getPathStartTile();
    if (startTile == null) return null;

    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();

    // Is there a valid target available from the starting tile?
    return unit.search(startTile, gd, standardCd, range, carrier);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:24,
代码来源:MissionaryMission.java

示例11: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a <code>GoalDecider</code> for finding the best colony
 * <code>Tile</code>, optionally falling back to the nearest colony.
 *
 * @param aiUnit The <code>AIUnit</code> that is searching.
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit) {
    return new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = 0;

            public PathNode getGoal() { return bestPath; }
            public boolean hasSubGoals() { return true; }
            public boolean check(Unit u, PathNode path) {
                int value = scorePath(aiUnit, path);
                if (bestValue < value) {
                    bestValue = value;
                    bestPath = path;
                    return true;
                }
                return false;
            }
        };
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:26,
代码来源:DefendSettlementMission.java

示例12: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a <code>GoalDecider</code> for finding the best colony
 * <code>Tile</code>, optionally falling back to the nearest colony.
 *
 * @param aiUnit The <code>AIUnit</code> that is searching.
 * @param deferOK Enable colony fallback.
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = 0;

            public PathNode getGoal() { return bestPath; }
            public boolean hasSubGoals() { return true; }
            public boolean check(Unit u, PathNode path) {
                Location loc = extractTarget(aiUnit, path);
                if (loc instanceof Tile) {
                    int value = scorePath(aiUnit, path);
                    if (bestValue < value) {
                        bestValue = value;
                        bestPath = path;
                        return true;
                    }
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:34,
代码来源:BuildColonyMission.java

示例13: findTargetPath

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a site for a new colony.  Favour closer sites.
 *
 * @param aiUnit The <code>AIUnit</code> to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Tile startTile = unit.getPathStartTile();
    if (startTile == null) return null;

    PathNode path;
    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();

    // Try for something sensible nearby.
    return unit.search(startTile, gd, standardCd, range, carrier);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:25,
代码来源:BuildColonyMission.java

示例14: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a <code>GoalDecider</code> for finding the best colony
 * <code>Tile</code>, optionally falling back to the nearest colony.
 *
 * @param aiUnit The <code>AIUnit</code> that is searching.
 * @param deferOK Not used in this mission.
 * @return A suitable <code>GoalDecider</code>.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    return new GoalDecider() {
        private PathNode bestPath = null;
        private int bestValue = 0;
        
        public PathNode getGoal() { return bestPath; }
        public boolean hasSubGoals() { return true; }
        public boolean check(Unit u, PathNode path) {
            int value = scorePath(aiUnit, path);
            if (bestValue < value) {
                bestValue = value;
                bestPath = path;
                return true;
            }
            return false;
        }
    };
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:28,
代码来源:UnitSeekAndDestroyMission.java

示例15: findTargetPath

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a suitable scouting target for the supplied unit.
 *
 * @param aiUnit The <code>AIUnit</code> to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Tile startTile = unit.getPathStartTile();
    if (startTile == null) return null;

    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd = CostDeciders.avoidIllegal();

    // Can the scout legally reach a valid target from where it
    // currently is?
    return unit.search(startTile, gd, standardCd, range, carrier);
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:24,
代码来源:ScoutingMission.java

示例16: searchCircle

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Searches for a tile within a radius of a starting tile.
 *
 * Does not use a unit, and thus does not consider movement validity.
 *
 * @param start The starting <code>Tile</code>.
 * @param goalDecider A <code>GoalDecider</code> that chooses the goal,
 *     which must be capable of tolerating a null unit.
 * @param radius The maximum radius of tiles to search from the start.
 * @return The goal tile as determined by the, or null if none found.
 */
public Tile searchCircle(final Tile start, final GoalDecider goalDecider,
                         final int radius) {
    if (start == null || goalDecider == null || radius <= 0) return null;

    for (Tile t : getCircleTiles(start, true, radius)) {
        PathNode path = new PathNode(t, 0, start.getDistanceTo(t), false,
                                     null, null);
        if (goalDecider.check(null, path)
            && !goalDecider.hasSubGoals())
            break;
    }
    
    PathNode best = goalDecider.getGoal();
    return (best == null) ? null : best.getTile();
}
 

开发者ID:vishal-mittal,
项目名称:SOEN6471-FreeCol,
代码行数:27,
代码来源:Map.java

示例17: findTargetPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a suitable pioneering target for the supplied unit.
 *
 * @param aiUnit The {@code AIUnit} to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Location start = unit.getPathStartLocation();
    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();

    // Try for something sensible nearby.
    return unit.search(start, gd, standardCd, range, carrier);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:22,
代码来源:PioneeringMission.java

示例18: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Makes a goal decider that checks for potential missions.
 *
 * @param aiUnit The {@code AIUnit} to find a mission with.
 * @param deferOK Enable deferring to a fallback colony.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          final boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;

            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                if (path.getLastNode().getLocation().getSettlement()
                    instanceof IndianSettlement) {
                    int value = scorePath(aiUnit, path);
                    if (bestValue < value) {
                        bestValue = value;
                        bestPath = path;
                        return true;
                    }
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(false, gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:36,
代码来源:MissionaryMission.java

示例19: findTargetPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Find a suitable mission location for this unit.
 *
 * @param aiUnit The {@code AIUnit} to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
private static PathNode findTargetPath(AIUnit aiUnit, int range,
                                       boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Location start = unit.getPathStartLocation();
    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();
    // Is there a valid target available from the starting tile?
    return unit.search(start, gd, standardCd, range, carrier);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:21,
代码来源:MissionaryMission.java

示例20: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Makes a goal decider that checks cash in sites.
 *
 * @param aiUnit The {@code AIUnit} to search with.
 * @param deferOK Keep track of the nearest colonies to use as a
 *     fallback destination.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          final boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;
            
            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                Location loc = extractTarget(aiUnit, path);
                if ((loc instanceof Colony
                        && invalidFullColonyReason(aiUnit, (Colony)loc)
                        == null)
                    || loc instanceof Europe) {
                    int value = scorePath(aiUnit, path);
                    if (bestValue < value) {
                        bestValue = value;
                        bestPath = path;
                        return true;
                    }
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(false, gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:40,
代码来源:CashInTreasureTrainMission.java

示例21: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a {@code GoalDecider} for finding the best colony
 * {@code Tile}, optionally falling back to the nearest colony.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @param deferOK Enable colony fallback.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private float bestValue = 0f;

            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                Location loc = extractTarget(aiUnit, path);
                if (loc instanceof Tile) {
                    float value = scorePath(aiUnit, path);
                    if (bestValue < value) {
                        bestValue = value;
                        bestPath = path;
                        return true;
                    }
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(false, gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:37,
代码来源:BuildColonyMission.java

示例22: findTargetPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a site for a new colony.  Favour closer sites.
 *
 * @param aiUnit The {@code AIUnit} to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Location start = unit.getPathStartLocation();
    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd
        = CostDeciders.avoidSettlementsAndBlockingUnits();

    // Try for something sensible nearby.
    return unit.search(start, gd, standardCd, range, carrier);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:22,
代码来源:BuildColonyMission.java

示例23: findCircleTarget

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a target for a unit without considering its movement
 * abilities.  This is used by missions when the current unit
 * can not find a target with the normal path finding routines,
 * and thus should consider targets that may require a carrier.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @param gd The {@code GoalDecider} that selects targets.
 * @param radius A maximum radius from the unit location to search within.
 * @param deferOK If true, fall back to the nearest port to Europe.
 * @return The best target {@code Tile} found, or null if none.
 */
protected static Location findCircleTarget(final AIUnit aiUnit,
                                           final GoalDecider gd,
                                           final int radius,
                                           boolean deferOK) {
    final Unit unit = aiUnit.getUnit();
    final Tile start = unit.getTile();
    if (start == null) {
        if (!deferOK) return null;
        Settlement settlement = unit.getOwner().getClosestPortForEurope();
        return (settlement == null) ? null : settlement;
    }
    return unit.getGame().getMap().searchCircle(start, gd, radius);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:26,
代码来源:Mission.java

示例24: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Gets a {@code GoalDecider} for finding the best colony
 * {@code Tile}, optionally falling back to the nearest colony.
 *
 * @param aiUnit The {@code AIUnit} that is searching.
 * @param deferOK Enable colony fallback.
 * @return A suitable {@code GoalDecider}.
 */
private static GoalDecider getGoalDecider(final AIUnit aiUnit,
                                          boolean deferOK) {
    GoalDecider gd = new GoalDecider() {
            private PathNode bestPath = null;
            private int bestValue = Integer.MIN_VALUE;

            @Override
            public PathNode getGoal() { return bestPath; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                Location loc = extractTarget(aiUnit, path);
                if (loc instanceof IndianSettlement
                    || loc instanceof Tile) {
                    int value = scorePath(aiUnit, path);
                    if (bestValue < value) {
                        bestValue = value;
                        bestPath = path;
                        return true;
                    }
                }
                return false;
            }
        };
    return (deferOK) ? GoalDeciders.getComposedGoalDecider(false, gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:38,
代码来源:ScoutingMission.java

示例25: findTargetPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Finds a suitable scouting target for the supplied unit.
 *
 * @param aiUnit The {@code AIUnit} to execute this mission.
 * @param range An upper bound on the number of moves.
 * @param deferOK Enables deferring to a fallback colony.
 * @return A path to the new target, or null if none found.
 */
public static PathNode findTargetPath(AIUnit aiUnit, int range,
                                      boolean deferOK) {
    if (invalidAIUnitReason(aiUnit) != null) return null;
    final Unit unit = aiUnit.getUnit();
    final Location start = unit.getPathStartLocation();
    final Unit carrier = unit.getCarrier();
    final GoalDecider gd = getGoalDecider(aiUnit, deferOK);
    final CostDecider standardCd = CostDeciders.avoidIllegal();

    // Can the scout legally reach a valid target from where it
    // currently is?
    return unit.search(start, gd, standardCd, range, carrier);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:22,
代码来源:ScoutingMission.java

示例26: findOurNearestSettlement

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDecider; //导入依赖的package包/类
/**
 * Find a path for this unit to the nearest settlement with the
 * same owner that is reachable without a carrier.
 *
 * @param startTile The {@code Tile} to start searching from.
 * @param excludeStart If true, ignore any settlement the unit is
 *     currently in.
 * @param range An upper bound on the number of moves.
 * @param coastal If true, the settlement must have a path to Europe.
 * @return The nearest matching settlement if any, otherwise null.
 */
public PathNode findOurNearestSettlement(final Tile startTile,
                                         final boolean excludeStart,
                                         int range, final boolean coastal) {
    final Player player = getOwner();
    if (startTile == null || !player.hasSettlements()) return null;
    final GoalDecider gd = new GoalDecider() {

            private int bestValue = Integer.MAX_VALUE;
            private PathNode best = null;

            @Override
            public PathNode getGoal() { return best; }
            @Override
            public boolean hasSubGoals() { return true; }
            @Override
            public boolean check(Unit u, PathNode path) {
                Tile t = path.getTile();
                if (t == null
                    || (t == startTile && excludeStart)) return false;
                Settlement settlement = t.getSettlement();
                int value;
                if (settlement != null
                    && player.owns(settlement)
                    && (!coastal || settlement.isConnectedPort())
                    && (value = path.getTotalTurns()) < bestValue) {
                    bestValue = value;
                    best = path;
                    return true;
                }
                return false;
            }
        };
    return search(startTile, gd, CostDeciders.avoidIllegal(), range, null);
}
 

开发者ID:FreeCol,
项目名称:freecol,
代码行数:46,
代码来源:Unit.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)