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

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

java 3次浏览

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

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

示例1: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例2: getTrivialPath

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Gets the trivial path for this unit.  That is, the path to the
 * nearest available safe settlement.
 *
 * @return A path to the trivial target, or null if none found.
 */
public PathNode getTrivialPath() {
    if (isDisposed() || getLocation() == null) return null;
    if (!isNaval()) return findOurNearestSettlement();
    PathNode path = findOurNearestPort();
    if (path == null) {
        // This is unusual, but can happen when a ship is up a
        // river and foreign ship creates a blockage downstream.
        // If so, the rational thing to do is to go to a tile
        // where other units can pass and which has the best
        // connectivity to the high seas.
        Tile tile = getTile();
        if (tile != null && tile.isOnRiver()
            && tile.isHighSeasConnected()) {
            path = search(getLocation(), 
                GoalDeciders.getCornerGoalDecider(),
                CostDeciders.avoidSettlementsAndBlockingUnits(),
                INFINITY, null);
            if (path == null && tile.isRiverCorner()) {
                // Return trivial path if already present.
                return new PathNode(tile, 0, 0, false, null, null);
            }
        }
    }
    return path;
}
 

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

示例3: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例4: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例5: getGoalDecider

点赞 3

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例6: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例7: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例8: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例9: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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

示例10: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Makes a goal decider that checks cash in 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) {
    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 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(gd,
        GoalDeciders.getOurClosestSettlementGoalDecider())
        : gd;
}
 

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

示例11: getGoalDecider

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的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 IndianSettlement
                    || 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,
代码行数:35,
代码来源:ScoutingMission.java

示例12: findMapPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Find the quickest path for a unit (with optional carrier) from
 * a start tile to an end tile.
 *
 * @param unit The <code>Unit</code> to find the path for.
 * @param start The <code>Tile</code> in which the path starts from.
 * @param end The <code>Tile</code> at the end of the path.
 * @param carrier An optional naval carrier <code>Unit</code> to use.
 * @param costDecider An optional <code>CostDecider</code> for
 *     determining the movement costs (uses default cost deciders
 *     for the unit/s if not provided).
 * @return A path starting at the start tile and ending at the end
 *     tile, or null if none found.
 */
private PathNode findMapPath(Unit unit, Tile start, Tile end, Unit carrier,
                             CostDecider costDecider) {
    final Unit offMapUnit = (carrier != null) ? carrier : unit;
    final GoalDecider gd = GoalDeciders.getLocationGoalDecider(end);
    final SearchHeuristic sh = getManhattenHeuristic(end);

    PathNode path;
    if (start.getContiguity() == end.getContiguity()) {
        // If the unit potentially could get to the destination
        // without a carrier, compare both with-carrier and
        // without-carrier paths.  The latter will usually be
        // faster, but not always, e.g. mounted units on a good
        // road system.
        path = searchMap(unit, start, gd, costDecider,
                         INFINITY, null, sh);
        PathNode carrierPath = (carrier == null) ? null
            : searchMap(unit, start, gd, costDecider,
                        INFINITY, carrier, sh);
        if (carrierPath != null
            && (path == null
                || (path.getLastNode().getCost()
                    > carrierPath.getLastNode().getCost()))) {
            path = carrierPath;
        }
    } else if (offMapUnit != null) {
        // If there is a water unit then complex paths which use
        // settlements and inland lakes are possible, but hard to
        // capture with the contiguity test, so just allow the
        // search to proceed.
        path = searchMap(unit, start, gd, costDecider,
                         INFINITY, carrier, sh);
    } else { // Otherwise, there is a connectivity failure.
        path = null;
    }
    return path;
}
 

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

示例13: findMapPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Find the quickest path for a unit (with optional carrier) from
 * a start tile to an end tile.
 *
 * @param unit The {@code Unit} to find the path for.
 * @param start The {@code Tile} in which the path starts from.
 * @param end The {@code Tile} at the end of the path.
 * @param carrier An optional naval carrier {@code Unit} to use.
 * @param costDecider An optional {@code CostDecider} for
 *     determining the movement costs (uses default cost deciders
 *     for the unit/s if not provided).
 * @param lb An optional {@code LogBuilder} to log to.
 * @return A path starting at the start tile and ending at the end
 *     tile, or null if none found.
 */
