#VS2017 – #Minecraft game interaction agents, missions definitions and recording with #ProjectMalmo


I am going to write some posts about Project Malmo, Minecraft and Visual Studio 2017. I still do not have very clear the order in which I will do them, so I will write and update them as I go along with my learning process.

Once we have installed all the necessary prerequisites and Apps to be able to work with Visual Studio 2017 and Minecraft, it is time to begin to understand some basic concepts about how to program against the game.

It all starts with the creation of an AgentHost(), that is the main object to perform the command communication between a .Net App and Minecraft. The next thing we must do is define the environment in which we want to interact, we define this as a mission with the MissionSpec() object. A couple of important details here is that we can define the duration of the same and the resolution with which we want to work (lines 17 and 18).

If we also want to have a recording of each of the steps that are made in our game, in addition to several execution logs, we can use an object of the MissionRecordSpec() type for this. The only necessary step at this point is to start the mission (lines 21 to 27) where we can see something similar to the following


2017 11 08 Malmo 01

A couple of details to keep in mind when the game is running

  • Minecraft must load the game environment, so we must wait for it to be up and running before we add and run some game logic. An example on how to do this can be seen on lines 29 to 38
  • It is also important to control the time in which the mission is running. Missions are usually time based, so mission start and end time are important. Lines 41 to 48

Sample Source Code

using System;
using System.Threading;
using Microsoft.Research.Malmo;
namespace Malmo03
class Program
private static AgentHost _agentHost;
public static void Main()
_agentHost = new AgentHost();
_agentHost.parse(new StringVector(Environment.GetCommandLineArgs()));
var mission = new MissionSpec();
mission.requestVideo(640, 480);
mission.rewardForReachingPosition(19.5f, 0.0f, 19.5f, 100.0f, 1.1f);
var recordedFileName = $"./mission_data{DateTime.Now:hh mm ss}.tgz";
var missionRecord = new MissionRecordSpec(recordedFileName);
missionRecord.recordMP4(20, 400000);
_agentHost.startMission(mission, missionRecord);
WorldState worldState;
Console.WriteLine("Waiting for the mission to start");
worldState = _agentHost.getWorldState();
while (!worldState.has_mission_begun);
Console.WriteLine("Mission in progress !");
} while (worldState.is_mission_running);
Console.WriteLine("Mission has stopped.");

view raw
hosted with ❤ by GitHub

Greetings @ Toronto

El Bruno



8 thoughts on “#VS2017 – #Minecraft game interaction agents, missions definitions and recording with #ProjectMalmo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.