Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8fae8be
Readded craft handlers and slight changes to argument
ccodel Oct 31, 2018
8d5f166
Reimplemented craft, collect handlers, added possess handler with dec…
ccodel Dec 6, 2018
230f49b
Added smelting reward and quit handlers
ccodel Feb 6, 2019
f1cf5d6
Bulk of implementation done, onto testing
ccodel Feb 9, 2019
c532889
Updated smelting to call matcher once every four now
ccodel Feb 9, 2019
74d89b3
Merge branch 'master' into craftEdits
brandonhoughton Feb 10, 2019
8d84d9b
Implemented nearby handlers, with lots of trig
ccodel Feb 13, 2019
4abdbca
Added some other files I guess
ccodel Feb 13, 2019
e60eb60
One more too
ccodel Feb 13, 2019
3ee2052
Fixed merge issues
ccodel Feb 13, 2019
40d3724
Updating agent host.
MadcowD Feb 18, 2019
553ca51
Fix bug with navigate teleport
eambutu Feb 19, 2019
3afbd41
Added place commands, not yet tested
ccodel Feb 20, 2019
c9c9e33
Swapped items back
ccodel Feb 20, 2019
b88a7eb
Updatting fixe.
MadcowD Feb 20, 2019
0321078
Fix from teleport check to spawn change check
eambutu Feb 20, 2019
a12f533
Updated commands for cayden's new handlers
brandonhoughton Feb 22, 2019
f815035
Merged master into craft edits
brandonhoughton Feb 22, 2019
60e4ea6
Reimplemented craft, collect handlers, added possess handler with dec…
ccodel Dec 6, 2018
f5776ac
Added smelting reward and quit handlers
ccodel Feb 6, 2019
2797851
Bulk of implementation done, onto testing
ccodel Feb 9, 2019
6c8586f
Updated smelting to call matcher once every four now
ccodel Feb 9, 2019
3b16457
Implemented nearby handlers, with lots of trig
ccodel Feb 13, 2019
353bf5c
Merged version changes
brandonhoughton Feb 22, 2019
222c084
Added place commands, not yet tested
ccodel Feb 20, 2019
a394b7f
Swapped items back
ccodel Feb 20, 2019
6da0907
Updated commands for cayden's new handlers
brandonhoughton Feb 22, 2019
af08f90
Merge branch 'craftEdits' of github.com:cmu-rl/malmo into craftEdits
brandonhoughton Feb 22, 2019
6c54ed2
Correct small isues with command naming
brandonhoughton Feb 22, 2019
36e611c
Fix API
brandonhoughton Feb 22, 2019
a4500e3
Fix api integration
brandonhoughton Feb 22, 2019
96ab4d6
Update value of craft and smelt nearby command
brandonhoughton Feb 22, 2019
bbdc0d4
Add new commands to python api =(
brandonhoughton Feb 22, 2019
8c2cb18
Revert testing change
brandonhoughton Feb 22, 2019
b2c5f93
Skrew the API
brandonhoughton Feb 22, 2019
89680e7
Java != Python
brandonhoughton Feb 22, 2019
3df3ebb
Made things strictly better
brandonhoughton Feb 22, 2019
7a901e9
Dont do silly things
brandonhoughton Feb 22, 2019
d284fdb
Make new messeges to pass to cute squirrels
brandonhoughton Feb 23, 2019
04a3c26
Likely need a new channel for each message
brandonhoughton Feb 23, 2019
b188b83
Check for non-existant items
brandonhoughton Feb 23, 2019
5a8de6b
Updated place logic
ccodel Feb 28, 2019
d2bf899
Some little changes regarding Forge events, testing, making new branc…
ccodel Mar 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ ClientBin/
*.pfx
*.publishsettings
node_modules/
.DS_Store

# RIA/Silverlight projects
Generated_Code/
Expand Down
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ set( STATIC_BOOST ON CACHE BOOL ${STATIC_BOOST_DESC} )

if( INCLUDE_PYTHON )
set( USE_PYTHON_VERSIONS_DESC "Specifies which version of Python to build Malmo with Python bindings" )
set( MACOS_USE_PYTHON_MODULE_DESC "Specifies which Python module to build Malmo on Apple MacOS" )
set( USE_PYTHON_VERSIONS 3.6 CACHE STRING ${USE_PYTHON_VERSIONS_DESC} )
set( BOOST_PYTHON_NAME_DESC "Specifies which Boost Python module to build Malmo with" )
set( BOOST_PYTHON_NAME "python3" CACHE STRING ${BOOST_PYTHON_NAME_DESC} )
# Boost has switched to using a 2 digit naming convention for python on MacOS.
set( MACOS_USE_PYTHON_MODULE "python37" CACHE STRING ${MACOS_USE_PYTHON_MODULE_DESC} )
endif()

set( WARNINGS_AS_ERRORS OFF )
Expand Down Expand Up @@ -105,18 +106,21 @@ SET(Boost_ADDITIONAL_VERSIONS "1.67" "1.67.0")

SET(BOOST_PYTHON_MODULE_NAME "python")
if ( USE_PYTHON_VERSIONS VERSION_GREATER 3 )
SET( BOOST_PYTHON_MODULE_NAME ${BOOST_PYTHON_NAME} )
if ( APPLE )
SET( BOOST_PYTHON_MODULE_NAME ${MACOS_USE_PYTHON_MODULE} )
else()
SET( BOOST_PYTHON_MODULE_NAME "python3" )
endif()
endif()

if( WIN32 )
SET(Boost_USE_STATIC_LIBS ON)
find_package( Boost COMPONENTS chrono date_time filesystem iostreams program_options ${BOOST_PYTHON_MODULE_NAME} regex system thread REQUIRED )
add_definitions(-DBOOST_ALL_NO_LIB=1) # Turn off auto-linking, creates problems when linking boost statically
find_package( Boost COMPONENTS chrono date_time filesystem iostreams program_options ${BOOST_PYTHON_MODULE_NAME} regex system thread zlib REQUIRED )
else()
SET(Boost_USE_STATIC_LIBS ${STATIC_BOOST})
find_package( Boost COMPONENTS chrono date_time filesystem iostreams program_options ${BOOST_PYTHON_MODULE_NAME} regex system thread REQUIRED )
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package( Threads REQUIRED )
SET(Boost_USE_STATIC_LIBS ${STATIC_BOOST})
endif()

# suggested install paths - see readme.md
Expand Down
63 changes: 63 additions & 0 deletions Malmo/samples/Python_examples/Untitled-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
agent_host = MalmoPython.AgentHost()
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)

