Create the quintessential arcade game of the 80’s! Wind your way through a maze while eating pellets. Watch out for the ghosts!
Created by: Susan Miller & Jeffrey Bush, University of Colorado, School of Education This curriculum has been designed as part of the Scalable Games Design project.
It was created using portions of prior work completed by Fred Gluck and Cathy Brand.
This material is based upon work supported by the National Science Foundation under Grant No. DRL-1312129
and CNS-1138526. Any opinions, findings, and conclusions or recommendations expressed in this
material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
Length of Activity:
Three to Five 30-45 minute lessons, although some students may advance more quickly
The students will apply the computational thinking patterns of user control, absorb, collaborative diffusion and Hill Climbing while creating a version of the 80’s arcade game, PacMan.
Computational Thinking Patterns:
Students are presumed to have the following skills.
Basic agent behavior including:
Ending the game
Part 1: Create a basic world with a PacMan and randomly moving ghosts
Part 2: Make the Ghosts chase the PacMan
Part 3: Enhance the game so that the game is over when the pellets are gone
Student Handout 4c: Challenge: Create Power Pellets
Student Handout 4d: Challenge: Move to next level
Algorithm a set of instructions designed to perform a specific task.
Attribute a variable belonging to an agent (such as scent) also called a Local Variable by computer scientists.
Brackets method of setting information apart using “[“ and “]”.
Broadcast controllers send out a message.
Ghost the agent that chases PacMan.
Collision an event wherein two agents run into each other.
Diffusion the process in which an attribute’s value (in this game, scent) is calculated based on the scent values of the neighboring agents.
Increment to increase by one.
Hill Climbing a specific form of searching/seeking technique, or algorithm, by which the seeking/searching agent uses information (the value of the scent agent attribute) embedded in the floor agent.
Method a named set of rules evaluated by an agent in response to a message.
PacMan the main character who eats the pellets as the user moves him around the world.
Parentheses method of setting information apart using ( and ).
Polling the process of asking agents to update a simulation property and then taking some action based on the value of the simulation property.
Propagate the spreading of the scent.
Randomly to occur in non-predictable ways.
Rule Order the order in which rules are placed for each agent.
Simulation Property A named value that all agents can see and update.
General Teaching Strategies1
The educational goal of these lessons is to learn and apply Computational Thinking Patterns in the context of a familiar game. Emphasis on these Computational Thinking Patterns is essential for student understanding.
These lessons are also designed to give students positive experiences with and perceptions of computer science. Research shows that students turn away from high school and college computer science courses if they perceive it as boring, unrelated to what matters to them, and hard. We hope to change that by providing a fun, relevant and accessible computer science experience where they can personalize their experience to make computer science about them.
Guided discovery is the central tenant of our curriculum. Direct instruction is sometimes used for aspects where students are learning the code for the first time; however, materials have been provided to ensure that students understand the programming concepts, as opposed to simply copying code.
Whenever possible, students should try to come up with the steps on their own or in small groups, when differentiation and more structure is needed, we have more structured materials available.
Student materials are available for each portion of the game design. These materials are intended to be used in addition to teacher materials, which provide prompts and discussion points.
Students may become frustrated with too little teacher support, THIS IS OK! A little frustration and moving at a slower pace is well worth the deeper conceptual understanding that comes with guided discovery.
Guided Discovery Process
Model the process rather than just giving students the answer. As a teacher, focus on explanations and discussions of WHY something works or doesn’t work and let the students figure out HOW to make it work.
Building the game on your own, before trying it with your class will enable you to see which steps may challenge or confuse your students.
Have students work through problems independently or in small groups. Ask directing questions or give helpful suggestions, but provide only minimal assistance and only when needed to overcome obstacles.
Group work is your friend! It is common for computer programmers to talk through problems with one another, and to use code snippets found from other programs and other programmers. Talking through coding problems enables students to think more critically about Computational Thinking Patterns, as well as the steps needed to solve a problem.
Additionally, seeing how others solved an issue with code helps students realize that problems often have multiple solution strategies, and that some solutions might be more effective than others. Also group work lets them see that they are not alone and that others have similar and different questions, struggles, inspirations and perspectives.
Recognize that programming is largely a process of trial and error, particularly when students are first learning. It is helpful to encourage this mindset with your students.
“What have you tried so far? Why didn’t it work?” is a great way to start any troubleshooting discussion.
Each project is designed to build on the prior one. Very little student support is provided where expertise has already been created. Conversely, material that is new has more support.
Be sure to talk through the building blocks (especially for PacMan in the area of diffusion and hill climbing) as these Computational Thinking Patterns will appear often in future games and simulations.
Encourage discussion and reflection on these Computational Thinking patterns. Small group or whole class discussion relating Computational Thinking patters to the outside world can be super productive.
Remember that conceptual understanding takes time, and it may be necessary to review these concepts multiple times, using different examples, so that all students can be successful.
Research shows that game design is associated with engaged students, and engaged students show higher levels on conceptual understanding. Allowing students to personalize their games aids in this engagement and motivation. Plus, it makes grading and reviewing games more fun for you.
Coding may be difficult for some students, and all students are likely to be frustrated at times when the code does not produce the expected results. Praise students for sticking with the troubleshooting process and encourage them to share what they learned with others.
Consider students who are ahead to the role of “code ambassadors” to walk around and help their peers with coding questions.
Be sure to communicate that the process is more important than the answer, and that coding of a project often takes time. Do not place pressure on your students to ‘hurry up’ and resort to giving them the code. The process of figuring it out on his/her own will result in much stronger conceptual understanding.
Note that there are many vocabulary words in this lesson that may be new for your students. Take time to define those words. Using the words in context often will reinforce their meaning for the students.
Students who need a challenge: Some students with more fluency in programming may finish this very quickly – be prepared for by having challenge activity materials ready in advance.
Students who need more assistance: Other students (especially those with no Frogger experience) may struggle a bit more. There are two options for differentiated instruction. Consider the needs of the student and the class as you decide which will work best.
Option 1: Pair a struggling student with an experienced student
Option 2: Provide student with a tutorial found on the Scalable Game Design Wiki2. Note that tutorials do not support independent thinking and should only be used when absolutely needed.
Vocabulary for ELL Students: : Generate, Absorb, Collision, Agent, Grotto, Depiction, Condition, Transport
Time management issues: While students can be more engaged when they design their own agents, some students can spend too much time on this design or find it frustrating.
Note: Two student packets are available. The STANDARD packet is for students with some basic knowledge of AgentCubes Online. The ALTERNATIVE packet is for students with NO prior AgentCubes Online experience who may need more support. The ALTERNATIVE packet should NOT be used for most students as it significantly reduces the active thinking processes.
Part 1 – Basic Game
Task your students with creating a new game. The basic features3 of the game are as follows:
The player controls Pac-Man through a maze, eating pellets. When all pellets are eaten, PacMan is taken to the next stage. Enemy ghosts roam the maze, chasing PacMan and trying to catch him. PacMan dies if an enemy touches him.
Give students time to discuss the features of this game in pairs or small groups. Have them share their responses together.
Consider these prompts:
How is this game similar to Frogger? Different than Frogger?
What are the skills that you learned from Frogger that you might need here?
What agents will we need?
How do you think you might be able to program the Ghosts to move randomly (and, what does “randomly” mean)?
What would make the game more challenging? Less challenging?
Once the students have had a few minutes to think through these prompts, provide them with Handout 1 (or display it for the class) so that they may begin work.
You may have some students who have never worked with AgentCubes Online. Use Handout 1A for those students.
The student pages can be found on page 3 of the STANDARD packet and page 3 of the ALTERNATIVE packet.
Student Handout 1:
Part I - Basic Game Initial Story: Create the quintessential arcade game of the 80’s! Wind your way through a maze while eating pellets. Watch out for the ghosts!
Create these Agents and the world:
PacMan Ghost with two depictions Pellet
Ground Wall 16x21 World with PacMan, Red & Green Ghosts Turn to your partner and discuss:
Do you want ground under the walls?
Why would it matter?
What could go wrong?
Create the following BEHAVIORS for your agents:
Step 1: Ghost:
Program the Ghost to move randomly on the ground.
Step 2: PacMan:
Make four rules so your agent moves in the right directions when each arrow key is typed just like the frog in Frogger (cursor control).
Step 3: Prevent your PacMan from going through walls
Work with the person next to you to figure out how to prevent the PacMan from walking into a wall. First come up with an if…then sentence to describe the behavior, then write/test the code.
Programming Tip: Use the NOT button below the method to add a NOT to a condition:
Scaffolding Tip: if they need help, encourage students to use if…and…then… sentences
Step 4: Enable your PacMan to ‘eat’ the pellets
Work with the person next to you to figure out how to have the PacMan eat the pellets.
The event that occurs when two
agents run into one another
IF the PacMan and the Pellet COLLIDE,
THEN the Pellet should ERASE
If the PacMan and the Ghost COLLIDE,
THEN the Game is OVER
Step 5: Game Over when the PacMan is next to a Ghost
Show a message so that the player knows why the game ended.
Very Important Tip: Put orin your Game over rule.
If you forget to do this, AgentCubes Online will do the game ending rule over and over until you are able to type the Return Key to click the OK on the dialog box and then immediately after use the mouse to click on the stop game button (the red square).
If you cannot click on the stop game button before the dialog box reappears, you must shut down and restart your computer and then restart AgentCubes Online.
Step 5: Test your game
Play your game by pressing the green arrow.
Does your PacMan move in all four directions?
Does your PacMan stay on the floor (and not go through walls)
Do the ghosts move randomly?
Does your PacMan eat pellets?
Does the game end when the PacMan is next to the Ghost?
Did you show a message to tell the player why the game ended?
Student Handout 1A:
Part I - Basic Game
Initial Story: Create the quintessential arcade game of the 80’s! Wind your way through a maze while eating pellets. Watch out for the ghosts!
Create these Agents and the world:
PacMan Ghost with two depictions Pellet
Ground Wall 16x21 World with PacMan, Red & Green Ghosts You are about to create your first game. Because this is new to you, we will give you some parts of the code. Be careful – you will have to find the patterns to create the rest of the code. If you get stuck, check in with a nearby student to get some help! Launch AgentCubes Online and Create a New Game
Go to https://www.agentcubesonline.com/
If you have an account, click on the Login link. If not, click on the Sign up link.
After you login, click on the blue “New project” link below your login name.
Name the Project
Name it PacMan and click Create project.
Create the agents for PacMan
Click on the +Agent button. Choose Inflatable Icon, then Miscellaneous, then “packy” to get a picture of PacMan. Type PacMan in the Agent Name box and click on the OK button.
To edit the drawing of PacMan, double click on the picture next to the agent’s name.
Use the drawing tools to edit the image or click on the Clear button to erase the picture.
Use the pencil and the color picker (black square in the center of the row of drawing tools on the left of the 2D drawing) to draw a new picture.
Click on the color picker to choose a new color.
Use the bucket tool to fill in the outline with color.
Click on the + to inflate your drawing into a 3D image.
Use the Ceiling slider to flatten it.
Click the upright box to stand PacMan up.
Pick front and back connected next to the word “surfaces” so PacMan has 2 sides.
Create the Ghost. If you go to the Miscellaneous category under Inflatable Icon, there is an agent named “ghosty”. You can edit the drawing and change the color or draw your own ghost.
Here is a PacMan Ghost like the ones in the original game.
Step 6 Make a second shape for your Ghost Click on the agent name, then click on the +Shape button at the bottom of the window. Give your new shape a name and click OK Then double click on the picture next to the name of the new shape and edit it.
Change the ghost color so this shape looks different from the original ghost.
Create the Wall Click +Agent
and name it Wall Select Cube and then pick a cube that you like.
Create the Ground Click +Agent and name it Ground Select Tile and pick one that you like.
Create the Pellet Click +Agent and name it Pellet.
Pick an inflatable icon, erase the picture, draw a pellet, use + to inflate & ceiling to flatten it.
Make a Level 1 World Click on the ‘+’ next to World When the New World box appears, type the name into the Name box. We recommend your world has at least 16 rows and 21 columns
Design your World Use the dotted rectangle tool
to place a rectangle of walls on the World. Use the same tool to place the walls of the maze. Then place ground where there is not maze. Place a rectangle of pellets on top of the ground. Use the pencil to draw single agents (PacMan, the Ghosts).
The Ghosts are the in the rectangular area with an opening.
Step 12 Save your World every time you make a change that you wish to keep.
When agents get moved around after playing or testing, click on the Reset button on the top bar of AgentCubes Online
to return to the saved version of your World!
Time to Create Behaviors for your Agents
Create an agent behavior Click on an agent and its behavior window will appear below the world. You are going to drop and drag the conditions (on the left) and the actions (on the right) to create the rules.
This rule says: IF the user presses the up arrow,
AND I Do NOT See a Wall in the up direction,
THEN my PacMan will move UP Tip: Click on the See condition, then the NOT button at the bottom of the window to make the NOT see condition. Create 3 more rules to make PacMan move right, left and down.
NOTE: Click on the rule you made, then click on the +RULE button at the bottom of the window to create each new rule.
Program the PacMan to eat the pellets.
First, take a moment to think about the PacMan and the Pellets When the PacMan collides with the Pellets, then the Pellet disappears, making it look like the PacMan ate it.
Take a look at this code when the Pellet sees the PacMan above or below him: It says…
IF I see a PacMan above or below me
THEN… erase myself (the pellet)
Play with adding a wait time before erase. What happens when wait before adding the pellet? Choose a wait time (or no wait time) that you think makes the eating behavior look the way you want it.
Program the Ghosts to move randomly
Click on the agent to add behaviors to that agent.
Should the ghost also move on the pellets? Or only on the floor? You decide and add rules accordingly!
Create rule to end the game when the PacMan is next to the Ghost Click on PacMan and add this rule. Note: You need a similar rule for each different Ghost shape.
This second Ghost rule says:
IF I am NEXT TO at least 1 PacMan
THEN, stop the simulation, show a message “You loose!” AND Reload the World
Very Important Tip: Put and/orin your Game ending rule. If you forget to do this, AgentCubes Online will do the game ending rule over and over until you are able to type the Return Key to click the OK on the dialog box and then immediately after use the mouse to click on the stop game button (the red square).
If you cannot click on the stop game button before the dialog box appears, you must close the browser window, then open a new browser window, go to AgentCubes Online, find your project and click on the edit button so it opens.
Teacher Instructions: Part 2 – Making the Ghost Chase the PacMan
In this part of the project, students will change the game to make it harder to win and more interesting. Instead of the Ghost moving randomly, the Ghost will now actually move toward the PacMan.
There are two Computational Thinking Patterns that will be included in this lesson:
Diffusion: The PacMan leaves a scent on the floor and the pellets. The scent will spread along the floor and pellets…this is the same as saying the floor and pellets will DIFFUSE the scent.
Hill Climbing: This is a particular way of ‘SEEKING’ a scent. This code makes the Ghost check the scent in all four directions, and follow the strongest scent.
These computational thinking patterns require AGENT ATTRIBUTES.
An Agent Attribute is a VARIABLE that can be used LOCALLY (by an individual agent). Note that AgentCubes Online also has Simulation Properties, or variables that can be used GLOBALLY (seen by ALL agents).
Talk to your students about the Ghost.
Consider these prompts:
Does the Ghost really ‘chase’ the PacMan? Why or why not?
Why would we change the game so that he really did chase the PacMan?
How could we change the game so that he could chase the PacMan?
[Give students a minute or two to discuss this with the person next to them. Then solicit their ideas. Remember that allowing students to discuss new concepts will aid their conceptual understanding of those concepts.]
Any of these videos can be used with the class to provide different views of how diffusion of scent and subsequent “hill-climbing” actions are used by different animals
[Say to your students] Imagine the PacMan emits a scent that the Ghost could smell…would that make it easier for the Ghost to find him? [Give the students an example they can relate to…bacon cooking in the kitchen, the smell of fresh coffee, sharks seeking blood in an ocean, etc.] This YouTube video explains how dogs use scent for search and rescue
This YouTube video of a MythBusters® segment shows how quickly sharks will respond to fish blood in a pool…students may be disappointed to see that the sharks do not respond to human blood with the same enthusiasm!
A more scientific explanation of how to determine if sharks can smell blood in the water.
Explain: In Part I of this project, the Ghost agent simply moved around randomly on the
ground. In this next phase of the design, the Ghost will intelligently seek the PacMan agent using
a computational thinking pattern called “Hill Climbing.”
Imagine the PacMan agent emits a scent. The scent will be propagated by the ground agents using a computational thinking pattern called “diffusion.” Diffusion is a fundamental physical process by which matter moves down a gradient from highest to lowest concentrations. The closer to the source of the scent, the greater its value. Hill climbing, which is an algorithm to find the direction in which the scent is strongest, is then used by the ghosts to chase the PacMan.
You may use the Diffusion PowerPoint Presentation to support understanding of these concepts4.
Students have a handout that accompanies this lesson. The following screen shots of code are for the teacher, but this information should not be shared fully with the student unless needed.
First, let’s make sure PacMan gives off a scent. To do this, we need to set the value of an attribute named “S” which stands for Scent. The scent attribute is associated with PacMan and is set when the PacMan is created by being drawn on the world. This guarantees that the scent attribute always has a meaningful value when the game starts running.
To set the value of s this way, we must click on the +Method button at the bottom of the AgentCubes Online window and make a new method. Click on the word “on” in the upper left corner of your new method and change it to “when-creating-new agent”.
This method of setting an agent attribute value ONLY works if the agent is erased and redrawn on the world after the when-creating-new-agent method is added to its rules.
Erase your PacMan agent and redraw it, then SAVE the world so that you save the new PacMan with s set to 1000.
If you forget to save the world, reloading the world will bring back your original PacMan that did not have an s attribute and the rest of the code that makes the ghosts chase PacMan will not work.
Check that PacMan’s S attribute is set to 1000 by double clicking on PacMan with the big arrow tool . PacMan’s agent attribute window will appear showing the value of s if it has been set.
Both the Pellet and the Background diffuse the scent so that the Ghosts can identify the direction of the strongest scent. The value of the agent attribute s belonging to any pellet or ground agent is the average of the values of the s agent attributes of the four surrounding agents:
s = 0.25*(s[left]+s[right]+s[up]+s[down])
Every 0.5 seconds, the Ghost will follow the scent by determining which direction is strongest, up, down, left or right. (Note, only the first of four rules is shown below).
More realistic Ghost catching
Have you noticed how your Ghost will “catch” PacMan when it is next to him, or even diagonal from him. Ask your students how they could now change the loose condition for when the ghosts catch PacMan to make the Ghosts only “catch” him when they are above him?
Ask them why this didn’t work before you added Hill Climbing and have them discuss with a partner.
Answer:when ghosts were moving randomly on the ground they would not move onto Pac-Man so the only way to make them “catch” him was by being next to him. Now that they move towards PacMan they can be on top. Changing the loose condition to”if stacked above or below PacMan” lets PacMan be next to Ghosts but then loose when he moves onto them or they move on to him.
Having students experiment with differences between staked above, below and above or below is a good critical thinking exercise Shortcut for Hill Climbing
AgentCubes Online has an even better way to handle the process of Hill Climbing which should be shared with students AFTER they understand the process of Hill Climbing. It is worth the time to create the Ghost’s Hill Climbing rules before using the shortcut to ensure that students understand the Hill Climbing computational thinking pattern. The use of the Hill Climbing action (see rule below) makes future extensions in the game, such as having the ghosts run from the PacMan, easier.
A learner may find the message action a helpful reminder of what the hill climb action does.
However, this behavior could be programmed in a single rule as follows:
This code is a shortcut for checking in all four directions (defined as Von Neumann’s Neighborhood…students could choose to check in eight directions using Moore’s Neighborhood!
You could then extend the learning by asking students to compare what happens when the ghosts search 4 directions around themselves versus searching 8 directions around themselves. Have the students do some tests to see which method catches PacMan more rapidly.
There are many resources available on the Scalable Game Design Wiki to support the computational thinking patterns of Diffusion and Hill Climbing. Take time before the lesson to check these out and determine how they might support your students in better understanding these concepts.
If students saved the game before the sent could diffuse throughout the world then the ghosts will move through walls at the start. This is a great opportunity for them to think about why they might be observing this behavior and what they can do to fix it.
Using a plot action to visualize S values:
Plotting can be used to look at values in simulations. PacMan offers an opportunity to introduce the concept to students.
Students can use the plot action to visualize the value of S in the ground agents and the pellets. The plot action will plot the values of S logarithmically in a 3D surface above the world. The peak on the plot represents the highest value of S in the world. The peak should be over PacMan since his S value is 1000.
Make a new rule at the bottom of PacMan’s while-running method and add the plot action:
To make the plot action work
This rule must be the last rule in PacMan’s while-running method! Why? What is the effect of the blank if condition?
Enter “S” for the name of the agent attribute.
Edit the row and column numbers so that values from the entire world are plotted. Remember that the world size for PacMan is 16 rows and 21 columns. Computer scientists always count from 0 to (Number – 1), in this case, rows 0 to 9 and columns 0 to 20. If you changed the default size, you must count from 0 to (New Size -1).
Pick a color for the plot that will show up against your background.
Change the elevation to 1.0.
Make sure to choose “logarithmically” as the plot type. This option works better than plotting linearly when some of the values are quite large and others are very close to zero.
Make a test world that just has a layer of ground agents, a layer of pellets, PacMan and one ghost.
Use the Rotate tool to tilt your world so that it is nearly horizontal and you can see the agents below the plot surface.
Run the game and move PacMan around. The peak, which represents the high value, will follow him. The ghost will move towards the high value (the peak).
Add a couple of rows of wall agents. What happens to the shape of the plot when the walls are added?
The walls have no S value so the plot gets some wrinkles and valleys.
Watch the ghost go around the walls following the increasing S values towards PacMan!
Now run your PacMan world with the complete maze on it and see what happens to the plot of the S values!
You may find that reloading the world does not erase the plot surface. Reload your browser window or click on the AgentCubes Online logo in the upper right corner of the AgentCubes Online window and click the edit button for your project again.
Figure 1. Plot of the S values with peak over PacMan.
Why is there a low spot over the ghost? Does the ghost have an S value?
Figure 2. Plot of the S values with some walls in the world.
PacMan and the ghost are under the peak. Why is there a valley over the wall?
Pass out Student Handout 2
The student pages can be found on page 7 of the STANDARD packet and page 11 of the ALTERNATIVE packet