Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-1806 committed Feb 8, 2024
1 parent c0efde8 commit 09e3afb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/defender/defender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ std::optional<size_t> Defender::get_nearest_attacker_index(
if (b.is_ability_active())
return true;

auto d1 = this->get_position().distance_to(a.get_position());

auto d2 = this->get_position().distance_to(b.get_position());

return d1 < d2;
return this->get_position().distance_to(a.get_position()) <
this->get_position().distance_to(b.get_position());
});
return std::distance(attackers.begin(), nearest_attacker);
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Game Game::simulate(
}
});

for (Game::attacker_id id : ability_activations) {
ranges::for_each(ability_activations, [&](Game::attacker_id id) {
auto attacker_index = this->get_attacker_index_by_id(id);
unsigned ability_activation_cost =
attackers[*attacker_index].get_ability_activation_cost();

if (coins_left < ability_activation_cost) {
break;
return;
}
coins_left -= ability_activation_cost;
// In case the ability is already active,
Expand All @@ -70,7 +70,7 @@ Game Game::simulate(
if (attacker_index.has_value()) {
attackers[*attacker_index].activate_ability(turn);
}
}
});

// Attacker Loop
ranges::for_each(attackers, [&](Attacker &attacker) mutable {
Expand Down

0 comments on commit 09e3afb

Please sign in to comment.