Make Grid iterable

This commit is contained in:
2024-09-05 20:10:34 -07:00
parent 9e6223f886
commit d6fc0396cb
11 changed files with 77 additions and 46 deletions

View File

@@ -60,11 +60,11 @@ Game::Game(Grid grid)
, debug_out_{}
{
// set each unit to its initial hit points
grid_.each([&](auto k, auto v) {
for (auto [k, v] : grid_) {
if (IsUnit(v)) {
units_[k] = initial_hp;
}
});
}
}
// Render the game as seen in the examples
@@ -166,9 +166,9 @@ auto Game::Simulate() -> std::optional<int> {
// Detect when no targets remain for this unit and end the game
auto game_over = true;
grid_.each([&](auto k, auto v) {
for (auto [k, v] : grid_) {
if (IsOpposed(active_team, v)) game_over = false;
});
}
if (game_over) {
int total_hp = 0;
for (auto const& [_,v] : units_) { total_hp += v; }