# -- set up the mission -- #
mission_file = './tutorial_6.xml'
with open(mission_file, 'r') as f:
print("Loading mission from %s" % mission_file)
mission_xml = f.read()
my_mission = MalmoPython.MissionSpec(mission_xml, True)
# add 20% holes for interest
for x in range(1,4):
for z in range(1,13):
if random.random()<0.1:
my_mission.drawBlock( x,45,z,"lava")

max_retries = 3

if agent_host.receivedArgument("test"):
num_repeats = 1
else:
num_repeats = 150

cumulative_rewards = []
for i in range(num_repeats):

print()
print('Repeat %d of %d' % ( i+1, num_repeats ))

my_mission_record = MalmoPython.MissionRecordSpec()

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.5)

print("Waiting for the mission to start", end=' ')
world_state = agent_host.getWorldState()
while not world_state.has_mission_begun:
print(".", end="")
time.sleep(0.1)
world_state = agent_host.getWorldState()
for error in world_state.errors:
print("Error:",error.text)
print()

# -- run the agent in the world -- #
cumulative_reward = agent.run(agent_host)
print('Cumulative reward: %d' % cumulative_reward)
cumulative_rewards += [ cumulative_reward ]
61 changes: 61 additions & 0 deletions Malmo/samples/Python_examples/navigation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<About>
<Summary>Navigation through survival world.</Summary>
</About>

<ModSettings>
<MsPerTick>50</MsPerTick>
</ModSettings>

<ServerSection>
<ServerInitialConditions>
<Time>
<StartTime>6000</StartTime>
<AllowPassageOfTime>false</AllowPassageOfTime>
</Time>
<Weather>clear</Weather>
<AllowSpawning>false</AllowSpawning>
</ServerInitialConditions>
<ServerHandlers>
<DefaultWorldGenerator forceReset="true"/>
<NavigationDecorator>
<randomPlacementProperties>
<maxRadius>64</maxRadius>
<minRadius>64</minRadius>
<block>diamond_block</block>
<placement>surface</placement>
</randomPlacementProperties>
<randomizeCompassLocation>true</randomizeCompassLocation>
<minRandomizedDistance>0</minRandomizedDistance>
<maxRandomizedDistance>1</maxRandomizedDistance>
</NavigationDecorator>
<ServerQuitFromTimeUp timeLimitMs="300000" description="out_of_time"/>
<ServerQuitWhenAnyAgentFinishes/>
</ServerHandlers>
</ServerSection>

