Skip to content

Commit

Permalink
Fix #2117: crash if either combatant was guaranteed to die
Browse files Browse the repository at this point in the history
Regression from commit f6c4f3d.

The code divided by zero and the probability to stay unscathed ended up as
NaN, which triggered an assertion failure if the AI simulated one more
fight for either combatant.
  • Loading branch information
jyrkive committed Oct 25, 2017
1 parent 73fa6bc commit 8bfc5eb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/attack_prediction.cpp
Expand Up @@ -2097,7 +2097,8 @@ void complex_fight(attack_prediction_mode mode,
double first_hit = hit_chance * opp_hit_unknown;
opp_hit += first_hit;
opp_hit_unknown -= first_hit;
double this_hit_killed_b = (pm->dead_prob_b() - b_already_dead) / ((1.0 - b_already_dead) * (1.0 - pm->dead_prob_a()));
double both_were_alive = (1.0 - b_already_dead) * (1.0 - pm->dead_prob_a());
double this_hit_killed_b = both_were_alive != 0.0 ? (pm->dead_prob_b() - b_already_dead) / both_were_alive : 1.0;
self_hit_unknown *= (1.0 - this_hit_killed_b);
}
if(i < opp_strikes) {
Expand All @@ -2109,7 +2110,8 @@ void complex_fight(attack_prediction_mode mode,
double first_hit = opp_hit_chance * self_hit_unknown;
self_hit += first_hit;
self_hit_unknown -= first_hit;
double this_hit_killed_a = (pm->dead_prob_a() - a_already_dead) / ((1.0 - a_already_dead) * (1.0 - pm->dead_prob_b()));
double both_were_alive = (1.0 - a_already_dead) * (1.0 - pm->dead_prob_b());
double this_hit_killed_a = both_were_alive != 0.0 ? (pm->dead_prob_a() - a_already_dead) / both_were_alive : 1.0;
opp_hit_unknown *= (1.0 - this_hit_killed_a);
}
}
Expand Down

0 comments on commit 8bfc5eb

Please sign in to comment.