For Windows
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int startp;
bool isadd=true;
int card[1000001];
int ys[15]={11,12,13,14,15,16,17,21,22,23,
1,31,41,42,43
};
int xg[5]={51,51,52,53,53};
int board[16];
void createcards(int n){
srand(time(0));
for(int i=1;i<=n;++i){
int res=rand()%100;
if(res<=70){
card[i]=ys[rand()%16];
}
else card[i]=xg[rand()%5];
}
}
inline int cardid(string cardname){
if(cardname=="A1") return 11;
if(cardname=="A2") return 12;
if(cardname=="A5") return 13;
if(cardname=="A9") return 14;
if(cardname=="A19") return 15;
if(cardname=="A49") return 16;
if(cardname=="A99") return 17;
if(cardname=="B1") return 21;
if(cardname=="B9") return 22;
if(cardname=="B19") return 23;
if(cardname=="C2") return 1;
if(cardname=="D2") return 31;
if(cardname=="E0") return 41;
if(cardname=="E49") return 42;
if(cardname=="E99") return 43;
if(cardname=="PASS") return 51;
if(cardname=="TURN") return 52;
if(cardname=="DOUBLE") return 53;
return -1;
}
inline int up(int p,int card){
if(card==1) return p*2;
if(card==11) return p+1;
if(card==12) return p+2;
if(card==13) return p+5;
if(card==14) return p+9;
if(card==15) return p+19;
if(card==16) return p+49;
if(card==17) return p+99;
if(card==21) return p-1;
if(card==22) return p-9;
if(card==23) return p-19;
if(card==31) return floor(p/2.0);
if(card==41) return 0;
if(card==42) return 49;
if(card==43) return 99;
return -1;
}
inline string cardname(int id){
if(id==11) return "A1";
if(id==12) return "A2";
if(id==13) return "A5";
if(id==14) return "A9";
if(id==15) return "A19";
if(id==16) return "A49";
if(id==17) return "A99";
if(id==21) return "B1";
if(id==22) return "B9";
if(id==23) return "B19";
if(id==1) return "C2";
if(id==31) return "D2";
if(id==41) return "E0";
if(id==42) return "E49";
if(id==43) return "E99";
if(id==51) return "PASS";
if(id==52) return "TURN";
if(id==53) return "DOUBLE";
return "";
}
struct player{
string name;
int card[4];
bool isdouble;
}pl[16];
int roundtot,nowround;
int playertot;
int cardtot,cardnow;
int p;
int nowp;
int lastuse;
bool hasdouble;
void reset(){
p=0;
isadd=true;
nowp=startp;
for(int i=1;i<=5;++i) pl[i].isdouble=false;
hasdouble=false;
}
void bd(){
cout<<endl<<endl<<"[Board]"<<endl<<endl;
for(int i=1;i<=playertot;++i){
cout<<"["<<"Player "<<i<<"] "<<board[i]<<endl;
}
}
bool turnp(int id){//true=failed
cout<<"Active: Player "<<id<<endl<<endl;
if(pl[id].isdouble) cout<<"[DOUBLE]"<<endl;
for(int i=1;i<=3;++i){
cout<<cardname(pl[id].card[i])<<" ";
}
cout<<endl;
string com;int res=0;
bool hasact=false;
while(!hasact){
cout<<"Choose one >>";
cin>>com;
if(com[0]>='1' and com[0]<='3'){
res=com[0]-'0';int pai=pl[id].card[res];
pl[id].card[res]=-1;
if(pai/10<=4){
p=up(p,pai);
if(p>=100) return true;
return false;
}
else{
if(pai==52){
isadd=1-isadd;
}
if(pai==53){
hasdouble=true;
}
pl[id].isdouble=false;
return false;
}
}
else{
res=cardid(com);
for(int i=1;i<=3;++i){
if(res==pl[id].card[i]){
pl[id].card[i]=-1;
hasact=true;
if(res/10<=4){
p=up(p,res);
if(p>=100) return true;
return false;
}
else{
if(res==52){
isadd=1-isadd;
}
if(res==53){
hasdouble=true;
}
pl[id].isdouble=false;
return false;
}
}
}
}
cout<<"Not Found!"<<endl;
}
return false;
}
void take(int id){
for(int i=1;i<=3;++i){
if(pl[id].card[i]==-1){
pl[id].card[i]=card[++cardnow];
break;
}
}
}
int main(){
cout<<"Totplayer >>";
cin>>playertot;
cout<<"Start Player >>";
cin>>startp;
createcards(1000000);
for(int i=1;i<=playertot;++i){
memset(pl[i].card,-1,sizeof pl[i].card);
for(int j=1;j<=3;++j){
take(i);
}
}
while(1){
nowround++;
cout<<"Round "<<nowround<<":"<<endl<<endl;
reset();
while(1){
if(hasdouble){
hasdouble=false;
pl[nowp].isdouble=true;
}
if(turnp(nowp)){
for(int i=1;i<=3;++i){
pl[nowp].card[i]=-1;
}
for(int i=1;i<=3;++i){
take(nowp);
}
startp=nowp;
system("cls");
cout<<"Round "<<nowround<<":"<<endl<<endl;
cout<<"Player "<<nowp<<" lost the game."<<endl;
board[nowp]--;
bd();
cout<<endl<<endl;
break;
}
else{
system("cls");
cout<<"Round "<<nowround<<":"<<endl<<endl;
cout<<"Actived. Now p="<<p<<endl<<endl;
take(nowp);
if(pl[nowp].isdouble){
pl[nowp].isdouble=false;
}
else if(isadd){
nowp++;
if(nowp>playertot) nowp-=playertot;
}
else{
nowp--;
if(nowp<1) nowp+=playertot;
}
}
}
}
}
For Linux
#include<bits/stdc++.h>
using namespace std;
int startp;
bool isadd=true;
int card[1000001];
int ys[15]={11,12,13,14,15,16,17,21,22,23,
1,31,41,42,43
};
int xg[5]={51,51,52,53,53};
int board[16];
void createcards(int n){
srand(time(0));
for(int i=1;i<=n;++i){
int res=rand()%100;
if(res<=70){
card[i]=ys[rand()%16];
}
else card[i]=xg[rand()%5];
}
}
inline int cardid(string cardname){
if(cardname=="A1") return 11;
if(cardname=="A2") return 12;
if(cardname=="A5") return 13;
if(cardname=="A9") return 14;
if(cardname=="A19") return 15;
if(cardname=="A49") return 16;
if(cardname=="A99") return 17;
if(cardname=="B1") return 21;
if(cardname=="B9") return 22;
if(cardname=="B19") return 23;
if(cardname=="C2") return 1;
if(cardname=="D2") return 31;
if(cardname=="E0") return 41;
if(cardname=="E49") return 42;
if(cardname=="E99") return 43;
if(cardname=="PASS") return 51;
if(cardname=="TURN") return 52;
if(cardname=="DOUBLE") return 53;
return -1;
}
inline int up(int p,int card){
if(card==1) return p*2;
if(card==11) return p+1;
if(card==12) return p+2;
if(card==13) return p+5;
if(card==14) return p+9;
if(card==15) return p+19;
if(card==16) return p+49;
if(card==17) return p+99;
if(card==21) return p-1;
if(card==22) return p-9;
if(card==23) return p-19;
if(card==31) return floor(p/2.0);
if(card==41) return 0;
if(card==42) return 49;
if(card==43) return 99;
return -1;
}
inline string cardname(int id){
if(id==11) return "A1";
if(id==12) return "A2";
if(id==13) return "A5";
if(id==14) return "A9";
if(id==15) return "A19";
if(id==16) return "A49";
if(id==17) return "A99";
if(id==21) return "B1";
if(id==22) return "B9";
if(id==23) return "B19";
if(id==1) return "C2";
if(id==31) return "D2";
if(id==41) return "E0";
if(id==42) return "E49";
if(id==43) return "E99";
if(id==51) return "PASS";
if(id==52) return "TURN";
if(id==53) return "DOUBLE";
return "";
}
struct player{
string name;
int card[4];
bool isdouble;
}pl[16];
int roundtot,nowround;
int playertot;
int cardtot,cardnow;
int p;
int nowp;
int lastuse;
bool hasdouble;
void reset(){
p=0;
isadd=true;
nowp=startp;
for(int i=1;i<=5;++i) pl[i].isdouble=false;
hasdouble=false;
}
void bd(){
cout<<endl<<endl<<"[Board]"<<endl<<endl;
for(int i=1;i<=playertot;++i){
cout<<"["<<"Player "<<i<<"] "<<board[i]<<endl;
}
}
bool turnp(int id){//true=failed
cout<<"Active: Player "<<id<<endl<<endl;
if(pl[id].isdouble) cout<<"[DOUBLE]"<<endl;
for(int i=1;i<=3;++i){
cout<<cardname(pl[id].card[i])<<" ";
}
cout<<endl;
string com;int res=0;
bool hasact=false;
while(!hasact){
cout<<"Choose one >>";
cin>>com;
if(com[0]>='1' and com[0]<='3'){
res=com[0]-'0';int pai=pl[id].card[res];
pl[id].card[res]=-1;
if(pai/10<=4){
p=up(p,pai);
if(p>=100) return true;
return false;
}
else{
if(pai==52){
isadd=1-isadd;
}
if(pai==53){
hasdouble=true;
}
pl[id].isdouble=false;
return false;
}
}
else{
res=cardid(com);
for(int i=1;i<=3;++i){
if(res==pl[id].card[i]){
pl[id].card[i]=-1;
hasact=true;
if(res/10<=4){
p=up(p,res);
if(p>=100) return true;
return false;
}
else{
if(res==52){
isadd=1-isadd;
}
if(res==53){
hasdouble=true;
}
pl[id].isdouble=false;
return false;
}
}
}
}
cout<<"Not Found!"<<endl;
}
return false;
}
void take(int id){
for(int i=1;i<=3;++i){
if(pl[id].card[i]==-1){
pl[id].card[i]=card[++cardnow];
break;
}
}
}
int main(){
cout<<"Totplayer >>";
cin>>playertot;
cout<<"Start Player >>";
cin>>startp;
createcards(1000000);
for(int i=1;i<=playertot;++i){
memset(pl[i].card,-1,sizeof pl[i].card);
for(int j=1;j<=3;++j){
take(i);
}
}
while(1){
nowround++;
cout<<"Round "<<nowround<<":"<<endl<<endl;
reset();
while(1){
if(hasdouble){
hasdouble=false;
pl[nowp].isdouble=true;
}
if(turnp(nowp)){
for(int i=1;i<=3;++i){
pl[nowp].card[i]=-1;
}
for(int i=1;i<=3;++i){
take(nowp);
}
startp=nowp;
cout<<"Round "<<nowround<<":"<<endl<<endl;
cout<<"Player "<<nowp<<" lost the game."<<endl;
board[nowp]--;
bd();
cout<<endl<<endl;
break;
}
else{
cout<<"Round "<<nowround<<":"<<endl<<endl;
cout<<"Actived. Now p="<<p<<endl<<endl;
take(nowp);
if(pl[nowp].isdouble){
pl[nowp].isdouble=false;
}
else if(isadd){
nowp++;
if(nowp>playertot) nowp-=playertot;
}
else{
nowp--;
if(nowp<1) nowp+=playertot;
}
}
}
}
}