/
mazebot.R
65 lines (46 loc) · 1.88 KB
/
mazebot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## You will need the "miner" package for this. You can install
## it with the commands below:
#library(devtools)
#install_github("ropenscilabs/miner")
library(miner)
source("genmaze.R") # functions for generating a maze
source("solvemaze.R") # functions to build a maze in the world, and solve it
## First, launch a Spigot server with RaspberryJuice plugin
## For instructions, see:
## https://ropenscilabs.github.io/miner_book/installation-and-configuration.html#docker
## The IP address of your server
## This is the same IP you will use to log into
## a multiplayer server using Minecraft (Java edition)
MCserverIP <- "52.170.156.222" # use YOUR IP address here
## Launch Minecraft now, and join the multiplayer server using its IP address.
## A function to connect to the server and print a message to confirm.
## Minecraft disconnects every now and again, so you might need
## to call it again later if you get errors.
rc <- function(msg=TRUE) {
try(mc_close(), silent=TRUE)
mc_connect(MCserverIP)
if(msg) chatPost("Connected from R")
}
## Now connect to the server from R
rc()
## Get a player ID. Works best if there's only one player in the game,
## so you know whose it is
id <- getPlayerIds()
if(length(id)>1) warning("Multiple players in instance")
id <- id[1]
## Maze dimensions (we'll create a square maze)
mazeSize <- 8
## using the functions in genmaze.R:
m <- print_maze(make_maze(mazeSize,mazeSize), print=FALSE)
nmaze <- ncol(m) # dimensions
m[nmaze,nmaze-1] <- "!" ## end of the maze. We'll place the exit here.
## we will place the maze to the southeast of the player, 3 blocks away
## works best in a fairly flat area
## get the current player position
v <- getPlayerPos(id, TRUE)
altitude <- -1 ## height offset of maze
pos <- v+c(3, altitude, 3) # corner
## Build a maze near the player
buildMaze(m, pos, id)
## Move the player into the start of the maze, and then
solveMaze(id)