Browse Source

isNextTo formulas for doors

pull/1/head
sp 11 months ago
parent
commit
5955bb9791
  1. 18
      util/PrismFormulaPrinter.cpp
  2. 5
      util/PrismFormulaPrinter.h

18
util/PrismFormulaPrinter.cpp

@ -32,7 +32,7 @@ namespace prism {
: os(os), agentName(agentName), restrictions(restrictions), boxes(boxes), balls(balls), lockedDoors(lockedDoors), unlockedDoors(unlockedDoors), keys(keys), slipperyTiles(slipperyTiles), lava(lava) : os(os), agentName(agentName), restrictions(restrictions), boxes(boxes), balls(balls), lockedDoors(lockedDoors), unlockedDoors(unlockedDoors), keys(keys), slipperyTiles(slipperyTiles), lava(lava)
{ } { }
void PrismFormulaPrinter::printFormulas() {
void PrismFormulaPrinter::print() {
for(const auto& [direction, cells] : restrictions) { for(const auto& [direction, cells] : restrictions) {
printRestrictionFormula(direction, cells); printRestrictionFormula(direction, cells);
} }
@ -58,17 +58,19 @@ namespace prism {
} }
for(const auto& door : unlockedDoors) { for(const auto& door : unlockedDoors) {
std::string color = capitalize(door.getColor());
printRestrictionFormulaWithCondition(color + "Door", getSurroundingCells(door), "!" + color + "DoorOpened");
std::string identifier = capitalize(door.getColor()) + door.getType();
printRestrictionFormulaWithCondition(identifier, getSurroundingCells(door), "!" + identifier + "Open");
printIsNextToFormula(identifier, getSurroundingCells(door));
} }
for(const auto& door : lockedDoors) { for(const auto& door : lockedDoors) {
std::string color = capitalize(door.getColor());
printRestrictionFormulaWithCondition(color + "Door", getSurroundingCells(door), "!" + color + "DoorOpened");
std::string identifier = capitalize(door.getColor()) + door.getType();
printRestrictionFormulaWithCondition(identifier, getSurroundingCells(door), "!" + identifier + "Open");
printIsNextToFormula(identifier, getSurroundingCells(door));
} }
if(conditionalMovementRestrictions.size() > 0) { if(conditionalMovementRestrictions.size() > 0) {
os << buildFormula("CannotMoveConditionally", vectorToDisjunction(conditionalMovementRestrictions));
os << buildFormula(agentName + "CannotMoveConditionally", vectorToDisjunction(conditionalMovementRestrictions));
} }
} }
@ -80,6 +82,10 @@ namespace prism {
os << buildFormula(agentName + "IsOn" + type + direction, buildDisjunction(agentName, grid_cells)); os << buildFormula(agentName + "IsOn" + type + direction, buildDisjunction(agentName, grid_cells));
} }
void PrismFormulaPrinter::printIsNextToFormula(const std::string &type, const std::map<ViewDirection, coordinates> &coordinates) {
os << buildFormula(agentName + "IsNextTo" + type, buildDisjunction(agentName, coordinates));
}
void PrismFormulaPrinter::printRestrictionFormulaWithCondition(const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition) { void PrismFormulaPrinter::printRestrictionFormulaWithCondition(const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition) {
os << buildFormula(agentName + "CannotMove" + reason, "(" + buildDisjunction(agentName, coordinates) + ") & " + condition); os << buildFormula(agentName + "CannotMove" + reason, "(" + buildDisjunction(agentName, coordinates) + ") & " + condition);
conditionalMovementRestrictions.push_back(agentName + "CannotMove" + reason); conditionalMovementRestrictions.push_back(agentName + "CannotMove" + reason);

5
util/PrismFormulaPrinter.h

@ -17,10 +17,11 @@ namespace prism {
public: public:
PrismFormulaPrinter(std::ostream &os, const AgentName &agentName, const std::map<std::string, cells> &restrictions, const cells &boxes, const cells &balls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const cells &lava); PrismFormulaPrinter(std::ostream &os, const AgentName &agentName, const std::map<std::string, cells> &restrictions, const cells &boxes, const cells &balls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const cells &lava);
void printFormulas();
void print();
void printRestrictionFormula(const std::string &direction, const cells &grid_cells); void printRestrictionFormula(const std::string &direction, const cells &grid_cells);
void printIsOnFormula(const std::string &type, const cells &grid_cells, const std::string &direction = ""); void printIsOnFormula(const std::string &type, const cells &grid_cells, const std::string &direction = "");
void printIsNextToFormula(const std::string &type, const std::map<ViewDirection, coordinates> &coordinates);
void printRestrictionFormulaWithCondition(const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition); void printRestrictionFormulaWithCondition(const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition);
private: private:
std::string buildFormula(const std::string &formulaName, const std::string &formula); std::string buildFormula(const std::string &formulaName, const std::string &formula);
@ -29,7 +30,7 @@ namespace prism {
std::string buildDisjunction(const AgentName &agentName, const cells &cells, const std::vector<std::string> &conditions = {}); std::string buildDisjunction(const AgentName &agentName, const cells &cells, const std::vector<std::string> &conditions = {});
std::ostream &os; std::ostream &os;
AgentName agentName;
AgentName agentName; // move this to functions
std::map<std::string, cells> restrictions; std::map<std::string, cells> restrictions;
cells boxes; cells boxes;
cells balls; cells balls;

Loading…
Cancel
Save