Browse Source

added keys and doors to walkable tiles

changed key init value handling
pull/3/head
Thomas Knoll 1 year ago
parent
commit
83e68bbad3
  1. 6
      util/Grid.cpp
  2. 10
      util/PrismModulesPrinter.cpp
  3. 2
      util/PrismModulesPrinter.h

6
util/Grid.cpp

@ -130,6 +130,9 @@ void Grid::printToPrism(std::ostream& os, const prism::ModelType& modelType) {
walkable.push_back(agent); walkable.push_back(agent);
walkable.insert(walkable.end(), adversaries.begin(), adversaries.end()); walkable.insert(walkable.end(), adversaries.begin(), adversaries.end());
walkable.insert(walkable.end(), lava.begin(), lava.end()); walkable.insert(walkable.end(), lava.begin(), lava.end());
walkable.insert(walkable.end(), keys.begin(), keys.end());
walkable.insert(walkable.end(), lockedDoors.begin(), lockedDoors.end());
for(auto const& c : walkable) { for(auto const& c : walkable) {
if(isBlocked(c.getNorth())) northRestriction.push_back(c); if(isBlocked(c.getNorth())) northRestriction.push_back(c);
if(isBlocked(c.getEast())) eastRestriction.push_back(c); if(isBlocked(c.getEast())) eastRestriction.push_back(c);
@ -178,10 +181,11 @@ void Grid::printToPrism(std::ostream& os, const prism::ModelType& modelType) {
size_t agentIndex = 0; size_t agentIndex = 0;
for(auto agentNameAndPosition = agentNameAndPositionMap.begin(); agentNameAndPosition != agentNameAndPositionMap.end(); ++agentNameAndPosition, agentIndex++) { for(auto agentNameAndPosition = agentNameAndPositionMap.begin(); agentNameAndPosition != agentNameAndPositionMap.end(); ++agentNameAndPosition, agentIndex++) {
AgentName agentName = agentNameAndPosition->first; AgentName agentName = agentNameAndPosition->first;
//std::cout << "Agent Name: " << agentName << std::endl;
bool agentWithView = std::find(gridOptions.agentsWithView.begin(), gridOptions.agentsWithView.end(), agentName) != gridOptions.agentsWithView.end(); bool agentWithView = std::find(gridOptions.agentsWithView.begin(), gridOptions.agentsWithView.end(), agentName) != gridOptions.agentsWithView.end();
bool agentWithProbabilisticBehaviour = std::find(gridOptions.agentsWithProbabilisticBehaviour.begin(), gridOptions.agentsWithProbabilisticBehaviour.end(), agentName) != gridOptions.agentsWithProbabilisticBehaviour.end(); bool agentWithProbabilisticBehaviour = std::find(gridOptions.agentsWithProbabilisticBehaviour.begin(), gridOptions.agentsWithProbabilisticBehaviour.end(), agentName) != gridOptions.agentsWithProbabilisticBehaviour.end();
std::set<std::string> slipperyActions; std::set<std::string> slipperyActions;
printer.printInitStruct(os, agentName);
printer.printInitStruct(os, agentName, keys);
if(agentWithProbabilisticBehaviour) printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, backgroundTiles, agentWithView, gridOptions.probabilitiesForActions); if(agentWithProbabilisticBehaviour) printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, backgroundTiles, agentWithView, gridOptions.probabilitiesForActions);
else printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, backgroundTiles, agentWithView); else printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, backgroundTiles, agentWithView);
for(auto const& c : slipperyNorth) { for(auto const& c : slipperyNorth) {

10
util/PrismModulesPrinter.cpp

@ -253,7 +253,7 @@ namespace prism {
std::ostream& PrismModulesPrinter::printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys) { std::ostream& PrismModulesPrinter::printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys) {
for(auto const& key : keys) { for(auto const& key : keys) {
os << "\t" << agentName << "_has_"<< key.getColor() << "_key : bool init false;\n";
os << "\t" << agentName << "_has_"<< key.getColor() << "_key : bool;\n";//init false;\n";
} }
os << "\n"; os << "\n";
return os; return os;
@ -292,7 +292,7 @@ namespace prism {
return os; return os;
} }
std::ostream& PrismModulesPrinter::printInitStruct(std::ostream &os, const AgentName &agentName) {
std::ostream& PrismModulesPrinter::printInitStruct(std::ostream &os, const AgentName &agentName, const cells &keys) {
os << "init\n"; os << "init\n";
os << "\t(!AgentIsInGoal & !AgentIsInLava & !AgentDone & !AgentIsOnWall)"; os << "\t(!AgentIsInGoal & !AgentIsInLava & !AgentDone & !AgentIsOnWall)";
if(enforceOneWays) { if(enforceOneWays) {
@ -300,8 +300,14 @@ namespace prism {
} else { } else {
os << " & ( !AgentIsOnSlippery ) "; os << " & ( !AgentIsOnSlippery ) ";
} }
for (auto const& key : keys) {
os << " & ( !" << agentName << "_has_" << key.getColor() << "_key )";
}
os << "\nendinit\n\n"; os << "\nendinit\n\n";
return os; return os;
} }

2
util/PrismModulesPrinter.h

@ -66,7 +66,7 @@ namespace prism {
std::ostream& printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys); std::ostream& printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles); std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles); std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
std::ostream& printInitStruct(std::ostream &os, const AgentName &agentName);
std::ostream& printInitStruct(std::ostream &os, const AgentName &agentName, const cells &keys);
std::ostream& printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities = {}); std::ostream& printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities = {});
std::ostream& printMovementActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const bool agentWithView, const float &probability = 1.0); std::ostream& printMovementActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const bool agentWithView, const float &probability = 1.0);
std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex); std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex);

Loading…
Cancel
Save