2020-11-28 13:10:25 +00:00
|
|
|
#include "Pellets.hpp"
|
2021-06-16 11:59:16 +00:00
|
|
|
#include <algorithm>
|
2020-11-28 13:10:25 +00:00
|
|
|
|
2021-07-05 12:10:01 +00:00
|
|
|
namespace pacman {
|
|
|
|
|
2021-07-07 09:39:09 +00:00
|
|
|
Pellets::Pellets()
|
2021-07-08 15:42:24 +00:00
|
|
|
: positions(initialPelletPositions()) {}
|
2021-06-16 11:59:16 +00:00
|
|
|
|
2021-09-17 14:44:16 +00:00
|
|
|
bool Pellets::isPellet(GridPosition p) const {
|
|
|
|
auto match = [&p](GridPosition pellet) {
|
|
|
|
return p.x == pellet.x && p.y == pellet.y;
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::any_of(positions.begin(), positions.end(), match);
|
|
|
|
}
|
|
|
|
|
2021-07-05 11:54:54 +00:00
|
|
|
bool Pellets::eatPelletAtPosition(GridPosition p) {
|
2021-06-16 11:59:16 +00:00
|
|
|
auto it = std::find(positions.begin(), positions.end(), p);
|
|
|
|
if (it == positions.end())
|
|
|
|
return false;
|
|
|
|
positions.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
2021-07-05 12:10:01 +00:00
|
|
|
|
|
|
|
} // namespace pacman
|