bartleby

Videos

Textbook Question
Book Icon
Chapter 15, Problem 9PP

The goal for this Programming Project is to create a simple two-dimensional predator–prey simulation. In this simulation the prey are ants and the predators are doodlebugs. These critters live in a world composed of a 20 × 20 grid of cells. Only one critter may occupy a cell at a time. The grid is enclosed, so a critter is not allowed to move off the edges of the world. Time is simulated in time steps. Each critter performs some action every time step.

The ants behave according to the following model:

  • Move. Every time step, randomly try to move up, down, left, or right. If the neigh boring 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, then at the end of the time step (that is, 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, then no breeding occurs. Once an offspring is produced, an ant cannot produce an offspring until three more time steps have elapsed.

    The doodlebugs behave according to the following model:

  • Move. Every time step, if there is an adjacent ant (up, down, left, or right), then the doodlebug will move to that cell and eat the ant. Otherwise, the doodlebug moves according to the same rules as the ant. Note that a doodlebug cannot eat other doodlebugs.
  • Breed. If a doodlebug survives for eight time steps, then at the end of the time step it will spawn off a new doodlebug in the same manner as the ant.
  • Starve. If a doodlebug has not eaten an ant within the last three time steps, then at the end of the third time step it will starve and die. The doodlebug should then be removed from the grid of cells.

During one turn, all the doodlebugs should move before the ants do. Write a program to implement this simulation and draw the world using ASCII characters of “o“ for an ant and “X“ for a doodlebug. Create a class named Organism that encapsulates basic data common to both ants and doodlebugs. This class should have a virtual function named move that is defined in the derived classes of Ant and Doodlebug. You may need additional data structures to keep track of which critters have moved. Initialize the world with 5 doodlebugs and 100 ants. After each time step, prompt the user to press Enter to move to the next time step. You should see a cyclical pattern between the population of predators and prey, although random perturbations may lead to the elimination of one or both species.

Blurred answer
Students have asked these similar questions
Please read the thickened sentences below   In this game, one flyand three frogs are placed randomly on a board with the size 7x7.In each iteration, they move randomlywithin the board, and the simulation stops when one of the frogs eats the fly.Fly and frogs are essentially creatures that can move, make noise, and eat. Frogs can move up to 2squares in any direction, and flies can move up to 1. Frogs make the "Croak! Croak!" sound, and fliesmake "ZzzZZz!". Since frogs should not eat their kind, a function of "isEatable" should also beimplemented in decision making. A variable or function to check if the fly is alive is also required as aterminate condition for simulation.In each iteration, an 'f' character represents frogs' position on board, and an '*' character is used torepresent the position of fly. Java language please   I dont want the survival game starting with the code below I want in Java language and like in photos please #functions def GenerateRandomScene():     scenes =…
You are to write an Ant class to simulate Langton's Ant.  In this simulation, a virtual "ant" moves about a two-dimensional square matrix, whose spaces can be designated white or black, according to the rules below: If the ant is on a white space, it will turn right 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to black. If the ant is on a black space, it will turn left 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to white. When the ant hits the edge of the board and is going to go out of the bounds, wrap the board around so the ant will appear on the other side. The matrix is initially composed of all white spaces. The user will specify the size of the square matrix. The user will also specify the number of steps that the ant will move and the starting location and direction of the ant. After the simulation, the final board with the ant position will be displayed to…
In this game, one flyand three frogs are placed randomly on a board with the size 7x7.In each iteration, they move randomlywithin the board, and the simulation stops when one of the frogs eats the fly.Fly and frogs are essentially creatures that can move, make noise, and eat. Frogs can move up to 2squares in any direction, and flies can move up to 1. Frogs make the "Croak! Croak!" sound, and fliesmake "ZzzZZz!". Since frogs should not eat their kind, a function of "isEatable" should also beimplemented in decision making. A variable or function to check if the fly is alive is also required as aterminate condition for simulation.In each iteration, an 'f' character represents frogs' position on board, and an '*' character is used torepresent the position of fly.

Chapter 15 Solutions

Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY