Repository navigation
Expand file tree
/
Copy pathExpMalmoMeca2.java
More file actions
177 lines (158 loc) · 7.2 KB
/
Copy pathExpMalmoMeca2.java
File metadata and controls
177 lines (158 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package expmalmomeca1;
import com.microsoft.msr.malmo.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author carol
*/
public class ExpMalmoMeca2 {
static
{
System.loadLibrary("MalmoJava"); // attempts to load MalmoJava.dll (on Windows) or libMalmoJava.so (on Linux)
}
/**
* @param argv the command line arguments
*/
////public static void main(String argv[])
////public static void main(String[] args) {
public static void main(String argv[]){
// TODO code application logic here
//XML da missão
String missionXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalon=\"no\" ?>"
+"<Mission xmlns=\"http://ProjectMalmo.microsoft.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+"<About><Summary>Hello World in Java!</Summary></About>"
+"<ServerSection>"
+"<ServerInitialConditions>"
+"<Time><StartTime>12000</StartTime><AllowPassageOfTime>false</AllowPassageOfTime></Time>"
+"<Weather>rain</Weather>"
+"</ServerInitialConditions>"
+"<ServerHandlers>"
+"<FlatWorldGenerator generatorString=\"3;7,44*49,73,35:1,159:4,95:13,35:13,159:11,95:10,159:14,159:6,35:6,95:6;12;\"/>"
+"<DrawingDecorator><DrawBlock x=\"-27\" y=\"70\" z=\"0\" type=\"air\"/></DrawingDecorator>"
+"<ServerQuitFromTimeUp timeLimitMs=\"30000\"/>"
+"<ServerQuitWhenAnyAgentFinishes/>"
+"</ServerHandlers>"
+"</ServerSection>"
+"<AgentSection mode=\"Survival\">"
+"<Name>MalmoTutorialBot</Name>"
+"<AgentStart>"
+"<Placement x=\"0\" y=\"56\" z=\"0\" yaw=\"90\"/>"
+"<Inventory><InventoryItem slot=\"0\" type=\"diamond_pickaxe\"/></Inventory>"
+"</AgentStart>"
+"<AgentHandlers>"
+"<ObservationFromFullStats/>"
+"<ContinuousMovementCommands turnSpeedDegs=\"180\"/>"
+"</AgentHandlers>"
+"</AgentSection>"
+"</Mission>";
AgentHost agent_host = new AgentHost(); //Criar agente
try {
StringVector args = new StringVector();
//args.add("JavaExamples_run_mission");
args.add("ExpMalmoMeca2");
for( String arg : argv )
args.add( arg );
agent_host.parse( args );
}
catch( Exception e ) {
System.err.println( "ERROR: " + e.getMessage() );
System.err.println( agent_host.getUsage() );
System.exit(1);
}
if( agent_host.receivedArgument("help") ) {
System.out.println( agent_host.getUsage() );
System.exit(0);
}
MissionSpec my_mission;
try {
my_mission = new MissionSpec(missionXML, true);
MissionRecordSpec my_mission_record = new MissionRecordSpec();
my_mission.setSummary("Primeiro Experimento de Missão");
try {
agent_host.startMission( my_mission, my_mission_record );
}
catch (MissionException e) {
System.err.println( "Error starting mission: " + e.getMessage() );
System.err.println( "Error code: " + e.getMissionErrorCode() );
// We can use the code to do specific error handling, eg:
if (e.getMissionErrorCode() == MissionException.MissionErrorCode.MISSION_INSUFFICIENT_CLIENTS_AVAILABLE)
{
// Caused by lack of available Minecraft clients.
System.err.println( "Is there a Minecraft client running?");
}
System.exit(1);
}
} catch (Exception ex) {
Logger.getLogger(ExpMalmoMeca2.class.getName()).log(Level.SEVERE, null, ex);
}
//MissionRecordSpec my_mission_record = new MissionRecordSpec();
//my_mission.timeLimitInSeconds(60);
//Definindo Missão
//Attempt to start a mission:
/*try {
agent_host.startMission( my_mission, my_mission_record );
}
catch (MissionException e) {
System.err.println( "Error starting mission: " + e.getMessage() );
System.err.println( "Error code: " + e.getMissionErrorCode() );
// We can use the code to do specific error handling, eg:
if (e.getMissionErrorCode() == MissionException.MissionErrorCode.MISSION_INSUFFICIENT_CLIENTS_AVAILABLE)
{
// Caused by lack of available Minecraft clients.
System.err.println( "Is there a Minecraft client running?");
}
System.exit(1);
}*/
//Loop until mission starts:
WorldState world_state;
System.out.print( "Waiting for the mission to start" );
do {
System.out.print( "." );
try {
Thread.sleep(10);
} catch(InterruptedException ex) {
System.err.println( "User interrupted while waiting for mission to start." );
return;
}
world_state = agent_host.getWorldState();
for( int i = 0; i < world_state.getErrors().size(); i++ )
System.err.println( "Error: " + world_state.getErrors().get(i).getText() );
} while( !world_state.getIsMissionRunning() );
System.out.println( "" );
System.out.println( "Mission running" );
//Commands
agent_host.sendCommand("move 1");
agent_host.sendCommand("turn -0.5");
agent_host.sendCommand("jump 1");
agent_host.sendCommand("pitch 1");
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(ExpMalmoMeca2.class.getName()).log(Level.SEVERE, null, ex);
}
agent_host.sendCommand("attack 1");
//Commands End
//Loop until mission ends:
do {
try {
Thread.sleep((long) 0.1);
} catch (InterruptedException ex) {
Logger.getLogger(ExpMalmoMeca2.class.getName()).log(Level.SEVERE, null, ex);
}
world_state = agent_host.getWorldState();
for( int i = 0; i < world_state.getErrors().size(); i++ ) {
TimestampedString error = world_state.getErrors().get(i);
System.err.println( "Error: " + error.getText() );
}
} while( world_state.getIsMissionRunning() );
System.out.println( "Mission ended" );
//Mission has ended.
//END
}
}