You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
7.6 KiB

  1. #pragma once
  2. #include <iostream>
  3. #include <set>
  4. #include <functional>
  5. #include "MinigridGrammar.h"
  6. #include "PrismPrinter.h"
  7. #include "ConfigYaml.h"
  8. std::string northUpdate(const AgentName &a);
  9. std::string southUpdate(const AgentName &a);
  10. std::string eastUpdate(const AgentName &a);
  11. std::string westUpdate(const AgentName &a);
  12. namespace prism {
  13. class PrismModulesPrinter {
  14. public:
  15. PrismModulesPrinter(std::ostream& os, const ModelType &modelType, const coordinates &maxBoundaries, const cells &boxes, const cells &balls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const AgentNameAndPositionMap &agentNameAndPositionMap, std::vector<Configuration> config, const float probIntended, const float faultyProbability);
  16. std::ostream& print();
  17. std::ostream& printModelType(const ModelType &modelType);
  18. std::ostream& printConstants(std::ostream &os, const std::vector<std::string> &constants);
  19. /*
  20. * Representation for Slippery Tile.
  21. * -) North: Slips from North to South
  22. * -) East: Slips from East to West
  23. * -) South: Slips from South to North
  24. * -) West: Slips from West to East
  25. */
  26. enum class SlipperyType { North, East, South, West };
  27. /*
  28. * Prints Slippery on move action.
  29. *
  30. * @param neighborhood: Information of wall-blocks in 8-neighborhood { n, nw, e, se, s, sw, w, nw }. If entry is false, then corresponding neighboorhood position is a wall.
  31. * @param orientation: Information of slippery type (either north, south, east, west).
  32. */
  33. std::ostream& printSlipperyMove(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &c, std::set<std::string> &slipperyActions, const std::array<bool, 8>& neighborhood, SlipperyType orientation);
  34. /*
  35. * Prints Slippery on turn action.
  36. *
  37. * @param neighborhood: Information of wall-blocks in 8-neighborhood { n, nw, e, se, s, sw, w, nw }. If entry is false, then corresponding neighboorhood position is a wall.
  38. * @param orientation: Information of slippery type (either north, south, east, west).
  39. */
  40. std::ostream& printSlipperyTurn(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &c, std::set<std::string> &slipperyActions, const std::array<bool, 8>& neighborhood, SlipperyType orientation);
  41. std::ostream& printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType);
  42. std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName);
  43. std::ostream& printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities = {}, const std::set<std::string> &slipperyActions = {});
  44. std::ostream& printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer);
  45. std::ostream& printRewards(std::ostream &os, const AgentName &agentName, const std::map<coordinates, float> &stateRewards, const cells &lava, const cells &goals, const std::map<Color, cells> &backgroundTiles);
  46. std::ostream& printConfiguration(std::ostream &os, const std::vector<Configuration>& configurations);
  47. std::ostream& printConfiguredActions(std::ostream &os, const AgentName &agentName);
  48. bool isGame() const;
  49. private:
  50. void printPortableObjectModule(const cell &object);
  51. void printPortableObjectActions(const std::string &agentName, const std::string &identifier);
  52. void printDoorModule(const cell &object, const bool &opened);
  53. void printLockedDoorActions(const std::string &agentName, const std::string &identifier);
  54. void printUnlockedDoorActions(const std::string &agentName, const std::string &identifier);
  55. void printRobotModule(const AgentName &agentName, const coordinates &initialPosition);
  56. void printPortableObjectActionsForRobot(const std::string &agentName, const std::string &identifier);
  57. void printUnlockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier);
  58. void printLockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier, const std::string &key);
  59. void printMovementActionsForRobot(const std::string &a);
  60. void printTurnActionsForRobot(const std::string &a);
  61. void printSlipperyMovementActionsForRobot(const AgentName &a);
  62. void printSlipperyMovementActionsForNorth(const AgentName &a);
  63. void printSlipperyMovementActionsForEast(const AgentName &a);
  64. void printSlipperyMovementActionsForSouth(const AgentName &a);
  65. void printSlipperyMovementActionsForWest(const AgentName &a);
  66. void printSlipperyTurnActionsForNorth(const AgentName &a);
  67. void printSlipperyTurnActionsForEast(const AgentName &a);
  68. void printSlipperyTurnActionsForSouth(const AgentName &a);
  69. void printSlipperyTurnActionsForWest(const AgentName &a);
  70. std::string printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection);
  71. std::string printMovementUpdate(const AgentName &a, const update &update) const;
  72. std::string printTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::string &cond = "");
  73. std::string printTurnUpdate(const AgentName &a, const update &u, const ActionId &actionId) const;
  74. std::string printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards);
  75. std::string printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const;
  76. std::string printSlipperyTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::vector<std::string> &guards, const std::string &cond);
  77. std::string printSlipperyTurnUpdate(const AgentName &a, const updates &u);
  78. void printFaultyMovementModule(const AgentName &a);
  79. void printMoveModule();
  80. bool anyPortableObject() const;
  81. bool faultyBehaviour() const;
  82. bool slipperyBehaviour() const;
  83. std::string moveGuard(const AgentName &agentName) const;
  84. std::string faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const;
  85. std::string faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const;
  86. std::string moveUpdate(const AgentName &agentName) const;
  87. std::string updatesToString(const updates &updates) const;
  88. std::string updateToString(const update &u) const;
  89. std::string viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView = true) const;
  90. std::string buildConjunction(const AgentName &a, std::vector<std::string> formulae) const;
  91. std::ostream &os;
  92. std::stringstream actionStream;
  93. ModelType const &modelType;
  94. coordinates const &maxBoundaries;
  95. AgentName agentName;
  96. cells boxes;
  97. cells balls;
  98. cells lockedDoors;
  99. cells unlockedDoors;
  100. cells keys;
  101. std::map<std::string, cells> slipperyTiles;
  102. AgentNameAndPositionMap agentNameAndPositionMap;
  103. std::map<AgentName, size_t> agentIndexMap;
  104. size_t numberOfPlayer;
  105. float const faultyProbability;
  106. float const probIntended;
  107. std::vector<Configuration> configuration;
  108. std::map<int, std::string> viewDirectionMapping;
  109. std::vector<ViewDirection> viewDirections = {0, 1, 2, 3};
  110. std::map<AgentName, std::set<std::pair<ActionId, std::string>>> agentNameActionMap;
  111. };
  112. }