![]() |
|
#1
|
|||
|
|||
i need help in C++ PLZcan anyone send me the coding 4 this problem:-
BUGS LIFE Problem: Create a simulation of doodlebugs life Description of the Problem: 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 20x20 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 tries to move up, down, left, or right. If the neighboring 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 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 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 step, then at the end of 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, 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. 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 population of predators and prey, although random perturbations may lead to the elimination of one or both species. Classes to be created: (use the concept of objects, classes, constructors and destructors with or without overloading, Data encapsulation, Data abstraction and Inheritance). Create an inheritance hierarchy to represent doodlebugs and ants that derived from Organism class..... can u PLZ send it to my email too, (just_4_u_686@yahoo.com).. thanks in advance |
|||
|
#2
|
|||
|
|||
Re: i need help in C++ PLZQuote:
Sure...how much money have you got? :davis: |
|
#3
|
|||
|
|||
Re: i need help in C++ PLZQuote:
This request is not consistent with the title of the thread. If you "need help in C++", as the title says, then I'm guessing that lots of people would like to try to help. You can ask specific questions, show what you have tried, etc., as the guidelines suggest: Guidelines for posting requests for help I believe that asking for "help in C++" is not the same thing as saying "can anyone send me..." Regards, Dave |
|
#4
|
|||
|
|||
Re: i need help in C++ PLZQuote:
There are some "challenges" to designing a system based on these requirements. Either the matrix must "know something" about the Organisms, or the Organisms must know something about the matrix. The behavioral specification required by the Organism definition suggests that "Move" needs to have an instance of the "matrix" available to it in order to accomplish the move. This obviously breaks the roles of responsibilities associated with the Organism derived classes. What does an Ant know about a matrix or moving in it? Even if we use interface inheritance to give Organism(s) an ability to move within the context of a matrix instance, we've tied all Organisms to that interface such that they can not exist outside of the matrix, or, at the very least, Move will be broken and must throw an error if there is no matrix instance. Also, since it is entirely inappropriate for each Organism (we should have 100 Ants!) to have an aggregated instance of the matrix (regardless of how we would then synchronize movements), we have to have some layer that knows Organism(s) and has a matrix instance but THEN must manage the interactions between the Organism(s) even though the Move operation is defined by the Organism base, which will then create a dependency loop in our "manager" code. In other words, the architecture available to implementing these requirements suggests VERY BAD implementation choice(s). The alternatives suggest that a prototypical Move operation is totally ridiculous inside of the Organism, even though it sounds salient at first glance. What does an Ant know about moving within the confines of a matrix? How are matrix interaction interfaces useful from within the Ant or Doodlebug instances? Even if we develop an "event driven" interface such that an "external" event produces a timestep interruption that forces moves, Organisms contained in the matrix would be required to have knowledge of their position in the matrix (access to matrix "get location" interfaces) and knowledge of the innerworkings of the matrix, which complete breaks the idea of encapsulating the matrix and separating the roles and responsibilities from Organism(s). Matrix should have a Move operation that takes an Organism instance reference as an argument. However, those elements of activity that are desired within the Organism that are pertinent to what happens as a result of moving (starving, eating ants, breeding, etc.) need to be pre/post "callbacks" as a result of the movement action produced by the Matrix encapsulation. For example, when Timestep fires a TimeInterval, Matrix would respond by moving each Organism and calling a "Organism::Moved" function with an argument such as "NULL" or "ANT_IN_LOCATION" ...etc. Based on the argument of the movement, the Organism would perform whatever appropriate activities were needed. However, even then, we've tied our ability to reproduce Organisms to some knowledge of what the "world" looks like (tied to the matrix impl) since we need to populate a cell nearby the moved-to cell. The alternative is that we tell the matrix that "we've bred" so that must distribute our "offspring" to available cells, which, unfortunately, means that we (as Organisms) do not know how many to reproduce since Matrix may disgard offspring that do not fit into adjacent cells based on occupany rules as stated in the requirements. So what we have is an "external driver" that must know the rules of occupation, movement and reproduction for every possible Organism and mangage the cellular population and movements through the interfaces exposed by the matrix. Matrix then becomes a relatively dumb container class, but worse, we have to implement its operations with return codes for successful and failed interactions. This impl suggests a "thin protocol" between the "driver" and the container such that we query the container (like an RDBMS) if it can accomplish the desired task, and if so, we perform the task, if not, we skip to the next subject involved in the operation. This is a bit like a transactional type of system, but it is very heavy since we must basically iterate through every cell to determine if an Organism instance is associated with the cell. Since the activities of a previous cell interaction may populate surrounding cells (ant bred, for instance), we have no real good way of iterating through the cells and therefore must work against a mapped cell population, that could easily change based on the interaction of previous cells (such as Doodlebug ate an Ant that was previously mapped in an adjacent cell). Since we know that Doodlebugs must move before the Ants, we can eliminate some of this by using a "dynamic" map, but then the matrix class complexity grows and it suggests that we maintain a copy, which limits scalability. I may be missing something obvious, but I see some definite drawbacks to this architecture. For instance, if the matrix moves a Doodlebug to a square with an Ant on it, then the matrix must know about the relationships that exist between Doodlebug and Ant such that the matrix removes the Ant AND informs the Doodlebug that it has just eaten (so that it does not starve). All of these implementation issues suggests that the architecture (as specified by the behavior specification found in Organism, Ant and Doodlebug) is "broken" in terms of good OOP. Basically, I'd redesign it such that it followed good OOP practices and accomplished the higher-level requirements associated with the simulation rather than a strict conformance to the behavioral specification requirement. Obviously, I'd caveat my entry with my explanation for departing from the strict guidelines. Given no other option, I'd refactor the base so that it wasn't so poorly designed :davis: |
Recent GIDBlog
Running Linux Programs at Boot Time by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The