Chase and Run away

GUTS Computer Science Concepts
Chase and Run Away- using number lists
Week 3 2010
Goal: Students will make a simple program that has an agent that ‘chases’ and
another agent that ‘runs away.’
Objectives: Students will learn about Shared Number Variables (also called global
variables), lists, smell and how to put these concepts together to make an agent
chase another agent.


1. Students are to use Setup, Forever and a simple wiggle procedure to make 2 different agents move around, one agent will become the predator and the other agent the prey. There should only be one predator and several prey agents moving around.

2. The predator agent will now get a new procedure called Chase. This procedure will allow the agent to run after the other agents.

3. Start by getting out a procedure block for the Predator column and calling it Chase. In the Predator column, put a Shared Number Variable List and call it Prey Nearby.

4. This will allow the program to start making a list and keeping track of the items that fit the criteria for the list. The Chase procedure will start by setting this list with a certain criteria.

5. The next block that is used is the Smell List With block. This block will allow the agent to be able to detect the other agents on this list within a given radius.

6. Now the Chase Procedure will test to see if there is anything on the list (length of list > 0).

7. If there is a Prey on the list, the agent will Chase after the first prey, if not, the agent will just wander about until a Prey gets on the list. This is accomplished by setting the Predator’s heading towards the x & y coordinates of the first Prey on the list.

8. If there isn’t anyone on the list, then the Predator just moves around (the part connected to the ‘else.’)

9. After testing the list logic, the Predator will then move forward one.

10. Test the program. You should see the Prey just moving around for now, unaware of the Predator. The Predator will move around randomly until one of the Prey gets close enough and then will chase it. Eventually there won’t be anymore Prey because the Predator got them all (if you have a collision block that has the predator ‘eat’ the prey.


Implementing a procedure for the Prey to Runaway, is pretty much the same as Chase, except that once the Prey set their heading towards x & y coordinates of the Predator, they then turn around 180 degrees to head away from the Predator. Here’s the entire code.

Submitted by joshua on 27. July 2010 - 14:53