There are many ants in the simulation, each one running the code in the classes.
Right click the AntWorld class icon and choose Open editor. What are the screen settings for this simulation? What is a simulation? Why is this a simulation rather than a game?
Comment on the first line of the constructor AntWorld(). What is the resolution of the screen area? What is the size of a cell?
What is the purpose of the three similar functions in the constructor?
Comment on the origins of the foodCounter object.
Name and describe the purpose of three properties of the class Food.
What does the Food constructor do?
Comment on the link between the definition for Ant and the display of many ants running around the screen.
Describe what the Ant class achieves. What does an ant do in the simulation?
Start with act() - what does this do? Either walk() or headHome() will be called forever.
walk() is called if the ant has no food; headHome() is called when the ant has found food.
What does haveFood() do? This will lead to walk() because to begin with the ant has no food.
What does walk() do? foundLastPheromone is initialised to 0 and there are no pheromones released at this stage so this will lead the ant to randomWalk().
Evaluate randomChance(50).
What does adjustSpeed do? It includes a reference to capSpeed().
And then to move(): what does this do?
Then to checkFood() - what does this do? What if food is not found? What if food is found?
takeFood leads where? Where is takeSome? What does takeSome() do?
haveFood is now true so headHome() is called. What does this do? How is the direction home calculated? What does the ant do as it returns home? (Produces pheromones.)
The pheromone level accumulates until the maximum level is reached. When is a pheromone dropped?
The ant checks whether it has reached home: how does it know when it is home?
If the ant is home it drops its food with dropFood().
If the ant is not home it continues to produce pheromones.
If a pheromone has been dropped it can be found. If it is found then headAway() is called.
walk() checks for pheromones that may have been dropped. If a pheromone is not found then smellPheromone() is called. If a pheromone is found then foundLastPheromone is > 0 and move() is called.
When is a pheromone brought into the AntWorld?
What happens to a pheromone when it is produced?
What happens to the image when the pheromone's value is divisible by 4?
What are the default shape and colour of a pheromone?
How is the appearance of a pheromone altered when it has been dropped?
Create a new scenario with a black background. Draw this using methods from the GreenfootImage class.
Add stars as white dots to simulate space.
Add stars of different sizes.
This could serve as the background to a game based in space.
Try animating the stars to create the 'Star Trek' look.
Use the Animated Actor video to help you with this exercise.
Create an animated actor. Download the AnimatedActor class from the Helper Classes page and paste the code into a new class under actor. Create a sequence of images with a base name such as 'stickman', a file suffix such as 'jpg' (.png allows transparency) and a sequence of number after the base name (0, 1, 2...).