PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 22 of 32
Scalable Game Design
Try setting up these rules now!
Count is not part of the continually running “While Running” method. It must be
a separate method since it only runs when called by the controller agent.
Check your program:
Here is the Controller agent behavior with the rule in the while running method that
makes the pellet agents count themselves and the new Checkwin method that ends the game if
PacMan has eaten all the pellets:
Here is the Pellet behavior with the new Count method that allows each Pellet agent to add 1 to
the Pellets simulation property:
PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 23 of 32
Scalable Game Design
The Bigger Picture: Communication between Agents
Polling introduces a technique that allows agents to create a complex behavior by cooperating: a
particular set of conditions cause one type of agent to send a message to another type of agent to
do a named method that contains a special set of rules. Count was the special method in the
polling example.
This type of communication between different types of agents can be used to create interesting
games. For example, if PacMan eats a power pill, then PacMan can broadcast a message to all
ghosts to “Get_Scared”. The Get_Scared method can change the ghosts’ appearance so that they
look different as they run away instead of chasing PacMan. Or the Traveler in Journey can fire
ice arrows at Chasers. When an ice arrow hits a Chaser, it sends the Chaser agent a message that
makes it freeze if it is unfrozen. Frozen chasers cannot move so the Traveler can collect the
treasures without being caught by the Chaser.
However, when the goal is just to count up the number of agents and stick the value in a
simulation property, AgentCubes Online has a simpler method for the controller to do this:
These two actions have been deleted from the controller’s while running method:
And replaced by this action:
The set action contains a specialized communication between the controller and the Pellet agents,
the agents_of_type(“Pellet”) message, which makes the pellets count themselves without the
need for us to code a separate count method.
You learned polling so that you would understand how to make different types of agents
communicate. But there is usually more than one solution to a programming problem so now you
have seen an alternate way to keep track of the number of any kind of agent.
PacMan
ACO PacMan Curriculum v2.0
Page 24 of 32
Scalable Game Design
Student Handout:
Troubleshooting Guide for PacMan Part III
Polling and Broadcast
Another Approach to Troubleshooting:
Make a quick check on how many Pellets are in the World:
Click on the gear button
on the upper right side of the AgentCubes Online window and
select “Show simulation Properties”. This window will appear:
The correct number of Pellets will not appear in this window until you have single-stepped (click
on the black triangle
next to the stop and go buttons) or briefly run the game. If your
programming is correct, the value of Pellets will decrease by 1 each time PacMan eats (erases) a
Pellet. When the value of Pellets is equal to 0, PacMan should win the game.
More detailed troubleshooting:
To determine what is happening in your game, it is helpful to look at how the simulation
property changes over time. Add the plot to window action to the rule in the Controller’s while
running method.
Common Problems:
1.
Is your Controller agent saved on the world?
2.
Did you type in @pellets whenever the simulation property was checked or
changed?
3.
Do you refer to the correct agents in each step?
PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 25 of 32
Scalable Game Design
Fill it out as it appears below:
In the plot to window action, you must name the simulation property to be plotted (Pellets),
name the window where it will appear (Pellets Plot), say what it represents (number of pellets)
and pick the color of the line that will appear on the graph.
Note that you must put “@” before the Pellets in the plot to window box because you are
checking the value of the simulation property Pellets!
The Pellets Plot window will appear as soon as the run button is clicked. Move the Pellets Plot
window somewhere where you can watch it while you run the game. In this window, you will
see a graph that shows you what’s happening ‘behind the scenes’ while you play the game.
This information will help you determine where a mistake may be. For example, if the number
of pellets never goes above 0, there is a problem with the method Count or the broadcast. If the
number of pellets goes to zero but the game doesn’t end, there is a problem with the game ending
rule in the Controller.
PacMan
ACO PacMan Curriculum v2.0
Page 26 of 32
Scalable Game Design
End of Unit Review Sheet – PacMan
(page 22 of the standard packet, page 28 of the alternative packet)
A)
The main computational thinking patterns we reviewed were:
1)
User Control: intentionally moving an agent.
a.
Using keyboard keys to move an agent.
b.
Example is moving the PacMan.
2)
Absorb: deleting agents on the screen.
a.
Use the “Erase” action in AgentCubes Online.
b.
Examples are erasing the pellets.
3)
Collision: when 2 agents collide (run into each other).
a.
Use the “See” condition
b.
Use the “Stacked” condition, OR
c.
Use the “Next to” condition.
d.
Examples are the eating pellets and losing the game when the ghosts
touch the PacMan.
B)
The main NEW computational thinking patterns we learned were:
1)
Diffusion: spreading the scent (smell) of an agent across a medium (like the
background). We use an agent attribute (S for smell) on the agent which should be
chased, and we diffuse the smell by setting the attribute on the background using
the average of the 4 smells around it,
S = .25 * (S[left]+S[right]+S[up]+S[down])
2)
Hill Climbing: following the highest value of the scent S. It only works if there is
diffusion done with it, so they go hand in hand. Example is the method we created
in the Ghost to move towards the agent next to him with the highest value of the
scent “S”.
3)
Broadcasting: is when we “shout out” to all agents of a certain type requesting
them to execute a specific method.
a.
Use the “broadcast” action in AgentCubes Online.
b.
Example is the broadcast by the Controller of the method “Count” to the
pellets so they will count themselves.
C)
Other concepts we covered in AgentCubes Online are:
1)
Troubleshooting the simulation, and considering rule order.
2)
Using sounds and messages in the game.
3)
Timing our actions using the “Once every” condition.
PacMan
ACO PacMan Curriculum v2.0
Page 27 of 32
Scalable Game Design
Student Handout 4a:
Challenge 1:PacMan Changes
Direction
Before your start this challenge:
You must have a complete basic PacMan game with a
PacMan who wins if he eats all the pellets and Ghosts who
either move randomly or chase the PacMan. The PacMan
loses if a Ghost gets too close. The world should have walls
that the Ghost and PacMan cannot cross.
Description of the Challenge:
PacMan will turn in the direction he’s heading.
Keep in mind there are multiple ways to solve this. Before reading ahead, try solving this
challenge your own way. Do you need new/different rules? New agents/shapes?
Option 1: Each PacMan follows the same rules so you need 3 new shapes instead of a new agent
Steps:
•
Select PacMan by clicking on him, then click on +Shape
•
Clear the picture and draw PacMan facing a different direction.
•
Use the change action with a dot in the middle because the means “change me to” so the
agent is able to change its shape.
Option 2: Instead of making new shapes, use the
“rotate to” command
Steps:
•
Edit the move behavior of PacMan to include a
“rotate to” command
•
The first of the three numbers in “rotate to” is
the rotation you want, a rotation of 180 degrees
will cause PacMan to turn in the opposite
direction.
Once you are done, TEST your program to confirm
that the PacMan’s shape changes when he changes
directions as he moves.
Change
Directions
Make the PacMan face
the direction he’s
heading
PacMan
ACO PacMan Curriculum v2.0
Page 28 of 32
Scalable Game Design
Student Handout 4b:
Challenge 2: PacMan Moves
Continuously
Before your start this challenge:
You must have a complete basic PacMan game with a PacMan
who wins if he eats all the pellets and Ghosts who either move
randomly or chase the PacMan. The PacMan loses if a Ghost
gets too close. The world should have walls that the Ghost and
PacMan cannot cross.
You must have 4 different shapes for the PacMan so that he
faces the direction he heads.
Description of the Challenge:
PacMan will continuously move in the direction he’s heading.
This challenge gets you started, but won’t give you all the code. Review the code below: It
says, when the right arrow is pressed AND I do not see a wall to the right, change to the
right-facing depiction. Once every 0.2 second, make me (the PacMan) do “move
continuously”.
When the move continuously method is called, the PacMan does the following:
If I see myself heading right AND I do not see a wall in the right direction, I will move right.
The effect of the rule in move continuously is to make PacMan keep moving whichever way
he is facing as long as there are no walls in the way.
Move
Continuously
Make the PacMan
move until the end of
the row of pellets
PacMan (Continued)
ACO PacMan Curriculum v2.0
Page 29 of 32
Scalable Game Design
There is still much to code:
Step 1:
Create code for all the other directions.
Step 2:
Test your program. (Hint: be sure your PacMan still leaves his scent everywhere.)
Click on the PacMan with the big arrow tool to select him and run the program.
Use the colors to decide which rules are true or false. In this case, the first rule is red,
which means the Right arrow was not pressed or a wall was in the way.
The next rule is green, which means every 0.2 seconds, the PacMan is being told to do
MoveDirection.
The method MoveDirection is green, which means that either or both conditions are true.
The PacMan does sees his right-facing shape AND does not see a wall, making the rule
TRUE, so PacMan will move one step to the right.
PacMan
ACO PacMan Curriculum v2.0
Page 30 of 32
Scalable Game Design
Student Handout 4c:
Challenge 3: Power Pellet
Before your start this challenge:
You must have a complete basic PacMan game with a PacMan
who wins if he eats all the pellets and Ghosts who either move
randomly or chase the PacMan. The PacMan loses if a Ghost
gets too close. The world should have walls that the Ghost and
PacMan cannot cross.
You must have different depictions of the PacMan so that he
faces the direction he heads, and he must move continuously.
Description of the Challenge:
•
Power Pellets are added to the world.
•
Power Pellets provide PacMan with the temporary ability to eat the enemies. The enemies
turn deep blue, and reverse direction.
This challenge gets you started, but won’t give you all the code.
To help you think this through…
•
You will need a new agent (Power Pellet)
•
Do you need a new agent or a new shape for the blue ghost?
•
When the ghost chases the PacMan, PacMan has a scent of 1000. What happens if he
has a scent of -1000? How can you set that new scent?
•
How can you limit the time that PacMan’s scent is -1000? Could you create a timer
agent that starts counting when it receives a message from PacMan that he ate a
Power Pellet? The timer agent should send a message back to PacMan when it is done
counting and it’s time for PacMan’s scent to return to 1000.
•
Hint: Use the hill climbing action rather than all the code for sniffing.
Power Pellets
Make a Power Pellet
that allows the
PacMan to eat the
ghosts.
PacMan
ACO PacMan Curriculum v2.0
Page 31 of 32
Scalable Game Design
Student Handout 4d:
Challenge 4: Next Level
Before your start this challenge:
You must have a complete basic PacMan game with a PacMan
who wins if he eats all the pellets and Ghosts who either move
randomly or chase the PacMan. The PacMan loses if a Ghost
gets too close. The world should have walls that the Ghost and
PacMan cannot cross.
You must have different depictions of the PacMan so that he
faces the direction he heads, and he must move continuously.
Description of the Challenge:
•
When the game ends, a new level appears, even harder than before!
This challenge gets you started, but won’t give you all the code.
To help you think this through…
•
Do you need a new agent? A new world?
•
When would a new level appear?
•
What code needs to change to make the new level appear?
You might have a rule like this:
How could you use this condition
and this action
to let the player move from a world
named “Level 1” to a world named “Level 2”?
Very Important Note: Add another rule that stops the simulation if the
player has won Level 2 so the game ends!
Next Level
Make a second level
for your PacMan!
Next
Level!
PacMan
ACO PacMan Curriculum v2.0
Page 32 of 32
Scalable Game Design
Appendix 1: Guidance on Ghost’s Random Movement
Making the ghosts move randomly on both pellets and ground is a challenge and
your students will come up with many different solutions that do not work.
Your students may make rules that look like these two examples:
What happens with the rules above if there are pellets on the ground? Can the ghost
move?
What happens in this case if the ghost is on the ground? Can the ghost move?
It helps to understand how timer events work. A “once every” condition can be
interpreted like this: “Has this amount of time passed since the last time this condition
was true?” Once the set amount of time has passed, the rule will remain true until the
“then” condition (move random in this case) has been preformed. Once that happens, the
condition is no longer true and it goes back to the start of the method. This means it will
never get to the second “once every” condition.
Both of these sets of rules will work correctly and allow Pac-
Man to move on pellets and ground if the once-every condition
has a different time for the second rule
Document Outline - Appendix 1: Guidance on Ghost’s Random Movement
Dostları ilə paylaş: |