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.

127 lines
7.0 KiB

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