Source:
<code>private void checkEndOfBattle(final StepUnits units) { final Collection<Unit> attackingUnits = units.getAliveOrWaitingToDieFriendly(); final Collection<Unit> defendingUnits = units.getAliveOrWaitingToDieEnemy(); final GamePlayer attacker = units.getPlayer(); final Territory battleSite = parameters.getLocation(); final Collection<TerritoryEffect> territoryEffects = parameters.getTerritoryEffects(); if (CollectionUtils.getMatches(attackingUnits, Matches.unitIsNotInfrastructure()).size() == 0) { if (!Properties.getTransportCasualtiesRestricted(parameters.getData())) { loseProbability = 1; hasResult = true; } else { final Predicate<Unit> matchAllied = Matches.unitIsTransport() .and(Matches.unitIsNotCombatTransport()) .and(Matches.isUnitAllied(attacker, parameters.getData())); final List<Unit> alliedTransports = CollectionUtils.getMatches(battleSite.getUnits(), matchAllied); <START> if (alliedTransports.isEmpty()) { <END> loseProbability = 1; hasResult = true; } else if (round <= 1) { } else { loseProbability = 1; hasResult = true; } } } else if (CollectionUtils.getMatches(defendingUnits, Matches.unitIsNotInfrastructure()) .size() == 0) { if (Properties.getTransportCasualtiesRestricted(parameters.getData())) { checkUndefendedTransports(units.getEnemy(), units); } checkForUnitsThatCanRollLeft(false, units); winProbability = 1; hasResult = true; } else if (MAX_ROUNDS > 0 && MAX_ROUNDS <= round) { tieProbability = 1; hasResult = true; } if (hasResult && units.noMoreEnemies() && units.noMoreFriendlies()) { loseProbability = 0; winProbability = 0; badProbability = 0; tieProbability = 1; } }</code><technical_language>Method checkEndOfBattle a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring</technical_language>

Target:
private void checkEndOfBattle(final StepUnits units) { final Collection<Unit> attackingUnits = units.getAliveOrWaitingToDieFriendly(); final Collection<Unit> defendingUnits = units.getAliveOrWaitingToDieEnemy(); final GamePlayer attacker = units.getPlayer(); final Territory battleSite = parameters.getLocation(); if (CollectionUtils.getMatches(attackingUnits, Matches.unitIsNotInfrastructure()).isEmpty()) { if (!Properties.getTransportCasualtiesRestricted(parameters.getData())) { loseProbability = 1; hasResult = true; } else { final Predicate<Unit> matchAllied = Matches.unitIsTransport() .and(Matches.unitIsNotCombatTransport()) .and(Matches.isUnitAllied(attacker, parameters.getData())); final List<Unit> alliedTransports = CollectionUtils.getMatches(battleSite.getUnits(), matchAllied); if (alliedTransports.isEmpty()) { loseProbability = 1; hasResult = true; } else if (round <= 1) { } else { loseProbability = 1; hasResult = true; } } } else if (CollectionUtils.getMatches(defendingUnits, Matches.unitIsNotInfrastructure()).size() == 0) { if (Properties.getTransportCasualtiesRestricted(parameters.getData())) { checkUndefendedTransports(units.getEnemy(), units); } checkForUnitsThatCanRollLeft(false, units); winProbability = 1; hasResult = true; } else if (MAX_ROUNDS > 0 && MAX_ROUNDS <= round) { tieProbability = 1; hasResult = true; } if (hasResult && units.noMoreEnemies() && units.noMoreFriendlies()) { loseProbability = 0; winProbability = 0; badProbability = 0; tieProbability = 1; } }