private PathNode findMapPath(Unit unit, Tile start, Tile end, Unit carrier,
                             CostDecider costDecider, LogBuilder lb) {
    final Unit offMapUnit = (carrier != null) ? carrier
        : (unit != null && unit.isNaval()) ? unit
        : null;
    final GoalDecider gd = GoalDeciders.getLocationGoalDecider(end);
    final SearchHeuristic sh = getManhattenHeuristic(end);
    Unit embarkTo;

    PathNode path;
    if (start.getContiguity() == end.getContiguity()) {
        // If the unit potentially could get to the destination
        // without a carrier, compare both with-carrier and
        // without-carrier paths.  The latter will usually be
        // faster, but not always, e.g. mounted units on a good
        // road system.
        path = searchMap(unit, start, gd, costDecider,
                         INFINITY, null, sh, lb);
        PathNode carrierPath = (carrier == null) ? null
            : searchMap(unit, start, gd, costDecider,
                        INFINITY, carrier, sh, lb);
        if (carrierPath != null
            && (path == null
                || (path.getLastNode().getCost()
                    > carrierPath.getLastNode().getCost()))) {
            path = carrierPath;
        }

    } else if (offMapUnit != null) {
        // If there is an off-map unit then complex paths which
        // use settlements and inland lakes are possible, but hard
        // to capture with the contiguity test, so just allow the
        // search to proceed.
        path = searchMap(unit, start, gd, costDecider,
                         INFINITY, carrier, sh, lb);

    } else if (unit != null && unit.isOnCarrier()
        && !start.isLand() && end.isLand()
        && !start.getContiguityAdjacent(end.getContiguity()).isEmpty()) {
        // Special case where a land unit is trying to move off a
        // ship to adjacent land.
        path = searchMap(unit, start, gd, costDecider, INFINITY,
                         carrier, sh, lb);

    } else if (start.isLand() && !end.isLand()
        && end.getFirstUnit() != null
        && !end.getContiguityAdjacent(start.getContiguity()).isEmpty()
        && unit != null && unit.getOwner().owns(end.getFirstUnit())
        && (embarkTo = end.getCarrierForUnit(unit)) != null) {
        // Special case where a land unit is trying to move from
        // land to an adjacent ship.
        path = searchMap(unit, start,
                         GoalDeciders.getAdjacentLocationGoalDecider(end),
                         costDecider, INFINITY, null, null, lb);
        if (path != null) {
            PathNode last = path.getLastNode();
            last.next = new PathNode(embarkTo, 0, last.getTurns()+1, true,
                last, null);
        }
    } else { // Otherwise, there is a connectivity failure.
        path = null;
    }
    return path;
}
 

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

示例14: findMapPath

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Find the quickest path for a unit (with optional carrier) from
 * a start tile to an end tile.
 *
 * @param unit The {@code Unit} to find the path for.
 * @param start The {@code Tile} in which the path starts from.
 * @param end The {@code Tile} at the end of the path.
 * @param carrier An optional naval carrier {@code Unit} to use.
 * @param costDecider An optional {@code CostDecider} for
 *     determining the movement costs (uses default cost deciders
 *     for the unit/s if not provided).
 * @param lb An optional {@code LogBuilder} to log to.
 * @return A path starting at the start tile and ending at the end
 *     tile, or null if none found.
 */
private PathNode findMapPath(Unit unit, Tile start, Tile end, Unit carrier,
    CostDecider costDecider, LogBuilder lb) {
    final Unit offMapUnit = (carrier != null) ? carrier
        : (unit != null && unit.isNaval()) ? unit
        : null;
    final GoalDecider gd = GoalDeciders.getLocationGoalDecider(end);
    final SearchHeuristic sh = getManhattenHeuristic(end);
    Unit embarkTo;

    PathNode path;
    if (start.getContiguity() == end.getContiguity()) {
        // If the unit potentially could get to the destination
        // without a carrier, compare both with-carrier and
        // without-carrier paths.  The latter will usually be
        // faster, but not always, e.g. mounted units on a good
        // road system.
        path = searchMap(unit, start, gd, costDecider,
            INFINITY, null, sh, lb);
        PathNode carrierPath = (carrier == null) ? null
            : searchMap(unit, start, gd, costDecider,
                INFINITY, carrier, sh, lb);
        if (carrierPath != null
            && (path == null
                || (path.getLastNode().getCost()
                    > carrierPath.getLastNode().getCost()))) {
            path = carrierPath;
        }

    } else if (offMapUnit != null) {
        // If there is an off-map unit then complex paths which
        // use settlements and inland lakes are possible, but hard
        // to capture with the contiguity test, so just allow the
        // search to proceed.
        path = searchMap(unit, start, gd, costDecider,
            INFINITY, carrier, sh, lb);

    } else if (unit != null && unit.isOnCarrier()
        && !start.isLand() && end.isLand()
        && !start.getContiguityAdjacent(end.getContiguity()).isEmpty()) {
        // Special case where a land unit is trying to move off a
        // ship to adjacent land.
        path = searchMap(unit, start, gd, costDecider, INFINITY,
            carrier, sh, lb);

    } else if (start.isLand() && !end.isLand()
        && end.getFirstUnit() != null
        && !end.getContiguityAdjacent(start.getContiguity()).isEmpty()
        && unit != null && unit.getOwner().owns(end.getFirstUnit())
        && (embarkTo = end.getCarrierForUnit(unit)) != null) {
        // Special case where a land unit is trying to move from
        // land to an adjacent ship.
        path = searchMap(unit, start,
            GoalDeciders.getAdjacentLocationGoalDecider(end), costDecider,
            INFINITY, null, null, lb);
        if (path != null) {
            PathNode last = path.getLastNode();
            last.next = new PathNode(embarkTo, 0, last.getTurns()+1, true,
                last, null);
        }
    } else { // Otherwise, there is a connectivity failure.
        path = null;
    }
    return path;
}
 

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

