Skip to content

Commit b246ca3

Browse files
authored
Merge pull request #558 from Microsoft/newMC
Update to newer version of Minecraft
2 parents 3a26656 + 352c595 commit b246ca3

File tree

89 files changed

+1652
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1652
-775
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ project( Malmo )
2424
# -------------------- Options --------------------------------
2525

2626
set( MALMO_VERSION_MAJOR 0)
27-
set( MALMO_VERSION_MINOR 22)
27+
set( MALMO_VERSION_MINOR 30)
2828
set( MALMO_VERSION_REVISION 0)
2929
set( MALMO_VERSION ${MALMO_VERSION_MAJOR}.${MALMO_VERSION_MINOR}.${MALMO_VERSION_REVISION} )
3030
# N.B. Check that this version number matches the ones in the schemas.

Malmo/samples/Python_examples/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
set( SOURCES
2121
animation_test.py
2222
build_test.py
23-
cart_test.py
2423
chat_reward.py
2524
chunk_test.py
2625
craft_work.py
@@ -79,6 +78,10 @@ set( MULTI_AGENT_TESTS
7978
set( OTHER_FILES
8079
tutorial_6.xml
8180
Tutorial.pdf
81+
note_block_test.py # Currently no way to test audio
82+
cart_test.py # Currently unreliable
83+
mob_zoo.py # Currently unreliable
84+
block_type_test.py # WIP
8285
)
8386

8487
install( FILES ${SOURCES} ${MULTI_AGENT_TESTS} ${OTHER_FILES} DESTINATION Python_Examples )
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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+
# Work in progress: this will eventually be a test of Malmo's support for all block types.
21+
22+
import MalmoPython
23+
import os
24+
import sys
25+
import time
26+
import json
27+
import copy
28+
import errno
29+
import xml.etree.ElementTree as ET
30+
31+
# Parse schema to collect all block types.
32+
# First find the schema file:
33+
schema_dir = None
34+
try:
35+
schema_dir = os.environ['MALMO_XSD_PATH']
36+
except KeyError:
37+
print "MALMO_XSD_PATH not set? Check environment."
38+
exit(1)
39+
types_xsd = schema_dir + os.sep + "Types.xsd"
40+
41+
# Now try to parse it:
42+
types_tree = None
43+
try:
44+
types_tree = ET.parse(types_xsd)
45+
except (ET.ParseError, IOError):
46+
print "Could not find or parse Types.xsd - check Malmo installation."
47+
exit(1)
48+
49+
# Find the BlockType element:
50+
root = types_tree.getroot()
51+
block_types_element = root.find("*[@name='BlockType']")
52+
if block_types_element == None:
53+
print "Could not find block types in Types.xsd - file corruption?"
54+
exit(1)
55+
56+
# Find the enum inside the BlockType element:
57+
block_types_enum = block_types_element.find("*[@base]")
58+
if block_types_enum == None:
59+
print "Unexpected schema format. Did the format get changed without this test getting updated?"
60+
exit(1)
61+
62+
# Now make a list of block types:
63+
block_types = [block.get("value") for block in block_types_enum]
64+
65+
def getMissionXML(block_types):
66+
forceReset = '"true"'
67+
structureXML = "<DrawingDecorator>"
68+
for i, b in enumerate(block_types):
69+
structureXML += '<DrawBlock x="{}" y="{}" z="{}" type="{}" />'.format(i % 10, 3, i / 10, b)
70+
structureXML += "</DrawingDecorator>"
71+
startpos=(-2, 10, -2)
72+
73+
return '''<?xml version="1.0" encoding="UTF-8" ?>
74+
<Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
75+
76+
<About>
77+
<Summary>Block Test</Summary>
78+
</About>
79+
80+
<ServerSection>
81+
<ServerHandlers>
82+
<FlatWorldGenerator generatorString="3;7,2*3,2;12;" forceReset=''' + forceReset + '''/>''' + structureXML + '''
83+
<ServerQuitWhenAnyAgentFinishes />
84+
</ServerHandlers>
85+
</ServerSection>
86+
87+
<AgentSection mode="Survival">
88+
<Name>Blocky</Name>
89+
<AgentStart>
90+
<Placement x="''' + str(startpos[0] + 0.5) + '''" y="''' + str(startpos[1] + 1) + '''" z="''' + str(startpos[2] + 0.5) + '''" pitch="90"/>
91+
</AgentStart>
92+
<AgentHandlers>
93+
<MissionQuitCommands />
94+
<ObservationFromFullStats/>
95+
<ObservationFromGrid>
96+
<Grid name="all_the_blocks" absoluteCoords="true">
97+
<min x="0" y="3" z="0"/>
98+
<max x="9" y="3" z="30"/>
99+
</Grid>
100+
</ObservationFromGrid>
101+
<VideoProducer viewpoint="1">
102+
<Width>860</Width>
103+
<Height>480</Height>
104+
</VideoProducer>
105+
</AgentHandlers>
106+
</AgentSection>
107+
</Mission>'''
108+
109+
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # flush print output immediately
110+
111+
agent_host = MalmoPython.AgentHost()
112+
agent_host.addOptionalStringArgument( "recordingDir,r", "Path to location for saving mission recordings", "" )
113+
try:
114+
agent_host.parse( sys.argv )
115+
except RuntimeError as e:
116+
print 'ERROR:',e
117+
print agent_host.getUsage()
118+
exit(1)
119+
if agent_host.receivedArgument("help"):
120+
print agent_host.getUsage()
121+
exit(0)
122+
123+
num_iterations = 30000
124+
if agent_host.receivedArgument("test"):
125+
num_iterations = 10
126+
127+
recording = False
128+
my_mission_record = MalmoPython.MissionRecordSpec()
129+
recordingsDirectory = agent_host.getStringArgument("recordingDir")
130+
if len(recordingsDirectory) > 0:
131+
recording = True
132+
try:
133+
os.makedirs(recordingsDirectory)
134+
except OSError as exception:
135+
if exception.errno != errno.EEXIST: # ignore error if already existed
136+
raise
137+
my_mission_record.recordRewards()
138+
my_mission_record.recordObservations()
139+
my_mission_record.recordCommands()
140+
my_mission_record.recordMP4(24,2000000)
141+
142+
for i in xrange(num_iterations):
143+
missionXML = getMissionXML(block_types)
144+
if recording:
145+
my_mission_record.setDestination(recordingsDirectory + "//" + "Mission_" + str(i+1) + ".tgz")
146+
my_mission = MalmoPython.MissionSpec(missionXML, True)
147+
148+
max_retries = 3
149+
for retry in range(max_retries):
150+
try:
151+
agent_host.startMission( my_mission, my_mission_record )
152+
break
153+
except RuntimeError as e:
154+
if retry == max_retries - 1:
155+
print "Error starting mission:",e
156+
exit(1)
157+
else:
158+
time.sleep(2)
159+
160+
world_state = agent_host.getWorldState()
161+
while not world_state.has_mission_begun:
162+
sys.stdout.write(".")
163+
time.sleep(0.1)
164+
world_state = agent_host.getWorldState()
165+
print
166+
167+
# main loop:
168+
while world_state.is_mission_running:
169+
if world_state.number_of_observations_since_last_state > 0:
170+
msg = world_state.observations[-1].text
171+
ob = json.loads(msg)
172+
if "all_the_blocks" in ob:
173+
blocks = ob["all_the_blocks"]
174+
missing_blocks = [b for b in block_types if not b in blocks]
175+
if len(missing_blocks) > 0:
176+
print "MISSING:"
177+
for b in missing_blocks:
178+
print b,
179+
print
180+
world_state = agent_host.getWorldState()

Malmo/samples/Python_examples/cart_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ def calcYawToMob(entities, x, y, z):
297297
''' + drawHilbert(4,16,34,16) + '''
298298
299299
<!-- Give the player a Minecart -->
300-
<DrawEntity x="18.5" y="56" z="20.5" type="Minecart"/>
300+
<DrawEntity x="18.5" y="56" z="20.5" type="MinecartRideable"/>
301301
302302
<!-- And something amusing to follow -->
303-
<DrawEntity x="20.5" y="56" z="16.5" xVel="0" yVel="0" zVel="-1" type="Minecart"/>
303+
<DrawEntity x="20.5" y="56" z="16.5" xVel="0" yVel="0" zVel="-1" type="MinecartRideable"/>
304304
<DrawEntity x="20.5" y="56" z="16.5" type="''' + MOB_TYPE + '''"/>
305305
</DrawingDecorator>''' + timeoutCondition + '''
306306
<ServerQuitWhenAnyAgentFinishes />

Malmo/samples/Python_examples/hit_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def getMissionXML(summary):
7070
<StartTime>1000</StartTime>
7171
<AllowPassageOfTime>true</AllowPassageOfTime>
7272
</Time>
73+
<AllowSpawning>true</AllowSpawning>
74+
<AllowedMobs>Pig Sheep</AllowedMobs>
7375
</ServerInitialConditions>
7476
<ServerHandlers>
7577
<FlatWorldGenerator generatorString="3;7,202*1,5*3,2;3;,biome_1" />

Malmo/samples/Python_examples/mob_fun.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def getMissionXML(summary):
9292
<StartTime>13000</StartTime>
9393
<AllowPassageOfTime>false</AllowPassageOfTime>
9494
</Time>
95+
<AllowSpawning>true</AllowSpawning>
96+
<AllowedMobs>''' + MOB_TYPE + '''</AllowedMobs>
9597
</ServerInitialConditions>
9698
<ServerHandlers>
9799
<FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />

0 commit comments

Comments
 (0)