#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
const int MaxMaps=20+10;
const int MaxMob=10000;
const int NewMobCont=1;
int GreenMobNumber,CntGreenMob;
int EatGreenMobNumber,CntEatGreenMob;
int RIPNumber,CntRIP;
long long Co2=1000,O2=1000,CntFood,tims;
int Maps[MaxMaps][MaxMaps];
int MobMaps[MaxMaps][MaxMaps];
struct GreenMob{//GreenFood :=)
int x,y,See,Speed;
int Time,MaxTime;
int Food,NewFoodSpeed;
bool Dead;
}Greens[MaxMob];
struct EatGreenMob{
int x,y,See,Speed;
int Time,MaxTime;
int Food,Eating,SartsEat;
bool Dead,Doeating;
}EatGreens[MaxMob];
struct RIP{
int x,y,Food;
int Time;
bool Eat;
}RIPs[MaxMob];
struct EatRIPMob{
int x,y,See,Speed;
int Time,MaxTime;
int Food,Eating,SartsEat;
bool Dead,Doeating;
}EatRIPMobs[MaxMob];
int srnd(int mood){
// Sleep(3);
srand(time(NULL));
return rand()%mood;
}
void GreenMobDo(){
for (int k=1;k<=CntGreenMob;++k){
GreenMob mob=Greens[k];
if (mob.Dead)continue;
--mob.Food;
CntFood+=mob.Food;
bool findeat;
for (int i=mob.x-mob.See;i<=mob.x+mob.See;++i){//findkill use next move
if (findeat==1)break;
for (int j=mob.y-mob.See;j<=mob.y+mob.See;++j){
if (MobMaps[i][j]==2){
findeat=1;
break;
}
}
}
if (findeat){
//which ai help me write this code?
}
else {//move
mob.Food-=mob.Speed;
bool findgo=0;
int go=srnd(4);
int gos[4][2]={{mob.Speed,0},{0-mob.Speed,0},{0,mob.Speed},{0,0-mob.Speed}};
for (int j=go;j<4;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){
findgo=1;
mob.x=nx;mob.y=ny;
break;
}
}
if (!findgo){
for (int j=0;j<go;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){
findgo=1;
mob.x=nx;mob.y=ny;
break;
}
}
}
}
//newfood
if (Co2>0){
Co2-=mob.NewFoodSpeed;
O2+=mob.NewFoodSpeed;
mob.Food+=mob.NewFoodSpeed;
}
mob.Time+=1;
int gos[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
for (int j=0;j<4;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (MobMaps[nx][ny]==2){//dead
mob.Dead=1;
break;
}
}
//somedead
if (mob.Time>=mob.MaxTime){
Greens[k].Dead=1;
GreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=mob.Food;
RIPs[CntRIP].Time=0;
continue;
//rip
}
if (mob.Food<=0){
//1952-1955
//rip
Greens[k].Dead=1;
GreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=5;
RIPs[CntRIP].Time=0;
continue;
//rip
}
if (srnd(100)==1){//GreenMob:what happend
Greens[k].Dead=1;
GreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=mob.Food;
RIPs[CntRIP].Time=0;
continue;
}
//new some mob
//ah
//r18xd
//hh
int NewGreenMobNeed=0;
for (int j=0;j<4;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){//new pro
GreenMob t;
t.Dead=0;
t.Food=10;
t.MaxTime=mob.MaxTime+srnd(6)-3;
t.NewFoodSpeed=mob.NewFoodSpeed+srnd(5)-3;
t.See=mob.See+srnd(2)-1;
t.Speed=mob.Speed+srnd(6)-3;
t.Time=0;
t.x=nx;t.y=ny;
NewGreenMobNeed=(t.MaxTime+t.NewFoodSpeed+t.See+t.Speed)*NewMobCont;
if (mob.Food>=NewGreenMobNeed+1){
// printf("New a GreenMob x=%d y=%d\n",nx,ny);
mob.Food-=NewGreenMobNeed;
++GreenMobNumber;
++CntGreenMob;
Greens[CntGreenMob]=t;
}
break;
}
}
MobMaps[mob.x][mob.y]=1;
Greens[k]=mob;
}
return ;
}
void EatGreenMobDo(){
for (int k=1;k<=CntGreenMob;++k){
EatGreenMob mob=EatGreens[k];
if (mob.Dead)continue;
// printf("a in the %d %d,its have %d food\n",mob.x,mob.y,mob.Food);
MobMaps[mob.x][mob.y]=2;
if (mob.Eating&&(mob.SartsEat+mob.Eating)<tims)continue;//pro is eating
if (O2>0){
Co2+=mob.Speed;
O2-=mob.Speed;
mob.Food-=mob.Speed;
}
CntFood+=mob.Food;
bool findeat;
for (int i=mob.x-mob.See;i<=mob.x+mob.See;++i){//findkill use next move
if (findeat==1)break;
for (int j=mob.y-mob.See;j<=mob.y+mob.See;++j){
if (MobMaps[i][j]==2){
findeat=1;
break;
}
}
}
if (findeat){
//which ai help me write this code?
}
else {//move
mob.Food-=mob.Speed;
bool findgo=0;
int go=srnd(4);
int gos[4][2]={{mob.Speed,0},{0-mob.Speed,0},{0,mob.Speed},{0,0-mob.Speed}};
for (int j=go;j<4;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){
findgo=1;
mob.x=nx;mob.y=ny;
break;
}
}
if (!findgo){
for (int j=0;j<go;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){
findgo=1;
mob.x=nx;mob.y=ny;
break;
}
}
}
}
mob.Time+=1;
//eat
int gos[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
for (int j=0;j<4;++j){
int nx=mob.x+gos[j][0];
int ny=mob.y+gos[j][1];//dfs?sweeter!
if (MobMaps[nx][ny]==1){//can eat
mob.Doeating=1;
mob.SartsEat=tims;
mob.Food+=30;
mob.x=nx;mob.y=ny;
break;
}
}
//somedead
if (mob.Time>=mob.MaxTime){
EatGreens[k].Dead=1;
EatGreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=mob.Food;
RIPs[CntRIP].Time=0;
continue;
//rip
}
if (mob.Food<=0){
//1952-1955
//rip
EatGreens[k].Dead=1;
EatGreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=5;
RIPs[CntRIP].Time=0;
continue;
//rip
}
if (srnd(100)==1){//GreenMob:what happend
EatGreens[k].Dead=1;
EatGreenMobNumber-=1;
//rip
++RIPNumber;
++CntRIP;
RIPs[CntRIP].x=mob.x;
RIPs[CntRIP].y=mob.y;
RIPs[CntRIP].Food=5;
RIPs[CntRIP].Time=0;
continue;
}
//new some mob
//ah
//r18xd
//hh
int NewEatGreenMobNeed=0;
int got[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
for (int j=0;j<4;++j){
int nx=mob.x+got[j][0];
int ny=mob.y+got[j][1];//dfs?sweeter!
if (nx<=MaxMaps-10&&nx>=1&&ny<=MaxMaps-10&&ny>=1&&MobMaps[nx][ny]==0&&Maps[nx][ny]==0){//new pro
EatGreenMob t;
t.Dead=0;
t.Food=10;
t.MaxTime=mob.MaxTime+srnd(6)-3;
t.See=mob.See+srnd(2)-1;
t.Speed=mob.Speed+srnd(6)-3;
t.Time=0;
t.Eating=mob.Eating+srnd(6)-3;
t.Doeating=0;
t.x=nx;t.y=ny;
NewEatGreenMobNeed=(t.MaxTime+t.See+t.Speed+t.Eating)*NewMobCont;
if (mob.Food>=NewEatGreenMobNeed+1){
//printf("New a EatGreenMob x=%d y=%d\n",nx,ny);
mob.Food-=NewEatGreenMobNeed;
++EatGreenMobNumber;
++CntEatGreenMob;
EatGreens[CntGreenMob]=t;
}
break;
}
}
EatGreens[k]=mob;
}
return ;
}
void RIPDo(){
for (int k=1;k<=RIPNumber;++k){
RIP mob=RIPs[k];
if (mob.Eat)continue;
MobMaps[mob.x][mob.y]=mob.Food;//new mob maps
++mob.Time;
//rip time?!
if (mob.Time>=20){
mob.Eat=1;//too old
--RIPNumber;
}
int findx[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
for (int i=0;i<4;++i){//pro eat bro
int fx=mob.x+findx[i][0];
int fy=mob.y+findx[i][1];//dfs?
if (MobMaps[fx][fy]==2){
mob.Eat=1;
--RIPNumber;
}
}
RIPs[k]=mob;
}
return ;
}
void Darw(){
system("cls");
printf("Made form MDTSF\n");
for (int i=1;i<=MaxMaps-10;++i)printf("--");
printf("\n");
for (int i=1;i<=MaxMaps-10;++i){
printf("|");
for (int j=1;j<=MaxMaps-10;++j){
if (Maps[i][j]==1)printf("* ");
else if (MobMaps[i][j]==1)printf("g ");
else if (MobMaps[i][j]==2)printf("e ");
else if (MobMaps[i][j]==3)printf("K ");
else if (MobMaps[i][j]==4)printf("o ");
else if (MobMaps[i][j]>4)printf("R ");
else printf(" ");
}
printf("|\n");
}
for (int i=1;i<=MaxMaps-10;++i)printf("--");
printf("\n");
printf("GreenMobNumber=%d\n",GreenMobNumber);
printf("EatGreenMobNumber=%d\n",EatGreenMobNumber);
printf("RIPNumber=%d\n",RIPNumber);
printf("O2=%d\nCo2=%d\nCntFood=%d\n",O2,Co2,CntFood);
}
void looping(){
for (int i=1;i<=MaxMaps-10;++i){
for (int j=1;j<=MaxMaps-10;++j){
MobMaps[i][j]=0;
}//clear
}
CntFood=0;
GreenMobDo();//mob do
EatGreenMobDo();
RIPDo();
Darw();
++tims;
string doin;
cin>>doin;
if (doin=="new"){//do something
system("cls");printf("new what?\n");cin>>doin;
if (doin=="GreenMob"){
system("cls");printf("where\n");int x,y;
cin>>x>>y;
GreenMob t;
t.Dead=0;
t.Food=10;
t.MaxTime=50;
t.NewFoodSpeed=5;
t.See=0;
t.Time=0;
t.x=x;
t.y=y;
++CntGreenMob;
++GreenMobNumber;
Greens[GreenMobNumber]=t;
}
if (doin=="EatGreenMob"){
system("cls");printf("where\n");int x,y;
cin>>x>>y;
EatGreenMob t;
t.Dead=0;
t.Food=10;
t.MaxTime=50;
t.Eating=0;
t.SartsEat=0;
t.Doeating=0;
t.Eating=2;
t.See=0;
t.Time=0;
t.x=x;
t.y=y;
++CntEatGreenMob;
++EatGreenMobNumber;
EatGreens[EatGreenMobNumber]=t;
}
if (doin=="*"){
system("cls");printf("where\n");int x,y;cin>>x>>y;
Maps[x][y]=1;
}
if (doin=="Co2"){
system("cls");printf("How Many?\n");int t;cin>>t;
Co2+=t;
}
if (doin=="O2"){
system("cls");printf("How Many?\n");int t;cin>>t;
O2+=t;
}
}
return ;
}
int main(){
while(1)looping();
return 0;
}//lots of code ,yeah?