Project Malmo  0.37.0
ALEAgentHost.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 _ALEAGENTHOST_H_
21 #define _ALEAGENTHOST_H_
22 
23 // Local:
24 #include "ArgumentParser.h"
25 #include "ClientConnection.h"
26 #include "ClientPool.h"
27 #include "MissionInitSpec.h"
28 #include "MissionRecord.h"
29 #include "MissionSpec.h"
30 #include "StringServer.h"
31 #include "VideoServer.h"
32 #include "WorldState.h"
33 #include "AgentHost.h"
34 
35 // Boost:
36 #include <boost/thread.hpp>
37 
38 // STL:
39 #include <string>
40 
41 class ALEInterface;
42 
43 namespace malmo
44 {
47  {
48  public:
51 
54 
57  void setSeed(int seed) { this->seed = seed; }
58 
65  void startMission( const MissionSpec& mission, const ClientPool& client_pool, const MissionRecordSpec& mission_record, int role, std::string unique_experiment_id );
66 
70  void startMission(const MissionSpec& mission, const MissionRecordSpec& mission_record);
71 
75 
79 
82  std::string getRecordingTemporaryDirectory() const;
83 
87 
91 
95 
99  void sendCommand(std::string command);
100 
101  void close();
102  friend std::ostream& operator<<(std::ostream& os, const ALEAgentHost& ah);
103 
104  private:
105  void initialize(const MissionSpec& mission, const MissionRecordSpec& mission_record, int role, std::string unique_experiment_id);
106 
107  void onVideo(TimestampedVideoFrame message);
108  void onReward(boost::posix_time::ptime ts, float reward);
109  void onObservation(TimestampedString message);
110 
111  AgentHost::VideoPolicy video_policy;
112  AgentHost::RewardsPolicy rewards_policy;
113  AgentHost::ObservationsPolicy observations_policy;
114 
115  WorldState world_state;
116  boost::shared_ptr<ALEInterface> ale_interface;
117  std::unique_ptr<VideoFrameWriter> video_frame_writer;
118 
119  mutable boost::mutex world_state_mutex;
120 
121  boost::shared_ptr<MissionRecord> current_mission_record;
122  int current_role;
123  int requested_width;
124  int requested_height;
125  std::ofstream commands_stream;
126  std::ofstream reward_stream;
127  int seed;
128  };
129 }
130 
131 #endif
An ALE agent host mediates between the researcher's code (the agent) and the ALE (the target environm...
Definition: ALEAgentHost.h:47
void setRewardsPolicy(AgentHost::RewardsPolicy rewardsPolicy)
Specifies how you want to deal with multiple rewards.
~ALEAgentHost()
Destructor.
void sendCommand(std::string command)
Sends a command to the game client.
ALEAgentHost()
Creates an agent host with default settings.
void startMission(const MissionSpec &mission, const MissionRecordSpec &mission_record)
Starts a mission running, in the simple case where there is only one agent running on the local machi...
WorldState peekWorldState() const
Gets the latest world state received from the game.
void setSeed(int seed)
Set the random seed used to seed the ALE.
Definition: ALEAgentHost.h:57
WorldState getWorldState()
Gets the latest world state received from the game.
void setVideoPolicy(AgentHost::VideoPolicy videoPolicy)
Specifies how you want to deal with multiple video frames.
std::string getRecordingTemporaryDirectory() const
Gets the temporary directory being used for the mission record, if recording is taking place.
void startMission(const MissionSpec &mission, const ClientPool &client_pool, const MissionRecordSpec &mission_record, int role, std::string unique_experiment_id)
Starts a mission running.
void setObservationsPolicy(AgentHost::ObservationsPolicy observationsPolicy)
Specifies how you want to deal with multiple observations.
RewardsPolicy
Specifies what to do when there are more rewards being received than can be processed.
Definition: AgentHost.h:87
VideoPolicy
Specifies what to do when there are more video frames being received than can be processed.
Definition: AgentHost.h:81
ObservationsPolicy
Specifies what to do when there are more observations being received than can be processed.
Definition: AgentHost.h:94
A general purpose command-line argument parser.
Definition: ArgumentParser.h:34
Specifies a mission to be run.
Definition: MissionSpec.h:37
A pool of expected network locations of Mod clients.
Definition: ClientPool.h:34
Specifies the type of data that should be recorded from the mission.
Definition: MissionRecordSpec.h:42
A string with an attached timestamp saying when it was collected.
Definition: TimestampedString.h:36
An image with an attached timestamp saying when it was collected.
Definition: TimestampedVideoFrame.h:36
Represents the state of the game world at a moment in time.
Definition: WorldState.h:35