<AgentSection mode="Survival">
<Name>Columbus</Name>
<AgentStart>
<Inventory>
<InventoryObject slot="0" type="compass" quantity="1"/>
</Inventory>
</AgentStart>
<AgentHandlers>
<ObservationFromFullStats/>
<ObservationFromCompass/>
<ContinuousMovementCommands turnSpeedDegs="1800"/>
<RewardForMissionEnd>
<Reward description="out_of_time" reward="0" />
</RewardForMissionEnd>
<RewardForDistanceTraveledToCompassTarget density="PER_TICK" rewardPerBlock="1" />
<!-- <RewardProducerAttributes reward="100.0" type="diamond_block" behaviour="onceOnly"/> -->
<!-- </RewardForDistanceTraveledToCompassTarget> -->
<AgentQuitFromTouchingBlockType>
<Block type="diamond_block"/>
</AgentQuitFromTouchingBlockType>
<PauseCommand/>
</AgentHandlers>
</AgentSection>
</Mission>
20 changes: 14 additions & 6 deletions Malmo/samples/Python_examples/run_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ def run(argv=['']):

agent_host = MalmoPython.AgentHost()
malmoutils.parse_command_line(agent_host, argv)
with open('navigation.xml', 'r') as f:
print("Loading mission from %s" % 'navigation.xml')
mission_xml = f.read()
my_mission = MalmoPython.MissionSpec(mission_xml, True)

my_mission = MalmoPython.MissionSpec()
my_mission.timeLimitInSeconds( 10 )
my_mission.requestVideo( 320, 240 )
my_mission.rewardForReachingPosition( 19.5, 0.0, 19.5, 100.0, 1.1 )
# my_mission = MalmoPython.MissionSpec()
# my_mission.timeLimitInSeconds( 10 )
# my_mission.requestVideo( 320, 240 )
# my_mission.rewardForReachingPosition( 19.5, 0.0, 19.5, 100.0, 1.1 )

my_mission_record = malmoutils.get_default_recording_object(agent_host, "saved_data")

Expand Down Expand Up @@ -103,6 +107,7 @@ def run(argv=['']):
print()

last_delta = time.time()
net_reward = 00
# main loop:
while world_state.is_mission_running:
agent_host.sendCommand( "move 1" )
Expand All @@ -119,14 +124,17 @@ def run(argv=['']):
print("Max delay exceeded for world state change")
restart_minecraft(world_state, agent_host, client_info, "world state change")
for reward in world_state.rewards:
print("Summed reward:",reward.getValue())
cur_r = reward.getValue()
print("Summed reward:",cur_r)
net_reward += cur_r
print(net_reward)
for error in world_state.errors:
print("Error:",error.text)
for frame in world_state.video_frames:
print("Frame:",frame.width,'x',frame.height,':',frame.channels,'channels')
#image = Image.frombytes('RGB', (frame.width, frame.height), bytes(frame.pixels) ) # to convert to a PIL image
print("Mission has stopped.")

print("FINAL REWARD: {}".format(net_reward))

if __name__ == "__main__":
run(sys.argv)
22 changes: 22 additions & 0 deletions Malmo/samples/samples.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>MIXIN</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Java_examples" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="com.microsoft.MalmoMod.Minecraft.main" exported="" />
<orderEntry type="module" module-name="com.microsoft.MalmoMod.Minecraft.test" scope="TEST" />
</component>
</module>
3 changes: 2 additions & 1 deletion Malmo/src/AgentHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,10 @@ namespace malmo
if( !this->commands_connection ) {
TimestampedString error_message(
boost::posix_time::microsec_clock::universal_time(),
"AgentHost::sendCommand : commands connection is not open. Is the mission running?"
"AgentHost::sendCommand : commands connection is not open. Attempting to start a new commands connection."
);
this->world_state.errors.push_back( boost::make_shared<TimestampedString>( error_message ) );
this->openCommandsConnection();
return;
}

