#include<bits\stdc++.h>
#include<windows.h>
#include<time.h>
using namespace std;
int a,b,c,k,k2,kk,bb,t,tt,R,Blood=10,Illness=10,Time=500;
int bird[15001],ill[15001],blood[15001];
bool what[5001][15001],e,win;
void Color(int a)
{
if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED);
if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_GREEN);
if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_BLUE);
}
void Slow(char *p){ while(1){if(*p!=0)printf("%c",*p++);else break;Sleep(20);}}
void help(int a)
{
if(kk==1) return;
K:int r=rand()%k+1;
if(r==a||bird[r]==0) goto K;
if(bird[r]==1) ill[a]=0;
if(bird[r]==2&&bird[a]==3&&what[a-k2][r]==0) what[a-k2][r]=1;
if(bird[r]==3&&what[r-k2][a]==0) ill[a]=0;
}
void Cout(int a)
{
Color(bird[a]);
if(ill[a]==1) Color(4);
if(blood[a]==0) cout<<setw(3)<<'*';
else cout<<setw(3)<<blood[a];
if(ill[a]==1) help(a);
if(ill[a]==1) blood[a]--,bb=1;
if(blood[a]<=0&&ill[a]==1) bird[a]=0,ill[a]=0,kk--;
Color(0);
}
int main()
{
Color(0);
srand((unsigned)time(NULL));
Slow("\n 请输入傻瓜,骗子,斤斤计较者的数量(均不可超过5000):"); cin>>a>>b>>c;
Slow("\n 要改变血量等常量的默认值吗?(1-Yes 0-No):"); cin>>e;
if(e==1)
{
Slow("\n 请输入鸟们的初始血量:"); cin>>Blood;
Slow("\n 请输入鸟们的得病率(<100):"); cin>>Illness;
Slow("\n 请输入输出间隔时间(毫秒):"); cin>>Time;
}
for(int i=1;i<=a;i++) k++,k2++,bird[k]=1,blood[k]=Blood;
for(int i=1;i<=b;i++) k++,k2++,bird[k]=2,blood[k]=Blood;
for(int i=1;i<=c;i++) k++,bird[k]=3,blood[k]=Blood;kk=k;
Slow("\n 三秒钟之后开始模拟------ ");Sleep(500);
cout<<"3";Sleep(1000);cout<<" 2";Sleep(1000);cout<<" 1"<<endl;Sleep(1000);
for(int i=1;i<=k;i++) Cout(i);cout<<endl;Sleep(Time);
while(kk!=0)
{
t++;bb=0;
for(int i=1;i<=k;i++)
{
R=rand()%100+1;
if(R<=Illness&&bird[i]!=0) ill[i]=1;
Cout(i);
}cout<<endl;
if(bb==0) tt++;
else tt=0;
if(tt>30) {win=1;break;}
Sleep(Time);
}for(int i=1;i<=k;i++) Cout(i);cout<<endl;
if(win==0) Slow("\n 此种族灭亡了,存活时间为"),printf("%d。\n ",t);Sleep(500);
if(win==1) Slow("\n 如果不出意外,此种族会永远存活下去。\n ");Sleep(500);
system("pause");
return 0;
}