Aco pacMan Curriculum page of 32



Yüklə 215,5 Kb.
Pdf görüntüsü
səhifə4/7
tarix14.10.2017
ölçüsü215,5 Kb.
#4780
1   2   3   4   5   6   7

 

PacMan (Continued)

 

ACO PacMan Curriculum v2.0 



Page 11 of 32 

Scalable Game Design 



Important Note: If you forget to save the world, PacMan may not have any value set for S when 

the world is reloaded. 

 

 

Checking the Value of PacMan’s S agent attribute: 

 

1.

 



Double click on PacMan with the big arrow tool 

2.



 

You should see this window appear:

 

 

3.



 

If S is not visible in the window, it did not get set to a value yet. 

4.

 

Erase and redraw PacMan and then save the world. Then S should appear in the 



Attributes window. 

 

Step 2: 

Now, since the scent is diffusing, or spreading out, we need to find the average of the scent from 

the area around a ground agent or a pellet agent.  Think of it as the smells are coming in from the 

North, South, East and West.  The smell in the center, then, is the average of these four smells.  

How will you create that programmatically?   

 

Diffuse the scent using the pellet agents 

The pellet agent will have the behavior below; the single 

action is to calculate and store the average of the four 

surrounding agents’ agent attributes. Remember, you named 

the agent attribute “S” (for scent). 

 

The “set” action sets each pellet agent’s attribute “S” to the 



average of the attributes in the agents above, below, and on 

each side: 



S = 0.25*(s[up]+s[down]+s[right]+s[left]) 

 

 



 

 

 

Why do we 

multiply by 0.25? 

When you find the average 

of a set of numbers, you add 

them up and divide by the 

number of numbers.   

 

In this case, dividing by 4 is 



the same as multiplying by ¼ 

which equals 0.25

 

 



 

PacMan (Continued)

 

ACO PacMan Curriculum v2.0 



Page 12 of 32 

Scalable Game Design 



 

 

NOW…diffuse the scent across the ground by adding 

a rule to the ground agents! 

 

 

Match both the parentheses “(”  and the brackets “[” as shown in the equation.   

 

 



 

Step 3: For the Ghost to know which way to walk, he has to determine where the scent is the 

strongest.  We call this HILL CLIMBING.  If this were real 

life, he would smell up, smell down, smell left and smell 

right.  Wherever the smell was strongest, he would walk in 

that direction.  We need to program the Ghost to do this. 

 

We will create a METHOD for the Ghost to follow a set of 



rules.   

 

Take a look at the programming below.   



 

The rule in the while running method says  

“ONCE EVERY 0.5 seconds, follow the Chase PacMan 

procedure”.  

 

 

The rule in the Chase PacMan method says 



“IF the smell above you is greater than or equal to any of the other smells in different directions 

(down, left or right), THEN move up.” 

What do FIRE ALARMS have 

to do with coding? 

A METHOD is a set of rules 

with a name…rules to follow 

in a specific situation.  These 

are done when there is a 

specific call for them…much 

like the fire alarm means 

you follow different rules.  

You can create a METHOD 

by clicking the +Method 

button below an agent’s 

 

 



 

PacMan (Continued)

 

ACO PacMan Curriculum v2.0 



Page 13 of 32 

Scalable Game Design 



 

 

Now, add the three more rules to the Chase Pacman method so that the Ghost knows what 

to do if the smell down (S[down]) is greater. What if the smell to the left is greater?  What 

about the smell to the right? 

 

 

 

 

Run your game to see if the Ghost chases the PacMan!   

If it isn’t working, check the following: 

o

 



Erase and redraw PacMan, then save the world so the initial value of S 

is saved. 

o

 

In the Chaser’s rules, the method name must be the same in the 



message action and the black and yellow striped method name tag of 

the hill climbing method!  

o

 

 Use of parentheses “(“ and brackets “[“ in the ground and pellet agent 



rules must be correct. Check the picture of the ground agent’s equation 

2 pages ago and compare it to the equations in your ground and pellet 

agents.   

o

 



Check your hill climbing rules again and make sure that the arrows in 

the actions point the correct direction and that the conditions for each 

rule are correct.

 

 




 

PacMan (Continued)

 

ACO PacMan Curriculum v2.0 



Page 14 of 32 

Scalable Game Design 



 

 

More realistic Ghost catching 

Have you noticed how your Ghost will “catch” PacMan when it is next to him, or even diagonal from 

him. How could you now change your lose condition for when the ghosts catch PacMan to make the 

Ghosts only “catch” him when they are above him? Give it a try. 

 

Why didn’t this work before you added Hill Climbing? Discuss with a partner.



 

 

Shortcut for Hill Climbing 

AgentCubes Online has an even better way to handle the process of Hill Climbing. 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. 



 

There is a single action, hill climb, that replaces all the rules in the Chase PacMan method. 



 

 

It is possible to eliminate the Chase PacMan method by simply putting the hill climb action in the 

rule in the ghost’s while running method. 



Yüklə 215,5 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə