Created
December 30, 2016 22:26
-
-
Save yukkura/931fec0a384f15fa393b7b353e180caa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import mcpi.minecraft as minecraft | |
import mcpi.block as block | |
# 奇数を設定する事 | |
# 迷路の一片の長さ | |
line = 51 | |
# 壁として設置するブロック | |
blockType = block.DIAMOND_BLOCK | |
# 壁の高さ | |
height = 4 | |
# 迷路を初期化 | |
# blocks[x] が 0なら通行可能 | |
# blocks[x] が 1なら壁 | |
blocks = [0] * line * line | |
# 外壁を設定 | |
for i in range(line): | |
blocks[i] = 1 | |
blocks[i * line] = 1 | |
blocks[(i + 1) * line - 1] = 1 | |
blocks[i + line * (line - 1)] = 1 | |
# スタート地点とゴールを通行可能にする | |
blocks[1] = 0 | |
blocks[line * line - 2] = 0 | |
# 偶数行及び列のブロックを壁に設定する | |
# 更に設定した壁から | |
# 2行目のみ上下左右 | |
# 以外を下左右 | |
# 方向に壁を設定する | |
# すでに壁が存在する場合異なる方向に壁を設置する | |
for y in range(2, line - 1, 2): | |
for x in range(2, line - 1, 2): | |
# 場所特定 | |
index = y * line + x | |
# 下左右は共通 | |
tmp = [index + line, index - 1, index + 1] | |
if y == 2: | |
# 一番上段のみ上への壁設置を試みる | |
tmp.append(index - line) | |
table = [] | |
for i in tmp: | |
if blocks[i] == 0: | |
table.append(i) | |
# 壁設置 | |
blocks[index] = 1 | |
blocks[table[random.randint(0, len(table) - 1)]] = 1 | |
mc = minecraft.Minecraft() | |
pos = mc.player.getPos() | |
pos.x += 1 | |
pos.z += 1 | |
# マインクラフトの世界にブロック配置 | |
for y in range(height): | |
for x in range(line): | |
for z in range(line): | |
index = x * line + z | |
type = block.AIR | |
if blocks[index] == 1: | |
type = blockType | |
mc.setBlock(pos.x + x, pos.y + y, pos.z + z, type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment