14-7 森の深みへ②

解説動画

解答コード

let pattern = [[0]];

function inspectStatue147() {
    pattern = [];
    for (let x = 0; x < 5; x++) {
        let patternLine = [];
        for (let y = 0; y < 5; y++) {
            const blockType = agent.inspect(AgentInspection.Block, DOWN);
            patternLine.push(blockType);
            agent.move(RIGHT, 1);
        }
        pattern.push(patternLine);
        agent.move(LEFT, 5);
        agent.move(FORWARD, 1);
    }
}

function cloneStatue147() {
    pattern.forEach(function (element) {
        element.forEach(function (block) {
            if (block !== AIR) {  // ブロックが空気でないかチェック
                agent.setItem(block, 1, 1);
                agent.place(DOWN);
            }
            agent.move(RIGHT, 1);
        });
        agent.move(LEFT, element.length);
        agent.move(FORWARD, 1);
    });
}

player.onChat("14-7", function on_on_chat() {
    // 読み込みの開始位置へ移動
    agent.move(UP, 1);
    agent.move(FORWARD, 1);

    // 像を読み込む
    inspectStatue147();

    // 建築の開始位置へ移動
    agent.move(BACK, 5);
    agent.move(RIGHT, 6);

    // 像を建築する
    cloneStatue147();
});