示例15: collectDestinations

点赞 2

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
private void collectDestinations(Unit unit, List<GoodsType> goodsTypes) {
    final Player player = unit.getOwner();
    final Settlement inSettlement = unit.getSettlement();
    final boolean canTrade = player.hasAbility("model.ability.tradeWithForeignColonies");
    final Europe europe = player.getEurope();
    final Game game = getGame();
    final Map map = game.getMap();
    int turns;

    if (unit.isInEurope() && !unit.getType().canMoveToHighSeas()) return;
    for (Player p : game.getPlayers()) {
        if (p != player
            && (!p.hasContacted(player) 
                || (p.isEuropean() && !canTrade))) continue;

        for (Settlement s : p.getSettlements()) {
            if (s == inSettlement
                || (unit.isNaval() && !s.isConnectedPort())
                || (s instanceof IndianSettlement
                    && !((IndianSettlement)s).hasContacted(player)))
                continue;
            if (p == player) {
                if ((turns = unit.getTurnsToReach(s)) == INFINITY) 
                    continue;
            } else {
                PathNode path = unit.search(unit.getLocation(),
                    GoalDeciders.getAdjacentLocationGoalDecider(s),
                    null, INFINITY, null);
                if (path == null) continue;
                turns = path.getTotalTurns();
                if (path.getLastNode().getMovesLeft() <= 0) turns++;
            }
            destinations.add(new Destination(s, turns,
                    ((s.getOwner() == unit.getOwner()) ? ""
                        : getExtras(unit, s, goodsTypes))));
        }
    }
    if (unit.isInEurope()) {
        destinations.add(new Destination(map, unit.getSailTurns(), ""));
    } else if (europe != null
        && player.canMoveToEurope()
        && unit.getType().canMoveToHighSeas()
        && (turns = unit.getTurnsToReach(europe)) != INFINITY) {
        destinations.add(new Destination(europe, turns,
                getExtras(unit, europe, goodsTypes)));
    }
    Collections.sort(destinations,
        ((destinationComparator != null) ? destinationComparator
            : new DestinationComparator(player)));
}
 

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

示例16: getBestEntryPath

点赞 1

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Gets the best (closest) path location for this unit to reach a
 * given tile from off the map.
 *
 * @param unit The {@code Unit} to check.
 * @param tile The target {@code Tile}.
 * @param carrier An optional carrier {@code Unit}to use.
 * @param costDecider An optional {@code CostDecider} to use.
 * @return A path to the best entry location tile to arrive on the
 *     map at, or null if none found.
 */
private PathNode getBestEntryPath(Unit unit, Tile tile, Unit carrier,
                                  CostDecider costDecider) {
    if (costDecider == null)
        costDecider = CostDeciders.avoidSettlementsAndBlockingUnits();
    return searchMap(unit, tile, GoalDeciders.getHighSeasGoalDecider(),
                     costDecider, INFINITY, carrier, null, null);
}
 

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

示例17: getBestEntryPath

点赞 1

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Gets the best (closest) path location for this unit to reach a
 * given tile from off the map.
 *
 * @param unit The {@code Unit} to check.
 * @param tile The target {@code Tile}.
 * @param carrier An optional carrier {@code Unit}to use.
 * @param costDecider An optional {@code CostDecider} to use.
 * @return A path to the best entry location tile to arrive on the
 *     map at, or null if none found.
 */
private PathNode getBestEntryPath(Unit unit, Tile tile, Unit carrier,
    CostDecider costDecider) {
    return searchMap(unit, tile, GoalDeciders.getHighSeasGoalDecider(),
        ((costDecider != null) ? costDecider
            : CostDeciders.avoidSettlementsAndBlockingUnits()),
        INFINITY, carrier, null, null);
}
 

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

示例18: getBestEntryPath

点赞 1

import net.sf.freecol.common.model.pathfinding.GoalDeciders; //导入依赖的package包/类
/**
 * Gets the best (closest) path location for this unit to reach a
 * given tile from off the map.
 *
 * @param unit The <code>Unit</code> to check.
 * @param tile The target <code>Tile</code>.
 * @param carrier An optional carrier <code>Unit</code>to use.
 * @param costDecider An optional <code>CostDecider</code> to use.
 * @return A path to the best entry location tile to arrive on the
 *     map at, or null if none found.
 */
private PathNode getBestEntryPath(Unit unit, Tile tile, Unit carrier,
                                  CostDecider costDecider) {
    return searchMap(unit, tile, GoalDeciders.getHighSeasGoalDecider(),
                     costDecider, INFINITY, carrier, null);
}
 

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


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