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.

119 lines
8.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(const ModelType &modelType, const size_t &numberOfPlayer, std::vector<Configuration> config ,const bool enforceOneWays = false);
  11. std::ostream& printRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &grid_cells, const cells& keys, const cells& doors);
  12. std::ostream& printKeyRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &keys);
  13. std::ostream& printDoorRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &doors);
  14. std::ostream& printIsOnSlipperyFormula(std::ostream& os, const AgentName &agentName, const std::vector<std::reference_wrapper<cells>> &slipperyCollection, const cells &slipperyNorth, const cells &slipperyEast, const cells &slipperySouth, const cells &slipperyWest);
  15. std::ostream& printGoalLabel(std::ostream& os, const AgentName&agentName, const cells &goals);
  16. std::ostream& printCrashLabel(std::ostream &os, const std::vector<AgentName> agentNames);
  17. std::ostream& printAvoidanceLabel(std::ostream &os, const std::vector<AgentName> agentNames, const int &distance);
  18. std::ostream& printKeysLabels(std::ostream& os, const AgentName&agentName, const cells &keys);
  19. std::ostream& printBackgroundLabels(std::ostream &os, const AgentName &agentName, const std::pair<Color, cells> &backgroundTiles);
  20. std::ostream& printIsInLavaFormula(std::ostream& os, const AgentName &agentName, const cells &lava);
  21. std::ostream& printIsFixedFormulas(std::ostream& os, const AgentName &agentName);
  22. std::ostream& printTurningNotAllowedFormulas(std::ostream& os, const AgentName &agentName, const cells &floor);
  23. std::ostream& printWallFormula(std::ostream& os, const AgentName &agentName, const cells &walls);
  24. std::ostream& printFormulas(std::ostream& os,
  25. const AgentName&agentName,
  26. const cells &restrictionNorth,
  27. const cells &restrictionEast,
  28. const cells &restrictionSouth,
  29. const cells &restrictionWest,
  30. const std::vector<std::reference_wrapper<cells>> &slipperyCollection,
  31. const cells &lava,
  32. const cells &walls,
  33. const cells &noTurnFloor,
  34. const cells &slipperyNorth,
  35. const cells &slipperyEast,
  36. const cells &slipperySouth,
  37. const cells &slipperyWest,
  38. const cells &keys,
  39. const cells &doors);
  40. std::ostream& printKeyModule(std::ostream &os, const cell &key, const coordinates &boundaries, AgentName agentName);
  41. std::ostream& printKeyActions(std::ostream &os, const cell& key ,const std::string &keyIdentifier, AgentName agentName);
  42. std::ostream& printDoorModule(std::ostream &os, const cell &door, const coordinates &boundaries, AgentName agentName);
  43. std::ostream& printDoorActions(std::ostream &os, const cell &door ,const std::string &doorIdentifier, AgentName agentName);
  44. std::ostream& printConstants(std::ostream &os, const std::vector<std::string> &constants);
  45. /*
  46. * Representation for Slippery Tile.
  47. * -) North: Slips from North to South
  48. * -) East: Slips from East to West
  49. * -) South: Slips from South to North
  50. * -) West: Slips from West to East
  51. */
  52. enum class SlipperyType { North, East, South, West };
  53. /*
  54. * Prints Slippery on move action.
  55. *
  56. * @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.
  57. * @param orientation: Information of slippery type (either north, south, east, west).
  58. */
  59. 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);
  60. /*
  61. * Prints Slippery on turn action.
  62. *
  63. * @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.
  64. * @param orientation: Information of slippery type (either north, south, east, west).
  65. */
  66. 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);
  67. std::ostream& printModel(std::ostream &os, const ModelType &modelType);
  68. std::ostream& printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  69. std::ostream& printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys);
  70. std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  71. std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
  72. std::ostream& printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType);
  73. std::ostream& printModule(std::ostream &os,
  74. const AgentName &agentName,
  75. const size_t &agentIndex,
  76. const coordinates &boundaries,
  77. const coordinates& initialPosition,
  78. const cells &keys,
  79. const std::map<Color, cells> &backgroundTiles,
  80. const bool agentWithView,
  81. const std::vector<float> &probabilities = {},
  82. const double faultyProbability = 0);
  83. 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);
  84. std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex);
  85. std::ostream& printEndmodule(std::ostream &os);
  86. std::ostream& printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities = {}, const std::set<std::string> &slipperyActions = {});
  87. std::ostream& printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer);
  88. 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);
  89. std::ostream& printConfiguration(std::ostream &os, const std::vector<Configuration>& configurations);
  90. std::ostream& printConfiguredActions(std::ostream &os, const AgentName &agentName);
  91. std::string moveGuard(const size_t &agentIndex);
  92. std::string pickupGuard(const AgentName &agentName, const std::string keyColor);
  93. std::string dropGuard(const AgentName &agentName, const std::string keyColor, size_t view);
  94. std::string moveUpdate(const size_t &agentIndex);
  95. std::string unlockGuard(const AgentName &agentName, const cell& door);
  96. std::string toggleGuard(const AgentName &agentName, const cell& door);
  97. std::string viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView);
  98. bool isGame() const;
  99. private:
  100. ModelType const& modelType;
  101. const size_t numberOfPlayer;
  102. bool enforceOneWays;
  103. std::vector<Configuration> configuration;
  104. std::map<int, std::string> viewDirectionMapping;
  105. };
  106. }