GOAL: Create a simple 2D simulation of ants crawling around. This is the first h
ID: 638475 • Letter: G
Question
GOAL: Create a simple 2D simulation of ants crawling around. This is the first half of a predator-prey simulation described in the textbook as Project #4, p.519 (at the end of Chapter 8). The second assignment this semester will be to add the doodlebugs.
The ants live in a world composed of a 20 x 20 grid of cells. Only one ant may occupy a cell at a time. The grid is enclosed, so an ant is not allowed to move off the edges of the grid. Time is simulated in time steps. Each ant performs some action every time step.
The ants behave according to the following rules:
Move. Every time step, randomly try to move up, down, left, or right. If the cell in the selected direction is occupied or would move the ant off the grid, then the ant stays in the current cell.
Breed. If an ant survives for three time steps (which all our ants will do in this first assignment since there are no doodlebugs to eat them), then at the end of the third time step (i.e. after moving), the ant will breed. This is simulated by creating a new ant in an adjacent (up, down, left, or right) cell that is empty. If there is no empty cell available, no breeding occurs. Once an offspring is produced, the ant cannot produce another offspring until three more time steps have elapsed.
Write a program to implement this simulation and draw the world using ASCII characters (say "A" for an ant and "." for an empty cell). So, it might look something like this (I've only drawn 12 rows instead of 20 here):
Initialize the world with 20 ants in random starting positions. After each time step, draw the world and prompt the user to press Enter to move to the next time step (like I did in HorseRacing).
Submit your Java code and a sample run showing 5 or 6 time steps of a simulation
Explanation / Answer
Here you go! This is the answer:
http://www.javaprogrammingforums.com/object-oriented-programming/22810-not-sure-what-logic-error-%5Bhelp%5D.html
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.