Simulation and Modeling
with the Advanced Placement GridWorld Case Study
Bob Allen and Laurie White
Mercer University
Abstract
Advanced Placement courses in Computer Science are currently using a case study named GridWorld that provides a fun and exciting visual environment where young people can "program" the behaviors of objects within a virtual world. This workshop will introduce GridWorld and demonstrate its suitability to motivate early involvement of young people to conduct research through simulation and modeling.
Flow of Workshop
- Our CS1 Background
- Reference Links for Workshop
- Introduction to GridWorld
- GridWorld Tools for Research
- A GridWorld Start in Research
- A CS1 Class Research(ish) Assignment
- Visualization of Queueing Models
- Thankyou!!
Our CS1 Background
- Bob
- Teaching CS1/CS2 approximately 20 years
- APCS Reader for 2 year
- Laurie
- Teaching CS1/CS2 approximately 25 years
- APCS Reader for 18 years
- Head of the APCS Development Committee
- We've both experimented with other "fun" things in CS-1, such as Alice, RoboCode, Greenfoot, and Karel the Robot.
- We started teaching with GridWorld in Spring 2007. We recently observed students using GridWorld as a visualization tool in some simple research.
Reference Links for Workshop
- AP Central's GridWorld:
- GridWorld Online Reference:
- This Presentation Online:
- Zip Folder of our Examples:
- Sun's Java:
Introduction to GridWorld
GridWorld consists of a "Grid" which is made up of "Locations." Each location can hold an "Actor." Each actor has a
method named "act()" that is called by the Grid for each "Step." The Grid, Actor, Location and much more is all
stored in the gridworld.jar. Confused? Lets take a look.
- Simple "Bug" example.
- A smarter Bug named "BoxBug."
- Hands-on: You get to make a "CircleBug!"
Introduction to GridWorld - Hands-on
You get to make a CircleBug!!!! A simple CircleBug
would alternate between just moving and turning-and-moving on each call to act().
- Open the Bugs folder.
- Edit the CircleBug.java file.
- Create an instance variable to help alternate the behavior.
- In the Constructor, initialize the instance variable.
- In the act() method, alternate moving and turning-and-moving.
- Save it, and then run "runCircleBugRunner".
Tools for Research
GridWorld was not designed for conducting research. It provides introductory students with a
visualization tool for representing things in the
world. The following tools can help students begin experimenting and conducting some simple research.
- Visualizing Mathematical Distributions
- Uniform,
- Normal and
- Exponential Distributions
- A GridWorld "Print String"
- Hands-on: Let's Roll Dice!
Tools for Research - Hands-on
Let's Roll Dice! First, lets look at rollDice.java which
just randomly rolls 1-5 die (command line argument). Your job is to create a Java program that
rolls the dice a large number of times and reports the frequency of each dice face that appears.
- Open the Distribution folder.
- Edit countDice.java.
- Add code to count the random die rolls (see comments)
- Add code to display the count of each dice face (see comments)
- Save it, and then run "runCountDice".
A Start in Research
In the spring of 2008 we had two students in our CS1 course that were highly motivated by GridWorld.
One started by making a pet mouse and modeling some mouse behavior. Another student saw the mouse and
researched maze generation.
- Pet Mouse
- Pet Mice
- Maze Generator
- Mouse in Maze
- Hands-on: Mouse eats cheese.
A Start in Research - Hands-on
Mouse eats cheese. You are going to let the mouse behave just
like in PetMouse, except for when it finds cheese. Once there is cheese in front of a mouse, it will
not move anymore (looks like it is eating the cheese).
- Open the PetMouse folder.
- Edit HungryMouse.java
- Leave canMove() and move() alone.
- In act() only move() if cheese is not in front of you. I'll give hints.
- Save and then run "runFeedMice"
A CS1 Class Research(ish) Assignment
A primary use of computer programs is to perform simulations. For this program, you will create a simulation of disease moving through a population. To do this, you will build three new objects that extend the Actor object. The complete assignment.
- Participant: this is similar to a Bug, except it moves left, right, or straight ahead at random, if the direction is not blocked.
- Subject: This is a Participant that can get infected. It will have a percentage chance of getting infected when it meets another infected Subject and a percentage chance of dying from the infection.
- Healer: This is a Participant that can heal infected participants. It will have a percentage chance of healing Subjects.
Visualization of Queueing Models
Qsim demonstrates the effects of arrival rates and service rates on queues.
runQsim S ST L AT T/F "Title"
- S = Number of Servers
- ST = Average Service Time
- L = Queue Length
- AT = Average Interarrival Time
- T/F = true means single queue, false means multiple queues
- Title = the Title in quotes