Skip to content

Commit

Permalink
Merge pull request #558 from Microsoft/newMC
Browse files Browse the repository at this point in the history
Update to newer version of Minecraft
  • Loading branch information
DaveyBiggers authored Jun 20, 2017
2 parents 3a26656 + 352c595 commit b246ca3
Show file tree
Hide file tree
Showing 89 changed files with 1,652 additions and 775 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ project( Malmo )
# -------------------- Options --------------------------------

set( MALMO_VERSION_MAJOR 0)
set( MALMO_VERSION_MINOR 22)
set( MALMO_VERSION_MINOR 30)
set( MALMO_VERSION_REVISION 0)
set( MALMO_VERSION ${MALMO_VERSION_MAJOR}.${MALMO_VERSION_MINOR}.${MALMO_VERSION_REVISION} )
# N.B. Check that this version number matches the ones in the schemas.
Expand Down
5 changes: 4 additions & 1 deletion Malmo/samples/Python_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
set( SOURCES
animation_test.py
build_test.py
cart_test.py
chat_reward.py
chunk_test.py
craft_work.py
Expand Down Expand Up @@ -79,6 +78,10 @@ set( MULTI_AGENT_TESTS
set( OTHER_FILES
tutorial_6.xml
Tutorial.pdf
note_block_test.py # Currently no way to test audio
cart_test.py # Currently unreliable
mob_zoo.py # Currently unreliable
block_type_test.py # WIP
)

install( FILES ${SOURCES} ${MULTI_AGENT_TESTS} ${OTHER_FILES} DESTINATION Python_Examples )
Expand Down
180 changes: 180 additions & 0 deletions Malmo/samples/Python_examples/block_type_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# ------------------------------------------------------------------------------------------------
# Copyright (c) 2016 Microsoft Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------------------------

# Work in progress: this will eventually be a test of Malmo's support for all block types.

import MalmoPython
import os
import sys
import time
import json
import copy
import errno
import xml.etree.ElementTree as ET

# Parse schema to collect all block types.
# First find the schema file:
schema_dir = None
try:
schema_dir = os.environ['MALMO_XSD_PATH']
except KeyError:
print "MALMO_XSD_PATH not set? Check environment."
exit(1)
types_xsd = schema_dir + os.sep + "Types.xsd"

# Now try to parse it:
types_tree = None
try:
types_tree = ET.parse(types_xsd)
except (ET.ParseError, IOError):
print "Could not find or parse Types.xsd - check Malmo installation."
exit(1)

# Find the BlockType element:
root = types_tree.getroot()
block_types_element = root.find("*[@name='BlockType']")
if block_types_element == None:
print "Could not find block types in Types.xsd - file corruption?"
exit(1)

# Find the enum inside the BlockType element:
block_types_enum = block_types_element.find("*[@base]")
if block_types_enum == None:
print "Unexpected schema format. Did the format get changed without this test getting updated?"
exit(1)

# Now make a list of block types:
block_types = [block.get("value") for block in block_types_enum]

def getMissionXML(block_types):
forceReset = '"true"'
structureXML = "<DrawingDecorator>"
for i, b in enumerate(block_types):
structureXML += '<DrawBlock x="{}" y="{}" z="{}" type="{}" />'.format(i % 10, 3, i / 10, b)
structureXML += "</DrawingDecorator>"
startpos=(-2, 10, -2)

return '''<?xml version="1.0" encoding="UTF-8" ?>
<Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<About>
<Summary>Block Test</Summary>
</About>
<ServerSection>
<ServerHandlers>
<FlatWorldGenerator generatorString="3;7,2*3,2;12;" forceReset=''' + forceReset + '''/>''' + structureXML + '''
<ServerQuitWhenAnyAgentFinishes />
</ServerHandlers>
</ServerSection>
<AgentSection mode="Survival">
<Name>Blocky</Name>
<AgentStart>
<Placement x="''' + str(startpos[0] + 0.5) + '''" y="''' + str(startpos[1] + 1) + '''" z="''' + str(startpos[2] + 0.5) + '''" pitch="90"/>
</AgentStart>
<AgentHandlers>
<MissionQuitCommands />
<ObservationFromFullStats/>
<ObservationFromGrid>
<Grid name="all_the_blocks" absoluteCoords="true">
<min x="0" y="3" z="0"/>
<max x="9" y="3" z="30"/>
</Grid>
</ObservationFromGrid>
<VideoProducer viewpoint="1">
<Width>860</Width>
<Height>480</Height>
</VideoProducer>
</AgentHandlers>
</AgentSection>
</Mission>'''

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # flush print output immediately

agent_host = MalmoPython.AgentHost()
agent_host.addOptionalStringArgument( "recordingDir,r", "Path to location for saving mission recordings", "" )
try:
agent_host.parse( sys.argv )
except RuntimeError as e:
print 'ERROR:',e
print agent_host.getUsage()
exit(1)
if agent_host.receivedArgument("help"):
print agent_host.getUsage()
exit(0)

num_iterations = 30000
if agent_host.receivedArgument("test"):
num_iterations = 10

recording = False
my_mission_record = MalmoPython.MissionRecordSpec()
recordingsDirectory = agent_host.getStringArgument("recordingDir")
if len(recordingsDirectory) > 0:
recording = True
try:
os.makedirs(recordingsDirectory)
except OSError as exception:
if exception.errno != errno.EEXIST: # ignore error if already existed
raise
my_mission_record.recordRewards()
my_mission_record.recordObservations()
my_mission_record.recordCommands()
my_mission_record.recordMP4(24,2000000)

for i in xrange(num_iterations):
missionXML = getMissionXML(block_types)
if recording:
my_mission_record.setDestination(recordingsDirectory + "//" + "Mission_" + str(i+1) + ".tgz")
my_mission = MalmoPython.MissionSpec(missionXML, True)

max_retries = 3
for retry in range(max_retries):
try:
agent_host.startMission( my_mission, my_mission_record )
break
except RuntimeError as e:
if retry == max_retries - 1:
print "Error starting mission:",e
exit(1)
else:
time.sleep(2)

world_state = agent_host.getWorldState()
while not world_state.has_mission_begun:
sys.stdout.write(".")
time.sleep(0.1)
world_state = agent_host.getWorldState()
print

# main loop:
while world_state.is_mission_running:
if world_state.number_of_observations_since_last_state > 0:
msg = world_state.observations[-1].text
ob = json.loads(msg)
if "all_the_blocks" in ob:
blocks = ob["all_the_blocks"]
missing_blocks = [b for b in block_types if not b in blocks]
if len(missing_blocks) > 0:
print "MISSING:"
for b in missing_blocks:
print b,
print
world_state = agent_host.getWorldState()
4 changes: 2 additions & 2 deletions Malmo/samples/Python_examples/cart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ def calcYawToMob(entities, x, y, z):
''' + drawHilbert(4,16,34,16) + '''
<!-- Give the player a Minecart -->
<DrawEntity x="18.5" y="56" z="20.5" type="Minecart"/>
<DrawEntity x="18.5" y="56" z="20.5" type="MinecartRideable"/>
<!-- And something amusing to follow -->
<DrawEntity x="20.5" y="56" z="16.5" xVel="0" yVel="0" zVel="-1" type="Minecart"/>
<DrawEntity x="20.5" y="56" z="16.5" xVel="0" yVel="0" zVel="-1" type="MinecartRideable"/>
<DrawEntity x="20.5" y="56" z="16.5" type="''' + MOB_TYPE + '''"/>
</DrawingDecorator>''' + timeoutCondition + '''
<ServerQuitWhenAnyAgentFinishes />
Expand Down
2 changes: 2 additions & 0 deletions Malmo/samples/Python_examples/hit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def getMissionXML(summary):
<StartTime>1000</StartTime>
<AllowPassageOfTime>true</AllowPassageOfTime>
</Time>
<AllowSpawning>true</AllowSpawning>
<AllowedMobs>Pig Sheep</AllowedMobs>
</ServerInitialConditions>
<ServerHandlers>
<FlatWorldGenerator generatorString="3;7,202*1,5*3,2;3;,biome_1" />
Expand Down
2 changes: 2 additions & 0 deletions Malmo/samples/Python_examples/mob_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def getMissionXML(summary):
<StartTime>13000</StartTime>
<AllowPassageOfTime>false</AllowPassageOfTime>
</Time>
<AllowSpawning>true</AllowSpawning>
<AllowedMobs>''' + MOB_TYPE + '''</AllowedMobs>
</ServerInitialConditions>
<ServerHandlers>
<FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
Expand Down
Loading

0 comments on commit b246ca3

Please sign in to comment.