AI, combat: fixed that computer blocking an attacker by biggest creature instead optimal;

refactor: fixed that Defiant Vanguard depends on debug data;
This commit is contained in:
Oleg Agafonov 2024-12-25 18:23:43 +04:00
parent 138788659a
commit f4572faf8b
5 changed files with 48 additions and 30 deletions

View file

@ -909,6 +909,7 @@ public class ComputerPlayer6 extends ComputerPlayer {
List<Permanent> blockers = entry.getValue();
if (blockers != null) {
for (Permanent blocker : blockers) {
// TODO: buggy or miss on multi blocker requirements?!
player.declareBlocker(player.getId(), blocker.getId(), attackerId, game);
blocked = true;
}

View file

@ -83,28 +83,17 @@ public final class CombatUtil {
}
public static void sortByPower(List<Permanent> permanents, final boolean ascending) {
Collections.sort(permanents, new Comparator<Permanent>() {
@Override
public int compare(Permanent o1, Permanent o2) {
if (ascending) {
return o1.getPower().getValue() - o2.getPower().getValue();
} else {
return o2.getPower().getValue() - o1.getPower().getValue();
}
}
});
permanents.sort(Comparator.comparingInt(p -> p.getPower().getValue()));
if (!ascending) {
Collections.reverse(permanents);
}
}
public static Permanent getWorstCreature(List<Permanent> creatures) {
if (creatures.isEmpty()) {
return null;
}
Collections.sort(creatures, new Comparator<Permanent>() {
@Override
public int compare(Permanent o1, Permanent o2) {
return o2.getPower().getValue() - o1.getPower().getValue();
}
});
creatures.sort(Comparator.comparingInt(p -> p.getPower().getValue()));
return creatures.get(0);
}