Expand Down
33 changes: 32 additions & 1 deletion Malmo/src/MissionSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace malmo
const std::vector<std::string> MissionSpec::all_inventory_commands = { "swapInventoryItems", "combineInventoryItems", "discardCurrentItem",
"hotbar.1", "hotbar.2", "hotbar.3", "hotbar.4", "hotbar.5", "hotbar.6", "hotbar.7", "hotbar.8", "hotbar.9" };
const std::vector<std::string> MissionSpec::all_simplecraft_commands = { "craft" };
const std::vector<std::string> MissionSpec::all_nearbycraft_commands = { "craftNearby" };
const std::vector<std::string> MissionSpec::all_nearbysmelt_commands = { "smeltNearby" };
const std::vector<std::string> MissionSpec::all_chat_commands = { "chat" };
const std::vector<std::string> MissionSpec::all_mission_quit_commands = { "quit" };
const std::vector<std::string> MissionSpec::all_human_level_commands = { "forward", "left", "right", "jump", "sneak", "sprint", "inventory", "swapHands", "drop", "use", "attack", "moveMouse",
Expand Down Expand Up @@ -110,6 +112,7 @@ namespace malmo
child.erase("FlatWorldGenerator");
child.erase("FileWorldGenerator");
child.erase("DefaultWorldGenerator");
child.erase("BiomeGenerator");
}
}

Expand Down Expand Up @@ -137,6 +140,11 @@ namespace malmo
if (defaultWorldGenerator) {
defaultWorldGenerator.get().put("<xmlattr>.forceReset", true);
}
const auto& biomeWorldGenerator =
mission.get_child_optional("Mission.ServerSection.ServerHandlers.BiomeGenerator");
if (biomeWorldGenerator) {
biomeWorldGenerator.get().put("<xmlattr>.forceReset", true);
}
}

void MissionSpec::setTimeOfDay(int t,bool allowTimeToPass)
Expand Down Expand Up @@ -376,6 +384,9 @@ namespace malmo
child.erase("DiscreteMovementCommands");
child.erase("AbsoluteMovementCommands");
child.erase("SimpleCraftCommands");
child.erase("NearbyCraftCommands");
child.erase("NearbySmeltCommands");
child.erase("PlaceCommands");
child.erase("ChatCommands");
child.erase("MissionQuitCommands");
}
Expand Down Expand Up @@ -420,11 +431,16 @@ namespace malmo
{
addVerbToCommandType(verb, "Mission.AgentSection.AgentHandlers.InventoryCommands");
}

void MissionSpec::allowAllChatCommands()
{
mission.put("Mission.AgentSection.AgentHandlers.ChatCommands", "");
}

void MissionSpec::allowAllPlaceCommands()
{
mission.put("Mission.AgentSection.AgentHandlers.PlaceCommands", "");
}

// ------------------------------- information ---------------------------------------------------

Expand Down Expand Up @@ -522,6 +538,15 @@ namespace malmo

if (e.second.get_child_optional("AgentHandlers.SimpleCraftCommands"))
command_handlers.push_back("SimpleCraft");

if (e.second.get_child_optional("AgentHandlers.NearbyCraftCommands"))
command_handlers.push_back("NearbyCraft");

if (e.second.get_child_optional("AgentHandlers.NearbySmeltCommands"))
command_handlers.push_back("NearbySmelt");

if (e.second.get_child_optional("AgentHandlers.PlaceCommands"))
command_handlers.push_back("Place");

if (e.second.get_child_optional("AgentHandlers.MissionQuitCommands"))
command_handlers.push_back("MissionQuit");
Expand Down Expand Up @@ -582,6 +607,12 @@ namespace malmo
else if (command_handler == "SimpleCraft") {
allowed_commands = all_simplecraft_commands;
}
else if (command_handler == "NearbyCraft") {
allowed_commands = all_nearbycraft_commands;
}
else if (command_handler == "NearbySmelt") {
allowed_commands = all_nearbysmelt_commands;
}
else if (command_handler == "Chat") {
allowed_commands = all_chat_commands;
}
Expand Down
6 changes: 6 additions & 0 deletions Malmo/src/MissionSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ namespace malmo
//! Only applies to the first agent in the mission. For multi-agent missions, specify the command handlers for each in the XML.
void allowAllChatCommands();

//! Adds a place command handler if none present, with neither an allow-list or a deny-list, thus allowing any command to be sent.
//! Only applies to the first agent in the mission. For multi-agent missions, specify the command handlers for each in the XML.
void allowAllPlaceCommands();

// ------------------------- information --------------------------------------

//! Returns the short description of the mission.
Expand Down Expand Up @@ -382,6 +386,8 @@ namespace malmo
static const std::vector<std::string> all_discrete_movement_commands;
static const std::vector<std::string> all_inventory_commands;
static const std::vector<std::string> all_simplecraft_commands;
static const std::vector<std::string> all_nearbycraft_commands;
static const std::vector<std::string> all_nearbysmelt_commands;
static const std::vector<std::string> all_chat_commands;
static const std::vector<std::string> all_mission_quit_commands;
static const std::vector<std::string> all_human_level_commands;
Expand Down
Loading