I'm making a pokemon type matchup calculator(water beats fire etc.) and I've come upon a rather strange bug. I'm iterating through an ArrayList containing all the weaknesses of that pokemon and comparing them to all of the resistances in order to see if any of them cancel out. Here's the repository for it on GitHub. The exception is being thrown on line 140 of src/main/Pokemon.java. I've accounted for the index changing when an item is removed, but still no luck. Here's the offending loop:
//Check 2x weakness v 2x Resist
eDiff = 0;
rDiff = 0;
for (int e = 0; e < effective.size()-eDiff; e++) {
for (int r = 0; r < resist.size()-rDiff; r++) {
if (effective.get(e-eDiff).equals(resist.get(r-rDiff))) {
effective.remove(e-eDiff);
resist.remove(r-rDiff);
eDiff++;
rDiff++;
}
}
}
Any thoughts?