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.7 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 printTurningActionsForRobot(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& printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  48. std::ostream& printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  49. std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  50. std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  51. std::ostream& printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType);
  52. std::ostream& printModule(std::ostream &os,
  53. const AgentName &agentName,
  54. const size_t &agentIndex,
  55. const coordinates &boundaries,
  56. const coordinates& initialPosition,
  57. const cells &keys,
  58. const std::map<Color, cells> &backgroundTiles,
  59. const bool agentWithView,
  60. const std::vector<float> &probabilities = {},
  61. const double faultyProbability = 0);
  62. 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);
  63. std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName);
  64. std::ostream& printEndmodule(std::ostream &os);
  65. std::ostream& printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities = {}, const std::set<std::string> &slipperyActions = {});
  66. std::ostream& printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer);
  67. 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);
  68. std::ostream& printConfiguration(std::ostream &os, const std::vector<Configuration>& configurations);
  69. std::ostream& printConfiguredActions(std::ostream &os, const AgentName &agentName);
  70. std::string moveGuard(const AgentName &agentName);
  71. std::string pickupGuard(const AgentName &agentName, const std::string keyColor);
  72. std::string dropGuard(const AgentName &agentName, const std::string keyColor, size_t view);
  73. std::string moveUpdate(const AgentName &agentName);
  74. std::string viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView = true);
  75. bool isGame() const;
  76. private:
  77. std::string printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection);
  78. std::string printMovementUpdate(const AgentName &a, const std::string &update);
  79. std::ostream &os;
  80. std::stringstream actionStream;
  81. ModelType const &modelType;
  82. coordinates const &maxBoundaries;
  83. AgentName agentName;
  84. cells boxes;
  85. cells balls;
  86. cells lockedDoors;
  87. cells unlockedDoors;
  88. cells keys;
  89. AgentNameAndPositionMap agentNameAndPositionMap;
  90. std::map<AgentName, size_t> agentIndexMap;
  91. size_t numberOfPlayer;
  92. float const &faultyProbability;
  93. std::vector<Configuration> configuration;
  94. std::map<int, std::string> viewDirectionMapping;
  95. };
  96. }