PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 19 of 32
Scalable Game Design
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?
PacMan
ACO PacMan Curriculum v2.0
Page 20 of 32
Scalable Game Design
Student Handout 3 Part 3:
Making the game more sophisticated – Polling and
Broadcast
In this enhancement to the PacMan project, the PacMan must “eat” all of the pellets in order to
win. Polling will tell us when all the pellets are gone and PacMan has won.
Polling uses a simulation property, also called a global variable by computer scientists, which
is a piece of information that all agents in the simulation or game may check or set if they have
the correct rules. A controller agent does the polling by sending out a message at intervals to all
the agents that must be counted. These agents respond by adding one to the simulation property.
The controller determines when all the pellet agents are gone and PacMan has won.
That’s what this programming will look like.
The Controller will say, “Pellet count starts at zero” (like the
classroom, no hands are up when the teacher asks who is still
working).
When the pellets ‘hear’ the Controller ask (broadcast) the
question, the pellets respond back (raise their hands).
The teacher has given an assignment to the class and wants to know if
everyone is finished. She says to the class, “Put your hand up if you are still
working.” Hands go up. She counts them – there are five students still
working. “Okay, put your hands down and keep working.”
A few minutes later, she does it again. She says to the class, “Put your hand
up if you are still working.” Hands go up. She counts them – there are two
students still working. “Okay, put your hands down and keep working.”
A few minutes later, she does it again. She says to the class, “Put your hand
up if you are still working.”
This time, no hands go up. “Everyone is done,
put your books away.”
Definition: Computer
scientists call the process of
making a decision by
sending a message to
multiple recipients and
checking responses polling.
PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 21 of 32
Scalable Game Design
The Controller counts the pellets. If the answer is more than zero, nothing happens and the game
continues. If the answer is zero (meaning that there are no remaining pellets on the board), the
game ends.
Step 1: Create the Pellets simulation
property as described in the green box
below.
Step 2: Create the Controller agent.
•
Use +Agent to make a Controller
agent and choose any image.
•
Place the Controller agent on top
of a wall in your PacMan world
and SAVE the world!
Step 3: Add a rule to the Controller
agent’s while running method.
1.
Set the number of pellets to zero.
(this is like the teacher saying
“hands down”)
Set @Pellets to zero
2.
Ask the pellets if they are still on
the world
Broadcast to Pellet agents to do
“Count”
3.
Check the number of pellets to see
if the game is done.
Send a Checkwin message to
myself.
Step 4: Program the Controller agent’s
Checkwin method.
•
If there are no pellets left, tell the
player that PacMan won and stop
the game.
Step 5: Program the Pellet Agent’s
Count method.
1.
Make
a new method for the Pellet
agent.
2.
Name it Count.
The name must exactly match the
name broadcast by the Controller.
3.
Add a rule with an action that sets
the value of “
@Pellets” to
“@Pellets + 1”.
This is how programmers add 1 to a
number.
How do Simulation Properties Work?
1.
Simulation properties may be
added, saved or deleted in the
Simulation Properties window.
2.
Open this window by clicking on
the gear button on the top right
side of the AgentCubes Online
window and choosing “Show
Simulation Properties”.
3.
Make the Pellets simulation
property by clicking on the +
button at the bottom of the
simulation properties window and
typing the name “Pellets”.
4.
Click on the Save button so that
the new simulation property is
saved!
5.
The value of a simulation property
can be changed or checked by any
of the agents in the game or world.
6.
All conditions and actions which
check or change the value of a
simulation property must place an
“@” before the simulation
property name.