Unit 8 - Arrays
Unit 8 - Arrays
Unit 8 – 4 Lessons
60 minutes per lesson
Single Student
EDUCATION.MINECRAFT.NET
1
THEME OVERVIEW
In this unit, students will explore the coding concept of arrays. In computer
science, an array is a series of places to store things. Earlier students learned how
to use variables as a way to store information. Arrays store multiple values and
they are accessed from a single object (the array itself). Students will continue to
learn about the idea of storing information for later use, but they will learn about
the many values and usefulness of arrays.
LESSON OVERVIEW
All of the following lessons are approximately 45-60 minutes, depending on how
much time students are given to explore the coding activities:
• Lesson A: Introduction to Arrays
• Lesson B: Build a Zoo with Arrays
• Lesson C: Teleport with Arrays
• Lesson D: Get Creative with Arrays
LESSON OBJECTIVES
• Learn and apply the coding concept of arrays
• Explain the usefulness of arrays, as a collection of related items
• Describe real-life examples of arrays
• Use the array operations to add and arrange items
• Describe array indexes and elements in MakeCode
• Sort array values with basic sorting algorithms
• Design an original project to apply the use of arrays to create a piece of
artwork in Minecraft
MINECRAFT MECHANICS
C C
Summons the Agent and opens the MakeCode
interface
T T
2
Opens chat panel in Minecraft for commands to
be typed
ESC ESC
When a student wants to leave the game, leave
chat, or pause the game
CODING BLOCKS
Array
a list of other items that have a basic
(primitive) type.
KEY VOCABULARY
Array – a list of items that are numbers, booleans, or strings
LESSON ACTIVITIES
Lesson A: Introduction to Arrays (Slides 1-10)
Direct Instruction (Teacher-Led; “I Do”)
Welcome to back to Coding with Minecraft, a place to learn all about the basic
concepts of computer science. Over the next couple of sessions, we are going to
learn about arrays. (slide 1)
Today, we are going to learn about what are arrays and how arrays are applicable
in real-life, but also how they are used in Minecraft. (slide 2)
3
one name to find the information. This information could be a list of items, a row
of mailboxes, or a train of container boxes. for example. The information in the
array is all similar.
For example, maybe we want to store what each mailbox on a street has in it.
If you wanted to save information about the preceding mailboxes and used
variable, you would need to make several variables with names
like Mailbox0, Mailbox1, and so on.
This is time consuming because you have to type a lot, and it is inefficient when
you want to later get that information back. This is where arrays help in a big way.
By using one array and one name, you can store all the information you need.
Then you just use the one name, “Mailboxes,” and the number or “key” of the
mailbox you want. The keys in this example are 0, 1, 2, 3, 4, and 5. Sometimes the
term index is used too. The key or index is the number of the box holding the
information you want.
Therefore, when you have a lot of variables to deal with, it’s more convenient to
use an array. Also, arrays are handy when you don’t know ahead of time how
many variables you are going to need.
4
Array Indexes
The location of a particular item in the array is known as its index. By default,
arrays start at an index of 0. The first item in an array has an index of 0, the next
one has an index of 1, and so on.
The length of an array is the same as the number of items in the array.
For example, if there are six mailboxes, with indexes from 0 to 5. The length of this
array is 6.
Array Elements
In MakeCode, you can store different types in an array:
• Numbers
• Text
• Chickens
• Positions
• Blocks
• Zombies
You can add objects to an array, remove them, and count the number of things in
the array at any given time. You can even reverse their order in the array with a
single command. Arrays are a convenient and powerful way to work with lots of
items at once.
5
Guided Instruction (Teacher Modeling; “We Do”)
Unplugged Activity: Arrays in Real Life (slide 5)
Questions to ask students
• Ask your students if any of them like to collect something. What is it? It
could be comic books, game/sports cards, coins, action figures, books, and
so on.
• How big is the collection?
• How is it organized?
• Are the items sorted in any way?
• How would you go about finding a particular item in the collection?
Array “terms”
In the discussion, see if you can explore the following array vocabulary words in
the context of your students’ personal collections:
Having some pictures of collections might help to get the conversation going. You
might even do this in a few sessions and allow students to bring in pictures of their
collections for the second time you meet.
Directions
Have 10 students volunteer to stand up at the front of the classroom. Ask another
student to volunteer to be the sorter.
• Mix up the order of the papers and give each student a piece of paper with a
number on it. They should hold the paper facing outward so their number is
6
visible to the rest of the class. Each of these students represents a value in
the array.
Initial sort
Ask the sorter to place the students in order by directing them to move, one at a
time, to the proper place. After the students are sorted, ask students the following
questions:
• How did the sorter put you into the right order?
• Did you see a pattern?
• What strategy did the sorter use to put everyone in the right order?
Ask for clarification when necessary: What does it mean when you say “put them
in the right place”?
For example, to put someone in the right place means:
• Bring the person to the front of the line, and then compare that person’s
number with the first person’s number.
• If it’s larger, then move that person to the right.
• Keep doing this as long as the person’s number is larger than the person on
the right.
A good point to bring up is the fact that several mini tasks happen when you sort
something. Pattern matching, comparing, and so on are all used. Without the
proper instructions, there is no way for a computer to do this easily. Therefore,
sorting is not always a simple task in computer science. However, if you think, test,
and plan out your code, you can get the computer to sort some very complicated
information.
7
• If the student on the right is smaller than the student on the left, they
should swap places.
• Then compare the second and third students.
• If the student on the right is smaller than the student on the left, they
should swap places.
• When you reach the end, start over at the beginning again.
• Continue in this way until you make it through the entire row of students
without swapping anybody.
In Pseudocode
1. Create a variable called counter.
2. Set the counter to zero.
3. Go through the entire array.
4. If the value you are considering is greater than the value to its right:
a. Swap them
b. Add one to counter
5. Repeat steps 2 through 4 as long as counter is greater than zero.
To have some fun, create two groups and race! You might even make one group
use the bubble sort and have the other group use their own style. Then you could
talk about the differences. If the bubble sort is slower, which it probably will be,
you can again point to the fact that it may be slower but the directions to the
computer are actually much simpler (compare two numbers, swap, repeat). The
8
team using their own style, no doubt, relied on several other small decisions that
would be difficult to convey to the computer in directions.
Computers are great at doing simple directions very quickly. Sorting should
leverage this.
LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 8)
9
You can store animals in an array and spawn them wherever you like. We’ll use
this capability to build a fenced-in animal pen and create an instant zoo anytime
we want. When this project starts up, it will create an array and fill it with animals
of your choice. (slide 13)
Make sure you are set-up to demonstrate and lead the students through this
coding experience. It is best if you complete this activity on a device connected to a
projector or presentation screen. Split the screen and display the classroom
presentation alongside of the Minecraft world.
Have all students log into Minecraft: Education Edition. Students should continue
working in the same world from Lesson A. Directions for navigating to the previous
world can be found on slide 15-16.
•
•
•
Coding Solution:
Then, you will need to publish and import the program into Code Builder.
11
Step 1: Share your program. Step 2: Name the project, provide a
brief description, and select the
“Publish to share” button.
Step 3: Select the green “Copy link” Step 4: Inside Code Builder, select the
button. “Import” button.
12
Now, we are going to return to our Minecraft world to try out our code. (slide 27-
30)
Extensions
Let’s add to our existing zoo to continue to make it bigger and better. Play around
with the code in each experiment and see what else you can add to make the zoo
more complete!
Experiment 1 - Add a birdhouse, birds only!
In this experiment, we separate the birds into their own array and build a cage for
them specifically. An aviary is a building where birds are kept. This is what they will
get. Type ‘zoo’ into the chat window and now you will get your land animals in
their pen and birds in their own aviary. However, there are still some problems.
Use this code to start with.
How might you make this better? Can you build a separate pen for each animal?
What else can you think up to do?
13
Here you can see one problem. Look how the donkey is red. This is because our
wolves are attacking them. Perhaps wolves need to be separated into their own
pen or cave or something.
Again, you might try to extend the zoo even more by adding signs, different
features, caves, rivers, or any other thing you can think of.
Notice the code uses functions to help organize the new enclosures for different
kinds of animals. Each function creates the pen and animals for each type of
animal.
14
LESSON CONCLUSION
Upon completion of this lesson, students should be able to answer the following
questions: (slide 31)
15
1. What is a builder?
Answer: The Builder is like an invisible cursor in the game that can place
blocks along a path very quickly.
2. What direction does the builder default to when walking, if you do not set a
direction?
Answer: The direction the builder is facing when the command starts.
The following questions can also be used as an exit ticket (formative assessment).
A printable version of these questions can be found in the Assessment Guide.
Conclude the lesson by reviewing the concepts covered in Lesson B. (slide 32)
One of the most enjoyable activities when playing Minecraft is to build houses.
Often, these houses are spread all over the world. Sometimes while exploring, you
might discover awesome hidden temples or villages in remote locations. It can be
challenging to remember how to get back to all of those places. In this activity,
you’ll see how to create a tool that you can use to teleport between all of those
different locations. This ‘Warp Belt’ will save the locations in memory by using
arrays so you can easily jump between them all. (slide 36)
We are going to create code to help us create this wrap belt. (slide 37)
16
this activity on a device connected to a projector or presentation screen. Split the
screen and display the classroom presentation alongside of the Minecraft world.
Have all students log into Minecraft: Education Edition. Students will need to open
a new world template. Directions for navigating to the previous world can be
found on slide 38.
In the chat window, enter ”/locate” followed by a space + the name of a structure
you would like you to find. You can then enter in any structure you might want to
find in the world you are in. You might use this to first locate things, teleport there,
and then save the locations in your warp belt!
For example, to find a mansion in a world, enter the following:
Once you locate at least two different locations (e.g., mansion and a village), make
sure to rewrite down the coordinates.
17
You’ll support four main commands in this program: (slide 41)
• Delete: This creates an empty array, effectively deleting your old one.
• Save: This saves your current position to the next empty spot in the array.
• Warp: This command, when entered with a number, teleports the player to
the position stored at that index in the array.
• List: This command prints all the positions in the array, with their index
numbers
18
• From PLAYER, drag another on chat command to the Workspace. Name
this command save.
• From ARRAYS, drag add value to end into on chat command "save".
• From the add value to end drop-down menu, select warp_array as the
array you want to add values to.
• You are saving positions, so you need to adjust add value to end a little
more. From PLAYER, drag a player world position into the Add value of
add value to end.
• From PLAYER, drag a say block after the "warp_array" add value "player
world position" to end block.
• In the say block, enter a message, for example, "position added".
• From PLAYER, drag a on chat command to the Workspace. Name this
command warp.
• In on chat command "warp", click the plus sign (+) to add a parameter.
• Rename num1 to Warp_LocationNum.
• From PLAYER, drag teleport to into on chat command "warp".
• From ARRAYS, drag get value at into teleport to and replace the existing
coordinates block.
• From the get value at drop-down menu, select the warp_array variable.
• From the MATH, drag an operator into the slot.
• From the VARIABLES, drag Warp_LocationNum into the first slot of the
math block.
• Write the number “1” in the second slot of the math block.
Coding Solution:
Import the program into Code Builder and then test your code. (slide 46)
Now, when you call the warp command with a number, the code will grab the
position in the spot you specify. Then you will teleport to the position stored in the
array. (slide 47-48)
19
Independent Work (Teacher Support; “You Do”)
Challenge
Let’s continue to improve our warp belt code by checking what the user enters and
giving them feedback.
Extensions
Here, there are no rules… Copy this code for the experiments and change things
around to see what kind of results you can create. Suggestions are given, but do as
you like!
Extension 1
Enter save in your chat window, and then press enter. You should see directions
prompting you to enter a number now. You will now save coordinates and keep a
name of the type of location connected to this.
This code does a few things. First, it uses multiple arrays that have connected
information. This means the same index works with multiple arrays and the
information you get is connected. In one array, the coordinates are stored; in
another, the names of the locations. A third array is used to keep the default
locations, but it is not necessary to do it this way.
20
In the chat window, enter ‘/locate’ followed by a space.
You can then enter in any structure you might want to find in the world you are in.
You might use this to first locate things, teleport there, and then save the locations
in your warp belt!
What other things could you do with teleporting or coordinates in code? Can you
use arrays creatively to make the code more complex?
What about saving a monster type to each location? Then when you warp back, it
spawns that monster! You could make a teleporting game with missions to
teleport to different locations, kill all the monsters there (which you spawn with
code), and then teleport to the next location.
LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
49).
What four main commands did you support in this program and what did they do?
• Delete: This creates an empty array, effectively deleting your old one.
• Save: This saves your current position to the next empty spot in the array.
• Warp: This command, when entered with a number, teleports the player to
the position stored at that index in the array.
21
• List: This command prints all the positions in the array, with their index
numbers
Then, students should take the quiz (found in the assessment guide). This is
intended as a low-stakes formative assessment tool to establish whether students
are prepared to take on the unit independent project.
Questions Answers
1. What’s a benefit of iteration inAny of the following:
coding? • Fewer lines of code
• Simplified code
• Takes up less room in memory
• Shorter programs
• Makes it easier to find mistakes
2. Match the following types of loops with their definition:
22
Celebrate the learning that occurred within the lesson. (slide 50)
Then provide students with a preview of the next lesson. (slide 51)
23
• Describe how your program creates its artwork.
• How did you ensure that only valid indexes are accessed?
GRADING CRITERIA
4 = Project creates a piece of artwork, efficiently and effectively.
3 = Project is missing 1 of the required elements.
2 = Project is missing 2 of the required elements.
1 = Project lacks all of the required elements.
ARRAYS
4 = Array is properly created, possible to access all elements, no out-of-bounds
access.
3 = Array is properly created, (possible to access all elements or no out-of bounds
access)
2 = Array is properly created, some elements not reachable, and out-of-bounds
access not prevented.
1 = Array is not created properly or used at all, no means of stopping out-of-
bounds access was implemented.
LESSON CONCLUSION
Upon completion of this lesson, review the concepts covered in this lesson. (slide
58).
24
EDUCATIONAL STANDARDS
CSTA Standards
• 2-AP-17 Systematically test and refine programs using a range of test cases.
• 2-AP-14 Create procedures with parameters to organize code and make it easier to
reuse.
• 2-AP-11 Create clearly named variables that represent different data types and perform
operations on their values.
• 2-AP-10 Use flowcharts and/or pseudocode to address complex problems as
algorithms.
• 2-AP-12 Design and iteratively develop programs that combine control structures,
including nested loops and compound conditionals.
• 2-AP-13 Decompose problems and subproblems into parts to facilitate the design,
implementation, and review of programs.
• 2-AP-19 Document programs in order to make them easier to follow, test, and debug.
ISTE Standards
• 1.4.c Students develop, test and refine prototypes as part of a cyclical design process.
• 1.5.a Students formulate problem definitions suited for technology-assisted methods
such as data analysis, abstract models and algorithmic thinking in exploring and
finding solutions.
• 1.5.c Students break problems into component parts, extract key information, and
develop descriptive models to understand complex systems or facilitate problem-
solving.
• 1.6.b Students create original works or responsibly repurpose or remix digital
resources into new creations.
25