Lesson plan

Walled Fortress

Program the Agent to construct a three-block-high fortress wall around a village foundation using repeat loops and movement commands.

Walled Fortress
Ages
Ages 8-10
Essential question

How can we use loops and Agent movement commands to construct a secure perimeter wall around a village?

Overview

In this engineering and computer science challenge, students define a clear design problem: securing an entire village by building a protective wall. By breaking the construction project into automated tasks, learners explore how automation and programmatic thinking can solve architectural and structural challenges efficiently.

Using Minecraft Education and Code Builder, students write scripts to direct their personal Agent. Instead of placing every block by hand, learners test movement controls, load their Agent inventory, and implement repeat loops to erect sturdy multi-block structures along a predefined foundation.

Learning objectives

By the end of this lesson students will be able to:

  • Define the criteria and constraints needed to successfully enclose a village perimeter.
  • Write and test a repeat loop that enables the Agent to build vertical wall segments.
  • Sequence Agent movement and placement commands to navigate turns and continuous foundations.
  • Analyze non-working code snippets to identify errors and propose corrective fixes.

Blocks and items used in this lesson

Key vocabulary

Agent
A programmable helper in Minecraft that carries inventory and performs actions through code.
Repeat Loop
A coding structure that executes a set of instructions multiple times.
Inventory
The storage slots where items and construction blocks are held for the player or Agent to use.

Before class

Lesson sequence

  1. Problem Definition and Criteria Review

    Introduce the engineering challenge: protecting the village. Outline the success criteria with the class: the finished wall must be at least three blocks tall, one block wide, and fully trace the red sandstone foundation line.

  2. Agent Setup and Material Selection

    Have students choose their building material and load those blocks into the Agent's inventory. Remind learners to position their Agent along the sandstone line using the teleport to player command.

  3. Code Construction and Testing

    Working individually or in small teams, students write code using repeat loops, place on move, and directional commands (forward, turn left, turn right). Encourage testing small sections of wall before attempting to enclose entire stretches or tackle corners.

  4. Debugging and Perimeter Enclosure

    Students continue building around the village perimeter. If the Agent stops or misplaces blocks, students inspect their loop limits and turning logic to adjust their scripts.

  5. Code Reflection and Review

    Regroup to discuss what made loops effective, what challenges arose at corners, and how criteria for success were met. Display samples of broken code to collaboratively diagnose why they did not work.

Assessment: success criteria

  • The wall completely encloses the village along the red sandstone foundation line.
  • The wall meets the minimum dimensions of three blocks high and one block wide.
  • The student successfully used a repeat loop within Code Builder to place building materials.
  • The student can articulate what a loop does and explain how they solved a programming challenge.

Differentiation

Support

Provide the wall-building tutorial and guide students to test a simple vertical loop on a straight one-block strip before attempting corners.

Stretch

Challenge students to program their Agent to navigate 90-degree turns autonomously and seal the entire perimeter in a single automated program run.

Knowledge check

5 questions to check understanding after the lesson. Tap an answer to see if it is right; the score appears at the end.

  1. 1What is the primary function of a loop in coding?

  2. 2What must students do before their Agent can build with a selected material?

  3. 3What is the minimum required wall height for this engineering challenge?

  4. 4Which marker line does the Agent need to trace around the village?

  5. 5Why is testing small segments of code recommended before running a large building loop?

Resources

Part of the Code for STEM curriculum

This is lesson 19 of 20 in Code for STEM.

  1. 3-D Fractions
  2. Aquarium
  3. Build a Dam
  4. Canyon Arch Bridge
  5. Chicken or the Egg
  6. Creeper Tower Test
  7. Energy Transfer
  8. Forces
  9. Hour of Code: AI for Good
  10. Minecraft Code Town
  11. Molecules
  12. Number Line Railroad
  13. Plate Motions
  14. Road Construction Ahead
  15. Scale
  16. Slope
  17. Surface Area and Perimeter
  18. Units of Measurement
  19. Walled Fortress
  20. Wave Properties

Frequently Asked Questions

Are students restricted to a single building material for their fortress?

No. Students may choose any building block they like, provided they load an adequate supply into the Agent's inventory prior to running the program.

How should students tackle building around corners?

Students should break down the movement into sequential steps, using turn commands such as turn left or turn right combined with forward movement before re-initiating their placement loop.

What is an effective way to handle code that fails during the lesson?

Capture screenshots of non-working code and share them with the group so students can collaboratively analyze what went wrong and how to fix it.

Adapted from Walled Fortress by John Miller on Minecraft Education, last updated Jan 25, 2019. This classroom version, the timings and the quiz were written by 9Minecraft Education.

You May Also Like

9Minecraft Education is an independent teaching resource and is not affiliated with Mojang or Microsoft. Lesson plans here are our own classroom-ready adaptations; each one links to the original resource and credits its author. © 2026 9minecraft.net