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.

109 lines
6.3 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 bool enforceOneWays = false);
  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. std::ostream& printConstants(std::ostream &os, const std::vector<std::string> &constants);
  23. /*
  24. * Representation for Slippery Tile.
  25. * -) North: Slips from North to South
  26. * -) East: Slips from East to West
  27. * -) South: Slips from South to North
  28. * -) West: Slips from West to East
  29. */
  30. enum class SlipperyType { North, East, South, West };
  31. /*
  32. * Prints Slippery on move action.
  33. *
  34. * @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.
  35. * @param orientation: Information of slippery type (either north, south, east, west).
  36. */
  37. 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);
  38. /*
  39. * Prints Slippery on turn action.
  40. *
  41. * @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.
  42. * @param orientation: Information of slippery type (either north, south, east, west).
  43. */
  44. 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);
  45. std::ostream& printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  46. std::ostream& printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  47. std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  48. std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  49. std::ostream& printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType);
  50. std::ostream& printModule(std::ostream &os,
  51. const AgentName &agentName,
  52. const size_t &agentIndex,
  53. const coordinates &boundaries,
  54. const coordinates& initialPosition,
  55. const cells &keys,
  56. const std::map<Color, cells> &backgroundTiles,
  57. const bool agentWithView,
  58. const std::vector<float> &probabilities = {},
  59. const double faultyProbability = 0);
  60. 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);
  61. std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex);
  62. std::ostream& printEndmodule(std::ostream &os);
  63. std::ostream& printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities = {}, const std::set<std::string> &slipperyActions = {});
  64. std::ostream& printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer);
  65. 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);
  66. std::ostream& printConfiguration(std::ostream &os, const std::vector<Configuration>& configurations);
  67. std::ostream& printConfiguredActions(std::ostream &os, const AgentName &agentName);
  68. std::string moveGuard(const size_t &agentIndex);
  69. std::string pickupGuard(const AgentName &agentName, const std::string keyColor);
  70. std::string dropGuard(const AgentName &agentName, const std::string keyColor, size_t view);
  71. std::string moveUpdate(const size_t &agentIndex);
  72. std::string viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView);
  73. bool isGame() const;
  74. private:
  75. std::ostream &os;
  76. std::stringstream actionStream;
  77. ModelType const& modelType;
  78. coordinates const& maxBoundaries;
  79. AgentName agentName;
  80. cells boxes;
  81. cells balls;
  82. cells lockedDoors;
  83. cells unlockedDoors;
  84. cells keys;
  85. AgentNameAndPositionMap agentNameAndPositionMap;
  86. size_t numberOfPlayer;
  87. bool enforceOneWays;
  88. std::vector<Configuration> configuration;
  89. std::map<int, std::string> viewDirectionMapping;
  90. };
  91. }