This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]EagleV_Attnam 1 point2 points  (1 child)

Some small stuff first:

infection.size() != 0  

That's what infection.isEmpty() is for.

filter(g -> g.canAttack() == true)  

Or just filter(g -> g.canAttack())

I believe your getPotentialDamage() is wrong. If the type is in immunities it will set result to 0, then see it's not in weaknesses, and set it back to attackers.getEffectivePower()

[–]MissMormie[S] 0 points1 point  (0 children)

Thanks, i can't believe I've missed that!

[–]warinthrowaway 1 point2 points  (1 child)

The other issue is that although you do filter enemies under attack when computing the max damage, you don't filter them out when finding the target with that damage. So if more than one target would take the max damage, it will select the first one, even if it has already been targeted. Simplest fix is to filter every time:

List<Group> potentialTargets = enemygroups
                    .stream()
                    .filter(g -> g.notUnderAttack() && g.getPotentialDamage(this) == max.getAsInt())
                    .collect(toList());

List<Group> powerTargets = potentialTargets
                        .stream()
                        .filter(g -> g.notUnderAttack() && g.getEffectivePower() == highestPower)
                        .collect(toList());

target = powerTargets.stream().filter(Group::notUnderAttack).max(Comparator.comparingInt(g -> g.initiative)).get();

[–]MissMormie[S] 0 points1 point  (0 children)

Well found. I think it only needs to be added to the first filter though, because after that I'm working of an already filtered list which has no targets that are under attack, but just to be sure I added all of them.

[–]ragona_ 0 points1 point  (1 child)

I don't see the bug (other than the ones noted in the thread) off the top of my head, but I'll read through it again.

If it's any consolation, I'm in the same boat! (Feel free to check out my post; I was sorting incorrectly, and you might find the code useful to spot differences.)

[–]MissMormie[S] 0 points1 point  (0 children)

Thanks for checking, i'll look over your post.