Project Malmo  0.37.0
MissionSpec.h
1 // --------------------------------------------------------------------------------------------------
2 // Copyright (c) 2016 Microsoft Corporation
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5 // associated documentation files (the "Software"), to deal in the Software without restriction,
6 // including without limitation the rights to use, copy, modify, merge, publish, distribute,
7 // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all copies or
11 // substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14 // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 // --------------------------------------------------------------------------------------------------
19 
20 #ifndef _MISSIONSPEC_H_
21 #define _MISSIONSPEC_H_
22 
23 // Boost:
24 #include <boost/property_tree/ptree.hpp>
25 
26 // STL:
27 #include <string>
28 #include <vector>
29 
30 // Local:
31 #include "Logger.h"
32 
33 namespace malmo
34 {
37  {
38  MALMO_LOGGABLE_OBJECT(MissionSpec)
39  public:
40 
43 
47  MissionSpec(const std::string& xml, bool validate);
48 
52  std::string getAsXML( bool prettyPrint ) const;
53 
54  // -------------------- settings for the server -------------------------
55 
58  void setSummary( const std::string& summary );
59 
62  void timeLimitInSeconds(float s);
63 
67 
70  void setWorldSeed(const std::string& seed);
71 
75 
80  void setTimeOfDay(int t,bool allowTimeToPass);
81 
87  void drawBlock(int x, int y, int z, const std::string& blockType);
88 
97  void drawCuboid(int x1, int y1, int z1, int x2, int y2, int z2, const std::string& blockType);
98 
104  void drawItem(int x, int y, int z, const std::string& itemType);
105 
112  void drawSphere(int x, int y, int z, int radius, const std::string& blockType);
113 
122  void drawLine(int x1, int y1, int z1, int x2, int y2, int z2, const std::string& blockType);
123 
124  // -------------------- settings for the agents -------------------------
125 
131  void startAt(float x, float y, float z);
132 
140  void startAtWithPitchAndYaw(float x, float y, float z, float pitch, float yaw);
141 
149  void endAt(float x, float y, float z, float tolerance);
150 
153 
156 
162  void requestVideo(int width, int height);
163 
169  void requestLuminance(int width, int height);
170 
176  void requestColourMap(int width, int height);
177 
183  void request32bppDepth(int width, int height);
184 
190  void requestVideoWithDepth(int width, int height);
191 
194  void setViewpoint(int viewpoint);
195 
203  void rewardForReachingPosition(float x, float y, float z, float amount, float tolerance);
204 
209 
214 
219 
230  void observeGrid(int x1,int y1,int z1,int x2,int y2,int z2,const std::string& name);
231 
240  void observeDistance(float x,float y,float z,const std::string& name);
241 
243  void observeChat();
244 
247 
248  // -------------------- settings for the agents : command handlers -------------------------
249 
253 
257 
263  void allowContinuousMovementCommand(const std::string& verb);
264 
268 
274  void allowDiscreteMovementCommand(const std::string& verb);
275 
279 
285  void allowAbsoluteMovementCommand(const std::string& verb);
286 
290 
296  void allowInventoryCommand(const std::string& verb);
297 
301 
305 
306  // ------------------------- information --------------------------------------
307 
310  std::string getSummary() const;
311 
314  int getNumberOfAgents() const;
315 
319  bool isVideoRequested(int role) const;
320 
324  bool isDepthRequested(int role) const;
325 
329  bool isLuminanceRequested(int role) const;
330 
334  bool isColourMapRequested(int role) const;
335 
339  int getVideoWidth(int role) const;
340 
344  int getVideoHeight(int role) const;
345 
349  int getVideoChannels(int role) const;
350 
354  std::vector<std::string> getListOfCommandHandlers(int role) const;
355 
360  std::vector<std::string> getAllowedCommands(int role,const std::string& command_handler) const;
361 
367  int getChildCount(const std::string& element, const std::string& childName) const;
368 
369  friend std::ostream& operator<<(std::ostream& os, const MissionSpec& ms);
370  friend class MissionInitSpec;
371 
372  static const std::string XMLNS_XSI;
373  static const std::string MALMO_NAMESPACE;
374  private:
375 
376  boost::optional<int> getRoleValue(int role, std::string videoType, char what) const;
377  void addVerbToCommandType(std::string verb, std::string commandType);
378  void worldGeneratorReset();
379 
380  boost::property_tree::ptree& getDrawingDecorator();
381 
382  boost::property_tree::ptree mission;
383 
384  static const std::vector<std::string> all_continuous_movement_commands;
385  static const std::vector<std::string> all_absolute_movement_commands;
386  static const std::vector<std::string> all_discrete_movement_commands;
387  static const std::vector<std::string> all_inventory_commands;
388  static const std::vector<std::string> all_simplecraft_commands;
389  static const std::vector<std::string> all_nearbycraft_commands;
390  static const std::vector<std::string> all_nearbysmelt_commands;
391  static const std::vector<std::string> all_chat_commands;
392  static const std::vector<std::string> all_mission_quit_commands;
393  static const std::vector<std::string> all_human_level_commands;
394  };
395 }
396 
397 #endif
Specifies a mission to be run.
Definition: MissionSpec.h:37
void createDefaultTerrain()
Instead of the default flat world, make a world using Minecraft's terrain generator.
void allowAllAbsoluteMovementCommands()
Adds an absolute movement command handler if none present, with neither an allow-list or a deny-list,...
void drawBlock(int x, int y, int z, const std::string &blockType)
Draw a Minecraft block in the world.
void observeHotBar()
Asks for the contents of the player's hot-bar to be included in the observations.
MissionSpec()
Constructs a mission with default parameters: a flat world with a 10 seconds time limit and continuou...
void allowContinuousMovementCommand(const std::string &verb)
Adds an allow-list to the continuous movement command handler if none present.
void allowAllInventoryCommands()
Adds an inventory command handler if none present, with neither an allow-list or a deny-list,...
void endAt(float x, float y, float z, float tolerance)
Sets the end location for the agent.
void timeLimitInSeconds(float s)
Sets the time limit for the mission.
void startAtWithPitchAndYaw(float x, float y, float z, float pitch, float yaw)
Sets the start location and angles for the agent.
void drawSphere(int x, int y, int z, int radius, const std::string &blockType)
Draw a solid sphere of blocks in the world.
int getVideoHeight(int role) const
Returns the height of the requested video for one of the agents involved in this mission.
void observeDistance(float x, float y, float z, const std::string &name)
Asks for the Euclidean distance to a location to be included in the observations.
void setViewpoint(int viewpoint)
Sets the camera position.
void observeFullInventory()
Asks for the full item inventory of the player to be included in the observations.
void setModeToSpectator()
Sets the player mode for the agent to spectator, allowing them to fly and pass through objects....
void observeGrid(int x1, int y1, int z1, int x2, int y2, int z2, const std::string &name)
Asks for observations of the block types within a cuboid relative to the agent's position.
void requestLuminance(int width, int height)
Asks for 8bpp greyscale image data to be sent from Minecraft for the agent.
void setWorldSeed(const std::string &seed)
Set the seed used for Minecraft's terrain generation.
void setTimeOfDay(int t, bool allowTimeToPass)
Sets the time of day for the start of the mission.
void setSummary(const std::string &summary)
Sets the summary description of the mission.
void allowAllDiscreteMovementCommands()
Adds a discrete movement command handler if none present, with neither an allow-list or a deny-list,...
void allowDiscreteMovementCommand(const std::string &verb)
Adds an allow-list to the discrete movement command handler if none present.
MissionSpec(const std::string &xml, bool validate)
Constructs a mission from the supplied XML as specified here: Schemas/Mission.html
void allowAllPlaceCommands()
Adds a place command handler if none present, with neither an allow-list or a deny-list,...
void requestVideo(int width, int height)
Asks for image data to be sent from Minecraft for the agent.
bool isDepthRequested(int role) const
Gets whether depthmap video has been requested for one of the agents involved in this mission.
int getVideoWidth(int role) const
Returns the width of the requested video for one of the agents involved in this mission.
void allowAllContinuousMovementCommands()
Adds a continuous movement command handler if none present, with neither an allow-list or a deny-list...
std::vector< std::string > getAllowedCommands(int role, const std::string &command_handler) const
Returns a list of the names of the allowed commands for one of the agents involved in this mission.
void removeAllCommandHandlers()
Remove any existing command handlers from the mission specification.
void requestVideoWithDepth(int width, int height)
Asks for image data and depth data to be sent from Minecraft for the agent.
void drawLine(int x1, int y1, int z1, int x2, int y2, int z2, const std::string &blockType)
Draw a line of blocks in the world.
void allowAllChatCommands()
Adds a chat command handler if none present, with neither an allow-list or a deny-list,...
void observeChat()
Asks for chat messages to be included in the observations.
std::string getAsXML(bool prettyPrint) const
Gets the mission specification as an XML string.
void observeCompass()
Asks for compass information to be included in the observations.
void requestColourMap(int width, int height)
Asks for 24bpp colourmap image data to be sent from Minecraft for the agent.
int getChildCount(const std::string &element, const std::string &childName) const
Count the number of children with the given child name or -1 if no such element path is present.
void request32bppDepth(int width, int height)
Asks for 32bpp depth data to be sent from Minecraft for the agent.
int getVideoChannels(int role) const
Returns the number of channels in the requested video for one of the agents involved in this mission.
void rewardForReachingPosition(float x, float y, float z, float amount, float tolerance)
Asks for a reward to be sent to the agent when it reaches a certain position.
std::string getSummary() const
Returns the short description of the mission.
void startAt(float x, float y, float z)
Sets the start location for the agent.
void setModeToCreative()
Sets the player mode for the agent to creative, allowing them to fly and to not sustain damage....
void forceWorldReset()
Force Minecraft to reload the world rather than use the current one (if appropriate).
void allowAbsoluteMovementCommand(const std::string &verb)
Adds an allow-list to the absolute movement command handler if none present.
bool isLuminanceRequested(int role) const
Gets whether luminance video has been requested for one of the agents involved in this mission.
bool isColourMapRequested(int role) const
Gets whether colourmap video has been requested for one of the agents involved in this mission.
void drawItem(int x, int y, int z, const std::string &itemType)
Draw a Minecraft item in the world.
int getNumberOfAgents() const
Returns the number of agents involved in this mission.
void drawCuboid(int x1, int y1, int z1, int x2, int y2, int z2, const std::string &blockType)
Draw a solid cuboid in the world.
bool isVideoRequested(int role) const
Gets whether video has been requested for one of the agents involved in this mission.
void observeRecentCommands()
Asks for the list of commands acted upon since the last timestep to be returned in the observations.
void allowInventoryCommand(const std::string &verb)
Adds an allow-list to the inventory command handler if none present.
std::vector< std::string > getListOfCommandHandlers(int role) const
Returns a list of the names of the active command handlers for one of the agents involved in this mis...