Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP ME OUT HERE!!! I HAVE NO CLUE AS TO WHAT I AM DOING RIGHT NOW!! I AM

ID: 3761153 • Letter: P

Question

PLEASE HELP ME OUT HERE!!! I HAVE NO CLUE AS TO WHAT I AM DOING RIGHT NOW!! I AM NOT A GAME PROGRAMER AND DID NOT EXPECT THIS LEVEL OF DIFICULTY IN A BEGINNERS COURSE FOR C PROGRAMMING, I CANT FAIL THIS CLASS AND THIS ASSIGNMENT IS WORTH ALOT

Working in the C language, please help:

For this project, you will write a C program that will simulate and animate an ecosystem populated by two types of creatures: doodlebugs and ants. In this assignment, doodlebugs are the predators and ants are the prey. As the simulation runs, you should usually see the doodlebug population and the ant population grow and shrink in a cyclic manner; however, the built-in randomness many cause one or both creatures to die out completely.

Doodlebugs behaviour is as follows:

HUNT: if there is an ant in an adjecent direction (up,down,right,left) the doodlebugs moves up to where the ant is so that it eats it. If there are no ants adjacent to it, it randomly moves in any of the four direction unless it is at the edge of the grid, then it stays in place.

SPAWN: if the doodlebug survives for 8 days, it will spawn another doodlebug next to it uness there is no empty space.

STARVE: if the doodlebug is unable to eat an ant after three days have passed, it will starve and die, leaving an empty space where it was.

Ant behaviour is as follows:

MOVE: the ant moves in a randome directions (up,down,left,right) unless there are no empt spaces adjacent to it or is at the edge of the grid. It says in place.

SPAWN: if the ant survives 3 days, then it will create a new ant next to it unless and empty space does no exist

Ants should be represented as the character 'A' and doodlebugs as 'D'. Empty paces should be '.'

Likewise, doodlebugs move first, then ants.

this is on a 20x20 grid, with 100 ants and 5 doodlebugs in the beginning, using a single 2D array. Each entry in the array will be a C structure that captures the state of that location in the grid.

one time step is when all doodlebugs and ants have taken one step and the user presses enter

please help and comment, no C++, just C,
thank you

Explanation / Answer

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int a[20][20],p=0,q=0;
void step(int g,int h,int i,int &u,int &v);

class org
{
     public :
         int x,y,life;
};
class bug:public org
   {
     public:
        void birth(int e,int f)
         {
           x=e;
           y=f;
           life=0;
           a[e][f]=2;
           p++;
         }
        void move();
        void breed();
        void death()
         {
           a[x][y]=0;
         }
   }bugs[400];
   void bug::move()
    {
      int k=0,t1,t2,i;
       life++;
      for(i=0;i<4;i++)
       {
   step(x,y,i,t1,t2);
   if(a[t1][t2]==0)
   k++;
       }
      if(k>0)
       {
     if(k!=1)
       k=(rand()%k+1);
     for(i=0;i<4,k>0;i++)
      {
        step(x,y,i,t1,t2);
        if(a[t1][t2]==0)
        k--;
      }
     a[x][y]=0;
     a[t1][t2]=2;
     x=t1;
     y=t2;
     if(life>=3)
     {
       this->breed();
       life=0;
     }
       }
    }
   void bug::breed()
    {
      int i,k=0,t1,t2;
      for(i=0;i<4;i++)
       {
   step(x,y,i,t1,t2);
   if(a[t1][t2]==0)
    k++;
       }
  if(k!=1)
  k=(rand()%k+1);
  for(i=0;i<4,k>0;i++)
  {
   step(x,y,i,t1,t2);
   if(a[t1][t2]==0)
   k--;
  }
  bugs[p].birth(t1,t2);
    }
