解説動画
解答コード
let pattern149 = [[[0]]];
function inspectStracture149() {
pattern149 = []; // パターン全体を格納するための空の配列を初期化
for (let k = 0; k < 3; k++) {
let patternLine01 = []; // 1次元配列を初期化
for (let x = 0; x < 3; x++) {
let patternLine02 = []; // 1次元配列を初期化
for (let y = 0; y < 6; y++) {
const blockType = agent.inspect(AgentInspection.Block, DOWN);
patternLine02.push(blockType); // ブロックタイプをpatternLine02に追加
agent.move(LEFT, 1);
}
patternLine01.push(patternLine02); // patternLine02をpatternLine01に追加
agent.move(RIGHT, 6);
agent.move(FORWARD, 1);
}
pattern149.push(patternLine01); // patternLine01をpatternに追加
if (k == 0) {
agent.move(FORWARD, 1);
}
if (k == 1) {
agent.move(BACK, 3);
agent.move(RIGHT, 7);
}
if (k == 2) {
agent.move(BACK, 7);
}
}
}
function cloneStracture149() {
pattern149.forEach(function (element) {
element.forEach(function (block) {
block.forEach(function (item) {
if (item !== AIR) { // ブロックが空気でないかチェック
agent.setItem(item, 1, 1);
agent.place(DOWN);
}
agent.move(LEFT, 1);
});
agent.move(RIGHT, block.length);
agent.move(FORWARD, 1);
});
agent.move(BACK, element.length);
agent.move(UP, 1);
});
}
player.onChat("14-9", function on_on_chat() {
// 開始位置に移動
agent.move(UP, 1);
agent.move(FORWARD, 1);
inspectStracture149();
cloneStracture149();
});