|
|
In this lab you will program robots to play Minecraft and optimize their
|
|
|
operation by using multiple threads to control multiple robots. You are
|
|
|
provided a modded version of Minecraft which allows you to connect to a
|
|
|
running game world to obtain a robot called a “turtle”. When you close
|
|
|
the connection, the robot disappears. You may also open multiple
|
|
|
connections to obtain multiple robots which can then work in parallel.
|
|
|
|
|
|
The setup is based on the turtles in the mod ComputerCraft and as such
|
|
|
provides the same
|
|
|
[API](http://computercraft.info/wiki/Turtle_%28API%29). A small example
|
|
|
demonstrating some of the turtles’ functions is included in your files.
|
|
|
|
|
|
Even though most tasks can be solved using only one turtle,
|
|
|
parallelization is the key to do them quickly. This introduces a few
|
|
|
synchronization issues that you need to deal with: how to divide the
|
|
|
task among the turtles and how to prevent turtles from crashing into
|
|
|
each other.
|
|
|
|
|
|
Don’t worry, if you’ve never played Minecraft before. There is a lot of
|
|
|
content to the game, but for this lab you just need to know that the
|
|
|
world is made of a 3D grid of blocks, which can be mined (“dug”) to
|
|
|
obtain them as “item” in one’s inventory, allowing one to place them
|
|
|
somewhere else.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
- Before opening Eclipse or Minecraft, run
|
|
|
`/opt/Uebungen/turtles/setup.sh`.
|
|
|
|
|
|
- Run Eclipse and Minecraft from the “start menu”.
|
|
|
|
|
|
- Log into Minecraft (we will provide you with accounts for this lab)
|
|
|
and launch the game using the “forge” profile (set in the bottom
|
|
|
left of the launcher).
|
|
|
|
|
|
- Open a singleplayer world, for example the one we pre-installed for
|
|
|
you. Turtles may now be created by connecting on the port 7473.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
Run and read through the example program (“TurtleMain”). If you can’t
|
|
|
find the turtle moving about, try printing its location using
|
|
|
`System.out.println(turtle.getLocation())`.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
- In Minecraft the y coordinate is used for the height axis: near 0
|
|
|
you will encounter indestructible bedrock blocks, while ocean level
|
|
|
is 64.
|
|
|
|
|
|
- By pressing F3 in Minecraft an overlay showing various information
|
|
|
can be displayed. This is particularly useful for finding a certain
|
|
|
coordinate.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
Your first real task is to build a simple 3x1x3 grid (i.e., horizontal,
|
|
|
height 1) of blocks at height y = 90 centered right above the spawning
|
|
|
location. The goal here is to get accustomed to the
|
|
|
[API](http://computercraft.info/wiki/Turtle_%28API%29). Keep in mind
|
|
|
that turtles need to collect some blocks before being able to place any!
|
|
|
|
|
|
Edit
|
|
|
|
|
|
- Once turtles start placing blocks in the correct spots, the progress
|
|
|
of the building will be displayed in in-game chat.
|
|
|
|
|
|
- If a turtle function call fails (i.e., returns false), you can use
|
|
|
the `getFailureReason()` method to obtain a string containing the
|
|
|
reason. The reason will also be output to stderr.
|
|
|
|
|
|
- A turtle can interact with the 3 blocks in front of, above and below
|
|
|
them. To access other blocks it needs to move or turn.
|
|
|
|
|
|
- Turtles have an inventory of 16 slots labeled 1 through 16, all
|
|
|
starting out empty. A slot can hold up to 64 of any single block
|
|
|
type. When a block is mined it is placed in the first slot of its
|
|
|
type (if there is any) or into the first empty slot (if there is
|
|
|
not). Use the `select(int slot)` function to choose which slot is
|
|
|
used for actions, e.g., for placing blocks from.
|
|
|
|
|
|
- We extended the [Turtle
|
|
|
API](http://computercraft.info/wiki/Turtle_%28API%29) by 2
|
|
|
additional methods to allow a turtle to determine its position and
|
|
|
orientation in the world: `getLocation()` and `getFacing()`.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
**Setup:** Copy
|
|
|
`/home/lab/local-data/turtles/exercise2/ComputerCraft.cfg` over the
|
|
|
existing file of the same name in `/home/lab/.minecraft/config`, and
|
|
|
restart Minecraft.
|
|
|
|
|
|
Now that you have understood the basics, it is time to add some
|
|
|
parallelization! Build tower hollow of height 10 with a 5×5 area and a
|
|
|
few holes in the side (see whiteboard). The tower should be made of
|
|
|
cobblestone only (block name `minecraft:cobblestone`). Again, the tower
|
|
|
should start at y = 90 and be centered around the spawning location.
|
|
|
|
|
|
Try to complete this task as quickly as possible by using as many
|
|
|
turtles as you can handle! On world seed `qwer` 60 seconds is a good
|
|
|
time. The assistants’ record is 43.1 seconds.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
- Use `getItemDetail()` to find out what materials you picked up.
|
|
|
|
|
|
- All function calls are blocking, i.e., they only return once the
|
|
|
operation is complete or has failed.
|
|
|
|
|
|
- In Java, two strings `a` and `b` are compared by calling
|
|
|
`a.equals(b)`.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
The room will be divided into two teams, each of which will be provided
|
|
|
a server. The goal is to collaboratively build a cobblestone pyramid
|
|
|
larger than that of the other team!
|
|
|
|
|
|
This is a very open-ended task. Feel free to focus on smaller parts of
|
|
|
the problem, such as the efficient harvesting of cobblestone from the
|
|
|
game world.
|
|
|
|
|
|
Edit
|
|
|
|
|
|
- When creating a world, you may want to turn cheats on to allow you
|
|
|
to switch to spectator mode.
|
|
|
|
|
|
- Entering the command “/gamemode 3” enables you to fly around (press
|
|
|
‘T’ to open a text box in game).
|
|
|
|
|
|
- A random seed for a world without much obstruction near the spawn
|
|
|
point is `qwer`.
|
|
|
|
|
|
- If something goes wrong, you can easily get a clean world by
|
|
|
selecting an existing one from the menu and choosing “Re-Create”.
|
|
|
|
|
|
- Singleplayer worlds pause when the window loses focus unless you
|
|
|
select “Open to LAN” in the menu. |