java中的odds,Java CombatModel.calculateCombatOdds方法代码示例

import net.sf.freecol.common.model.CombatModel; //导入方法依赖的package包/类

/**

* Searches for a unit that is a credible threatening unit to this

* unit within a range.

*

* @param range The number of turns to search for a threat in.

* @param threat The maximum tolerable probability of a potentially

* threatening unit defeating this unit in combat.

* @return A path to the threat, or null if not found.

*/

public PathNode searchForDanger(final int range, final float threat) {

final CombatModel cm = getGame().getCombatModel();

final Tile start = getTile();

final GoalDecider threatDecider = new GoalDecider() {

private PathNode found = null;

@Override

public PathNode getGoal() { return found; }

@Override

public boolean hasSubGoals() { return false; }

@Override

public boolean check(Unit unit, PathNode path) {

Tile tile = path.getTile();

if (tile == null) return false;

Unit first = tile.getFirstUnit();

if (first == null

|| !getOwner().atWarWith(first.getOwner())) {

return false;

}

final Predicate attackerPred = u -> {

PathNode p;

return (u.canAttack(unit)

&& cm.calculateCombatOdds(u, unit).win >= threat

&& (p = u.findPath(start)) != null

&& p.getTotalTurns() < range);

};

if (any(transform(tile.getUnits(), attackerPred))) {

found = path;

return true;

}

return false;

}

};

// The range to search will depend on the speed of the other

// unit. We can not know what it will be in advance, and it

// might be significantly faster than this unit. We do not

// want to just use an unbounded search range because this

// routine must be quick (especially when the supplied range

// is low). So use the heuristic of increasing the range by

// the ratio of the fastest appropriate (land/naval) unit type

// speed over the unit speed.

int reverseRange = range * (((isNaval())

? getSpecification().getFastestNavalUnitType()

: getSpecification().getFastestLandUnitType())

.getMovement()) / this.getType().getMovement();

return (start == null) ? null

: search(start, threatDecider, CostDeciders.avoidIllegal(),

reverseRange, getCarrier());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值