Browse Source

commit to (col, row)

pull/1/head
sp 11 months ago
parent
commit
13974739d9
  1. 31
      util/Grid.cpp
  2. 8
      util/Grid.h
  3. 10
      util/cell.cpp
  4. 8
      util/cell.h

31
util/Grid.cpp

@ -89,43 +89,16 @@ cells Grid::getGridCells() {
}
bool Grid::isBlocked(coordinates p) {
return isWall(p); //|| isLockedDoor(p) || isKey(p);
return isWall(p);
}
bool Grid::isWall(coordinates p) {
return std::find_if(walls.begin(), walls.end(),
[p](cell cell) {
return cell.row == p.first && cell.column == p.second;
return cell.row == p.second && cell.column == p.first;
}) != walls.end();
}
bool Grid::isLockedDoor(coordinates p) {
return std::find_if(lockedDoors.begin(), lockedDoors.end(),
[p](cell cell) {
return cell.row == p.first && cell.column == p.second;
}) != lockedDoors.end();
}
bool Grid::isUnlockedDoor(coordinates p) {
return std::find_if(unlockedDoors.begin(), unlockedDoors.end(),
[p](cell cell) {
return cell.row == p.first && cell.column == p.second;
}) != unlockedDoors.end();
}
bool Grid::isKey(coordinates p) {
return std::find_if(keys.begin(), keys.end(),
[p](cell cell) {
return cell.row == p.first && cell.column == p.second;
}) != keys.end();
}
bool Grid::isBox(coordinates p) {
return std::find_if(boxes.begin(), boxes.end(),
[p](cell cell) {
return cell.row == p.first && cell.column == p.second;
}) != boxes.end();
}
void Grid::applyOverwrites(std::string& str, std::vector<Configuration>& configuration) {
for (auto& config : configuration) {

8
util/Grid.h

@ -22,16 +22,12 @@ struct GridOptions {
class Grid {
public:
Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards = {}, const double faultyProbability = 0);
Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards = {}, const float faultyProbability = 0);
cells getGridCells();
bool isBlocked(coordinates p);
bool isWall(coordinates p);
bool isLockedDoor(coordinates p);
bool isUnlockedDoor(coordinates p);
bool isKey(coordinates p);
bool isBox(coordinates p);
void printToPrism(std::ostream &os, std::vector<Configuration>& configuration, const prism::ModelType& modelType);
void applyOverwrites(std::string& str, std::vector<Configuration>& configuration);
@ -69,5 +65,5 @@ class Grid {
std::map<Color, cells> backgroundTiles;
std::map<coordinates, float> stateRewards;
double faultyProbability;
float faultyProbability;
};

10
util/cell.cpp

@ -4,10 +4,14 @@
std::ostream &operator<<(std::ostream &os, const cell &c) {
os << static_cast<char>(c.type) << static_cast<char>(c.color);
os << " at (" << c.row << "," << c.column << ")";
os << " at (" << c.column << "," << c.row << ")";
return os;
}
coordinates cell::getCoordinates() const {
return std::make_pair(column, row);
}
cell cell::getNorth(const std::vector<cell> &grid) const {
auto north = std::find_if(grid.begin(), grid.end(), [this](const cell &c) {
return this->row - 1 == c.row && this->column == c.column;
@ -52,10 +56,6 @@ cell cell::getWest(const std::vector<cell> &grid) const {
return *west;
}
coordinates cell::getCoordinates() const {
return std::make_pair(row, column);
}
std::string cell::getColor() const {
switch(color) {
case Color::Red: return "red";

8
util/cell.h

@ -40,10 +40,10 @@ std::string getColor(Color color);
class cell {
public:
coordinates getNorth() const { return std::make_pair(row - 1, column); }
coordinates getSouth() const { return std::make_pair(row + 1, column); }
coordinates getEast() const { return std::make_pair(row, column + 1); }
coordinates getWest() const { return std::make_pair(row, column - 1); }
coordinates getNorth() const { return std::make_pair(column, row - 1); }
coordinates getSouth() const { return std::make_pair(column, row + 1); }
coordinates getEast() const { return std::make_pair(column + 1, row); }
coordinates getWest() const { return std::make_pair(column - 1, row); }
cell getNorth(const std::vector<cell> &grid) const;
cell getEast(const std::vector<cell> &grid) const;

Loading…
Cancel
Save