From 13974739d9692937b775c06eb6ec9bf1de4f7564 Mon Sep 17 00:00:00 2001 From: sp Date: Sun, 7 Jan 2024 16:58:14 +0100 Subject: [PATCH] commit to (col, row) --- util/Grid.cpp | 31 ++----------------------------- util/Grid.h | 8 ++------ util/cell.cpp | 10 +++++----- util/cell.h | 8 ++++---- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/util/Grid.cpp b/util/Grid.cpp index cdd07eb..7a4cbfb 100644 --- a/util/Grid.cpp +++ b/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) { for (auto& config : configuration) { diff --git a/util/Grid.h b/util/Grid.h index 80f5055..e33d34e 100644 --- a/util/Grid.h +++ b/util/Grid.h @@ -22,16 +22,12 @@ struct GridOptions { class Grid { public: - Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map &stateRewards = {}, const double faultyProbability = 0); + Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map &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, const prism::ModelType& modelType); void applyOverwrites(std::string& str, std::vector& configuration); @@ -69,5 +65,5 @@ class Grid { std::map backgroundTiles; std::map stateRewards; - double faultyProbability; + float faultyProbability; }; diff --git a/util/cell.cpp b/util/cell.cpp index df20997..c6a72a1 100644 --- a/util/cell.cpp +++ b/util/cell.cpp @@ -4,10 +4,14 @@ std::ostream &operator<<(std::ostream &os, const cell &c) { os << static_cast(c.type) << static_cast(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 &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 &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"; diff --git a/util/cell.h b/util/cell.h index d1d1169..ca71559 100644 --- a/util/cell.h +++ b/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 &grid) const; cell getEast(const std::vector &grid) const;