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.

110 lines
7.9 KiB

  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, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities = {});
  74. std::ostream& printMovementActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const bool agentWithView, const float &probability = 1.0);
  75. std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex);
  76. std::ostream& printEndmodule(std::ostream &os);
  77. std::ostream& printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities = {}, const std::set<std::string> &slipperyActions = {});
  78. std::ostream& printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer);
  79. 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);
  80. std::ostream& printConfiguration(std::ostream &os, const std::vector<Configuration>& configurations);
  81. std::ostream& printConfiguredActions(std::ostream &os, const AgentName &agentName);
  82. std::string moveGuard(const size_t &agentIndex);
  83. std::string pickupGuard(const AgentName &agentName, const std::string keyColor);
  84. std::string dropGuard(const AgentName &agentName, const std::string keyColor, size_t view);
  85. std::string moveUpdate(const size_t &agentIndex);
  86. std::string unlockGuard(const AgentName &agentName, const cell& door);
  87. std::string toggleGuard(const AgentName &agentName, const cell& door);
  88. std::string viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView);
  89. bool isGame() const;
  90. private:
  91. ModelType const& modelType;
  92. const size_t numberOfPlayer;
  93. bool enforceOneWays;
  94. std::vector<Configuration> configuration;
  95. std::map<int, std::string> viewDirectionMapping;
  96. };
  97. }