class dood:public org
{
    public:
       int steps;
       void birth(int e,int f)
       {
         x=e;
         y=f;
         life=3;
         steps=0;
         a[e][f]=1;
         q++;
       }
       void move();
       void breed();
       void death()
       {
        a[x][y]=0;
       }
}doodle[400];
void shiftb();
void shiftd();
void dood::move()
   {
     int k=0,t1,t2;
      steps ++;
     for(int i=0;i<4;i++)
      {
    step(x,y,i,t1,t2);
     if(a[t1][t2]==2)
    k++;
      }
     if(k==0)
      life--;
     else
      {
       if(k!=1)
    k=(rand()%k+1);
       for(int i=0;i<4,k>0;i++)
    {
     step(x,y,i,t1,t2);
     if(a[t1][t2]==2)
     k--;
    }
       life=3;
       for(int j=0;j<p;j++)
    {
     if((bugs[j].x==t1)&&(bugs[j].y==t2))
       { bugs[j].death();
         shiftb();
       }
    }
       a[this->x][this->y]=0;
       a[t1][t2]=1;
       this->x=t1;
       this->y=t2;

      }
       if(steps>=8)
      this->breed();
       if(life<=0)
    this->death();
   }
void dood::breed()
{
int i,k=0,t1,t2;
for(i=0;i<4;i++)
{
  step(x,y,i,t1,t2);
  if(a[t1][t2]==0)
  k++;
}
if(k>0)
{
  if(k!=1)
  k=(rand()%k+1);
  for(i=0;i<4,k>0;i++)
  {
   step(x,y,i,t1,t2);
   if(a[t1][t2]==0)
    k--;
  }
  doodle[q].birth(t1,t2);
}
}
void display()
{
int i,j;
char c;
system("cls");
for(i=0;i<20;i++)
{
    for(j=0;j<20;j++)
{
   if(a[i][j]==0)
    c='-';
   if(a[i][j]==1)
    c='x';
   if(a[i][j]==2)
    c='o';
   cout<<c<<" ";
}
    cout<<" ";
}
}
void step(int g,int h,int i,int &u,int &v)
{
u=g;
v=h;
if(i==0)
u--;
if(i==1)
v++;
if(i==2)
u++;
if(i==3)
v--;
if(u<0||v<0||u>19||v>19)
{
   u=g;
   v=h;
}
}
void shiftb()
{
int j,k;
if(p!=1)
for( j=0;j<p;)
{
   if(a[bugs[j].x][bugs[j].y]==0)
   {
  p--;
  for(int k=j;k<p;k++)
   bugs[k]=bugs[k+1];
   }
   else
    j++;
}
if(p==1)
if(a[bugs[0].x][bugs[0].y]==0)
    p--;
}
void shiftd()
{
int j,k;
if(q!=1)
for( j=0;j<q;)
{
   if(a[doodle[j].x][doodle[j].y]==0)
    {
q--;
for(int k=j;k<q;k++)
doodle[k]=doodle[k+1];
    }
   else
    j++;
}
if(q==1)
if(a[doodle[0].x][doodle[0].y]==0)
    q--;
}
void main()
{
system("cls");
int m,n,i,j,s,t;
char ch='y';
cout<<"enter how many doodles & bugs do u wany?"<<endl;
cin>>s>>t;
for(i=0;i<20;i++)
for(j=0;j<20;j++)
a[i][j]=0;
srand(time(0));
for(i=0;i<s;i++)
{
do {
m=rand()%20;
n=rand()%20;
    }while(a[m][n]!=0);
doodle[i].birth(m,n);
}
for(i=0;i<t;i++)
{
do{
m=rand()%20;
n=rand()%20;
    }while(a[m][n]!=0);
bugs[i].birth(m,n);
}
display ();
ch=cin.get();
while(true)
{
for(i=0;i<q;i++)
   doodle[i].move();
shiftd();
for(i=0;i<p;i++)
  bugs[i].move();

  display();
cout<<"Press Enter for next";
ch=cin.get();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote