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.

117 lines
6.6 KiB

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