Make Grid iterable
This commit is contained in:
@@ -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; }
|
||||
|
Reference in New Issue
Block a user