Repository navigation
Expand file tree
/
Copy pathExpMalmoMeca1b.java
More file actions
122 lines (110 loc) 路 4.32 KB
/
Copy pathExpMalmoMeca1b.java
File metadata and controls
122 lines (110 loc) 路 4.32 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
/*
* 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 expmalmomeca1b;
import com.microsoft.msr.malmo.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author carol
*/
public class ExpMalmoMeca1b {
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
AgentHost agent_host = new AgentHost(); //Criar agente
try {
StringVector args = new StringVector();
//args.add("JavaExamples_run_mission");
args.add("ExpMalmoMeca1b");
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 = new MissionSpec();
MissionRecordSpec my_mission_record = new MissionRecordSpec();
my_mission.setSummary("Primeiro Experimento de Miss茫o");
//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(ExpMalmoMeca1.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(ExpMalmoMeca1b.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
}
}