UNO
很久以前的一个想法,终于实现出来了
忘了封出牌函数导致码就是屎山(
最好是放在 vscode 下运行。
有什么问题一定要说出来啊
For Windows
#include<bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
main(){while(1)new int;}
#endif
#ifndef ONLINE_JUDGE
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define color(i) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),(i))
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
// By: luobotianle
// black base
// This version runs better with vscode
// For Windows
/*
You can find Linux version at
https://www.luogu.com.cn/paste/q8ygzglm
Linux version is not so good as Windows
besause I don't know how to change color / pause / read keydown in Linux QAQ
*/
int seed=time(0);
mt19937 rnd(seed);
int n,rk,rem;
int ttttt=15;
bool flag=1;
void slowsay(const string &s,int t=ttttt*flag){
for(auto &i:s){
cout<<i;
Sleep(t);
}
}
void slowsay(int x,int t=ttttt*flag){
stack<char> s;
while(x){
s.push(x%10+'0');
x/=10;
}
while(s.size()){
cout<<s.top();
s.pop();
Sleep(t);
}
}
void appear(){
CONSOLE_CURSOR_INFO cursor_info={1,1};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void disappear(){
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
int calc(string s){
int i=0;
int x=0,f=1;
while(!isdigit(s[i])){
if(s[i]=='-')f=-f;
i++;
}
while(i<s.size()){
if(isdigit(s[i]))x=(x<<3)+(x<<1)+(s[i]^48);
i++;
}
return x;
}
map<char,string> name;
int color[5]={0x0c,0x09,0x0e,0x0a,0x0d};
struct card{
char num;//0~9 r(reverse) s(skip) d(draw 2) w(wild) W(wild draw 4)
int color;//0~3 red blue yellow green
int id;
bool operator < (const card &a)const{
return id<a.id;
}
}c[109];
void print(card c,char ch='\n',int col=-1){
if(col!=-1)color(color[col]);
else color(color[c.color]);
slowsay(name[c.num]);
cout<<ch;
color(0x07);
}
vector<card> used;
struct player{
int id,nxt,pre;
vector<card> c;
int maxn,maxcc=0,cnt[4];
int rnk;
}p[10];
int cnt=0;
void cset(char num){
if(num!='w'&&num!='W'){
for(int i=0;i<=3;i++){
cnt++;
c[cnt].num=num;
c[cnt].color=i;
}
}
else{
cnt++;
c[cnt].num=num;
c[cnt].color=4;
}
}
void setup(){
name['1']="1",name['2']="2",name['3']="3",name['4']="4",name['5']="5";
name['6']="6",name['7']="7",name['8']="8",name['9']="9",name['0']="0",
name['r']="reverse",name['s']="skip",name['d']="draw 2",name['w']="wild",name['W']="wild draw 4";
cnt=0;
for(char i='1';i<='9';i++){
for(int j=1;j<=2;j++){
cset(i);
}
}
cset('0');
for(int j=1;j<=2;j++){
cset('r');cset('s');cset('d');
}
for(int i=1;i<=4;i++)cset('W'),cset('w');
}
priority_queue<card> q;
void random(){
for(int i=0;i<used.size();i++){
used[i].id=rnd();
q.push(used[i]);
}
used.clear();
}
bool cmp(card a,card b){
if(a.color==b.color)return a.num<b.num;
return a.color<b.color;
}
bool cmp2(card a,card b){
if(a.color==b.color)return a.num>b.num;
return a.color<b.color;
}
void yourcard(){
slowsay("Your card:\n");
int tt=0;
cout<<tt<<" "<<"Draw a card\n";
sort(p[1].c.begin(),p[1].c.end(),cmp);
for(auto &i:p[1].c){
slowsay(++tt);cout<<" ";
print(i);
}
cout<<"\n";
}
void drawcard(int pp){
// cout<<q.size()<<"\n";
card cc=q.top();q.pop();
p[pp].c.push_back(cc);
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
if(q.empty())random();
}
void calmaxc(int pp){
memset(p[pp].cnt,0,sizeof(p[pp].cnt));
p[pp].maxcc=p[pp].maxn=0;
for(card cc:p[pp].c){
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
}
}
bool check(card a,card b,int cc){
if(a.color==4&&b.color==cc-1)return 1;
if(a.color==b.color)return 1;
if(a.num==b.num)return 1;
if(b.color==4)return 1;
return 0;
}
int nowp,f;
void start1(int n){
rem=n;
for(int i=1;i<=n;i++){
p[i].id=i;
p[i].pre=i-1;
p[i].nxt=i+1;
for(int j=1;j<=7;j++){
drawcard(i);
}
}
p[1].pre=n;
p[n].nxt=1;
slowsay("You're the player 1.\n");
slowsay("Your previous player: ");
cout<<p[1].pre<<"\n";
slowsay("Your next player: ");
cout<<p[1].nxt<<"\n";
slowsay("Your card:\n");
sort(p[1].c.begin(),p[1].c.end(),cmp);
int tt=0;
for(auto &i:p[1].c){
cout<<++tt<<" ";
print(i);
}
Sleep(1000);
card now=q.top();
q.pop();
// now={'d',0,0};
while(now.num=='w'||now.num=='W'){
now.id=rnd();
q.push(now);
now=q.top();
q.pop();
}
random();
if(now.num=='r')for(int i=1;i<=n;i++)swap(p[i].pre,p[i].nxt);
slowsay("\nThe first card is: ");
print(now);
Sleep(1000);
int nowp=1;
int cc=0;
int f=0;
if(now.num=='d'||now.num=='s')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
while(1){
system("cls");
for(int i=1;i<=n;i++){
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st ");
else if(p[i].rnk==2)slowsay("2nd ");
else if(p[i].rnk==3)slowsay("3rd ");
else{
cout<<p[i].rnk;
slowsay("th ");
}
color(0x07);
slowsay("Player ",0);
cout<<i;
}
else{
slowsay("Player ",0);
cout<<i;
slowsay(" remains ",0);
cout<<p[i].c.size();
slowsay(" card(s).",0);
if(p[i].c.size()==1){
color(color[0]);
slowsay("UNO",0);
color(0x07);
}
}
cout<<"\n";
}
cout<<"\n";
if(rem==2)puts("Only 2 people! Reverse equal to Skip! \n");
slowsay("Current card : ");
print(now,'\n',cc-1);
// cout<<now.num<<" "<<f<<"\n";
slowsay("\nNow:");
int ppp=1;
do{
slowsay(ppp);
slowsay(" -> ");
// cout<<ppp<<" -> ";
ppp=p[ppp].nxt;
}while(ppp!=1);
cout<<"1\n\n";
slowsay("Card remain : ");
slowsay(q.size());
cout<<"\n\n";
yourcard();
if(nowp!=1)sort(p[nowp].c.begin(),p[nowp].c.end(),cmp2);
calmaxc(nowp);
if(now.num=='s'&&f){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='r'&&f&&rem==2){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='d'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='d'||p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
Inv:
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
while(x<0||x>_t.size()){
slowsay("\nInvaild input.");
goto Inv;
}
if(x==0){
slowsay("Alright.\n");
goto draw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return;
}
goto no;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='d'||p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
if(p[nowp].c[i].num=='d')print(p[nowp].c[i],' ');
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto no;
}
}
}
draw:
while(f--)drawcard(nowp);
f=0;
no:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='W'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
if(x==0){
slowsay("Alright.\n");
goto draaw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return;
}
goto noo;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto noo;
}
}
}
draaw:
while(f--)drawcard(nowp);
f=0;
noo:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(nowp==1){
string xx;
int x=0;
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
while(x<0||x>p[1].c.size()){
tt:
system("cls");
slowsay("Invaild input.\n");
slowsay("Current card : ");print(now,'\n',cc-1);
yourcard();
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
}
if(x==0){
if(q.empty()){
system("cls");
slowsay("There is no more card!\n");
slowsay("Draw game.");
Sleep(2000);
return;
}
card ccc=q.top();q.pop();
p[1].c.push_back(ccc);
slowsay("You draw the card ");
print(ccc);
Sleep(1000);
if(check(now,ccc,cc))
{
slowsay("You can play the card you just drew. 1/0 for yes or no > ");
int flag;
cin>>xx,flag=calc(xx);
if(flag){
now=ccc;
p[1].c.pop_back();
if(now.color==4){
inv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx;
cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto inv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
if(q.empty())random();
}
else{
card tmp=p[1].c[x-1];
bool ff=check(now,tmp,cc);
if(!ff)goto tt;
now=tmp;
if(now.color==4){
invvvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvvv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
p[1].c.erase(p[1].c.begin()+x-1);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return;
}
}
}
else{
slowsay("It's player " );
cout<<nowp;
slowsay("'s turn.\n" );
random_shuffle(p[nowp].c.begin(),p[nowp].c.end());
bool ff=0;
for(int j=0;j<p[nowp].c.size();j++){
card i=p[nowp].c[j];
if(check(now,i,cc)){
now=i;
p[nowp].c.erase(p[nowp].c.begin()+j);
slowsay("Player " );
cout<<nowp;
slowsay(" played card " );
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
cout<<"\n";
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
ff=1;
break;
}
}
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
if(!ff){
slowsay("Player " );
cout<<nowp;
slowsay(" draw a card.\n" );
drawcard(nowp);
int siz=p[nowp].c.size();
if(check(now,p[nowp].c[siz-1],cc)){
now=p[nowp].c[siz-1];
p[nowp].c.pop_back();
slowsay("Player " );
cout<<nowp;
slowsay(" played the card which he just drew , " );
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
cout<<"\n";
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
}
Sleep(1500);
}
nowp=p[nowp].nxt;
}
}
int start(int n,int rm=-1){
if(rm==-1)rem=n;
else rem=rm;
for(int i=1;i<=n;i++){
if(p[i].rnk>0)p[i].rnk=0;
}
for(int i=1;i<=n;i++)for(int j=1;j<=7;j++){
drawcard(i);
}
// for(int i=1;i<=n;i++){
// cout<<i<<" "<<p[i].nxt<<" "<<p[i].pre<<"\n";
// }
slowsay("You're the player 1.\n");
slowsay("Your previous player: ");
cout<<p[1].pre<<"\n";
slowsay("Your next player: ");
cout<<p[1].nxt<<"\n";
slowsay("Your card:\n");
sort(p[1].c.begin(),p[1].c.end(),cmp);
// p[1].c.clear();
// p[1].c.push_back({'W',4,0});
// p[1].c.push_back({'W',4,0});
int tt=0;
for(auto &i:p[1].c){
cout<<++tt<<" ";
print(i);
}
Sleep(1000);
card now=q.top();
q.pop();
// now={'d',0,0};
while(now.num=='w'||now.num=='W'){
now.id=rnd();
q.push(now);
now=q.top();
q.pop();
}
random();
if(now.num=='r')for(int i=1;i<=n;i++)swap(p[i].pre,p[i].nxt);
slowsay("\nThe first card is: ");
print(now);
Sleep(1000);
nowp=1;
int cc=0;
f=0;
if(now.num=='d'||now.num=='s')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
while(1){
system("cls");
for(int i=1;i<=n;i++){
if(p[i].rnk==-1)continue;
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st ");
else if(p[i].rnk==2)slowsay("2nd ");
else if(p[i].rnk==3)slowsay("3rd ");
else{
cout<<p[i].rnk;
slowsay("th ");
}
color(0x07);
slowsay("Player ",0);
cout<<i;
}
else{
slowsay("Player ",0);
cout<<i;
slowsay(" remains ",0);
cout<<p[i].c.size();
slowsay(" card(s).",0);
if(p[i].c.size()==1){
color(color[0]);
slowsay("UNO",0);
color(0x07);
}
}
cout<<"\n";
}
cout<<"\n";
if(rem==2)puts("Only 2 people! Reverse equal to Skip! \n");
slowsay("Current card : ");
print(now,'\n',cc-1);
// cout<<now.num<<" "<<f<<"\n";
slowsay("\nNow:");
int ppp=1;
do{
slowsay(ppp);
slowsay(" -> ");
// cout<<ppp<<" -> ";
ppp=p[ppp].nxt;
}while(ppp!=1);
cout<<"1\n\n";
slowsay("Card remain : ");
slowsay(q.size());
cout<<"\n\n";
yourcard();
if(nowp!=1)sort(p[nowp].c.begin(),p[nowp].c.end(),cmp2);
calmaxc(nowp);
if(now.num=='s'&&f){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='r'&&f&&rem==2){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='d'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='d'||p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
Inv:
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
while(x<0||x>_t.size()){
slowsay("\nInvaild input.");
goto Inv;
}
if(x==0){
slowsay("Alright.\n");
goto draw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return 1;
}
goto no;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='d'||p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
if(p[nowp].c[i].num=='d')print(p[nowp].c[i],' ');
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
Sleep(500);
if(rk==1)return nowp;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return 0;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto no;
}
}
}
draw:
while(f--)drawcard(nowp);
f=0;
no:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='W'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
if(x==0){
slowsay("Alright.\n");
goto draaw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
return 1;
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return 0;
}
goto noo;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
Sleep(500);
if(rk==1)return nowp;
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return 0;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto noo;
}
}
}
draaw:
while(f--)drawcard(nowp);
f=0;
noo:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(nowp==1){
string xx;
int x=0;
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
while(x<0||x>p[1].c.size()){
tt:
system("cls");
slowsay("Invaild input.\n");
slowsay("Current card : ");print(now,'\n',cc-1);
yourcard();
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
}
if(x==0){
if(q.empty()){
system("cls");
slowsay("There is no more card!\n");
slowsay("Draw game.");
Sleep(2000);
return 0;
}
card ccc=q.top();q.pop();
p[1].c.push_back(ccc);
slowsay("You draw the card ");
print(ccc);
Sleep(1000);
if(check(now,ccc,cc))
{
slowsay("You can play the card you just drew. 1/0 for yes or no > ");
int flag;
cin>>xx,flag=calc(xx);
if(flag){
now=ccc;
p[1].c.pop_back();
if(now.color==4){
inv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx;
cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto inv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
if(q.empty())random();
}
else{
card tmp=p[1].c[x-1];
bool ff=check(now,tmp,cc);
if(!ff)goto tt;
now=tmp;
if(now.color==4){
invvvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvvv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
p[1].c.erase(p[1].c.begin()+x-1);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
return 1;
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return 0;
}
}
}
else{
slowsay("It's player " );
cout<<nowp;
slowsay("'s turn.\n" );
// random_shuffle(p[nowp].c.begin(),p[nowp].c.end());
bool ff=0;
for(int j=0;j<p[nowp].c.size();j++){
card i=p[nowp].c[j];
if(check(now,i,cc)){
now=i;
p[nowp].c.erase(p[nowp].c.begin()+j);
slowsay("Player " );
cout<<nowp;
slowsay(" played card " );
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
cout<<"\n";
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
ff=1;
break;
}
}
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
Sleep(500);
if(rk==1)return nowp;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
return 0;
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
if(!ff){
slowsay("Player " );
cout<<nowp;
slowsay(" draw a card.\n" );
drawcard(nowp);
int siz=p[nowp].c.size();
if(check(now,p[nowp].c[siz-1],cc)){
now=p[nowp].c[siz-1];
p[nowp].c.pop_back();
slowsay("Player " );
cout<<nowp;
slowsay(" played the card which he just drew , " );
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to " );
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
cout<<"\n";
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
}
Sleep(1500);
}
nowp=p[nowp].nxt;
}
}
int sum[20];
void clear(){
cnt=rk=rem=0;
setup();
used.clear();
for(int i=1;i<=108;i++) used.push_back(c[i]);
while(!q.empty())q.pop();
random();
for(int i=1;i<=n;i++)p[i].c.clear();
for(int i=1;i<=n;i++){
p[i].id=i;
p[i].pre=i-1;
p[i].nxt=i+1;
}
p[1].pre=n;
p[n].nxt=1;
for(int i=1;i<=n;i++){
if(p[i].rnk==-1){
p[p[i].pre].nxt=p[i].nxt;
p[p[i].nxt].pre=p[i].pre;
}
}
for(int i=1;i<=n;i++)p[i].maxcc=p[i].maxn=0;
for(int i=1;i<=n;i++)memset(p[i].cnt,0,sizeof(p[i].cnt));
}
namespace game1{
int main(){
appear();
system("cls");
clear();
slowsay("Please input the number of players(between 2 and 8) > ");
string ss;
cin>>ss,n=calc(ss);
while(n<2||n>8){
system("cls");
slowsay("Invaild input.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
cin>>ss,n=calc(ss);
}
ttttt=17-n;
slowsay("Seed : ",30);
slowsay(seed,30);
cout<<"\n\n";
Sleep(100);
slowsay("Game is starting..." ,100);
Sleep(200);
system("cls");
start1(n);
return 0;
}
}
namespace game2{
int goal;
int main(){
appear();
system("cls");
slowsay("Please input the number of players(between 2 and 8) > ");
string ss;
cin>>ss,n=calc(ss);
while(n<2||n>8){
system("cls");
slowsay("Invaild input.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
cin>>ss,n=calc(ss);
}
ttttt=17-n;
goal=n*100;
slowsay("Seed : ",30);
slowsay(seed,30);
cout<<"\n\n";
Sleep(100);
slowsay("Goal : ");
slowsay(goal);
slowsay("\n\n");
Sleep(200);
slowsay("Game is starting..." ,100);
Sleep(200);
system("cls");
while(1){
clear();
int win=start(n);
if(f>=2){
while(f--)drawcard(p[win].nxt);
}
Sleep(500);
system("cls");
slowsay("Card remain : \n");
int total=0;
for(int i=1;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(i==win){
color(color[4]);
slowsay("Winner ");
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
int now=0;
for(auto &j:p[i].c){
print(j,' ');
if(isdigit(j.num))now+=j.num-'0';
else if(j.color==4)now+=50;
else now+=20;
}
slowsay("\nPoints : ");
slowsay(now);
total+=now;
}
cout<<"\n\n";
}
slowsay("Total : ");
slowsay(total);
sum[win]+=total;
cout<<"\n\n";
slowsay("Now Points : \n");
int wp=0;
for(int i=1;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(sum[i]==0)cout<<"0";
else{
if(sum[i]>=goal-50)color(color[0]);
slowsay(sum[i]);color(0x07);
}
slowsay("\n");
if(sum[i]>=goal)wp=i;
}
cout<<"\n";
if(wp){
Sleep(500);
slowsay("The winner is Player ");
slowsay(wp);
slowsay(".\n");
break;
}
system("pause");
system("cls");
}
return 0;
}
}
namespace game3{
int rkk=0,remain;
int goal;
int main(){
appear();
system("cls");
slowsay("Please input the number of players(between 2 and 8) > ");
string ss;
cin>>ss,n=calc(ss);
while(n<2||n>8){
system("cls");
slowsay("Invaild input.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
cin>>ss,n=calc(ss);
}
ttttt=17-n;
slowsay("Seed : ",30);
slowsay(seed,30);
cout<<"\n\n";
Sleep(100);
slowsay("Deadline : ",30);
goal=n*100;
slowsay(goal,30);
cout<<"\n\n";
Sleep(200);
slowsay("Game is starting..." ,100);
Sleep(200);
system("cls");
remain=n;
goal=n*100;
clear();
while(1){
clear();
int win=start(n,remain);
if(f>=2){
while(f--)drawcard(p[win].nxt);
}
Sleep(500);
system("cls");
// for(int i=1;i<=n;i++)cout<<p[i].rnk<<" ";cout<<"\n"<<remain<<"\n";
slowsay("Card remain : \n");
int total=0;
for(int i=1;i<=n;i++){
if(p[i].rnk<0)continue;
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(i==win){
color(color[4]);
slowsay("Winner ");
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
int now=0;
for(auto &j:p[i].c){
print(j,' ');
if(isdigit(j.num))now+=j.num-'0';
else if(j.color==4)now+=50;
else now+=20;
}
slowsay("\nPoints : ");
slowsay(now);
sum[i]+=now;
}
cout<<"\n\n";
}
// sum[2]+=1000;
// slowsay("Total : ");
// slowsay(total);
// sum[win]+=total;
// cout<<"\n\n";
slowsay("Now Points : \n");
int wp=0;
for(int i=1;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
// cout<<i<<" "<<sum[i]<<" "<<goal<<" ovo\n";
if(p[i].rnk<0||sum[i]>=goal){
color(color[4]);
slowsay("OUT\n");
color(0x07);
if(sum[i]>=goal){
p[i].rnk=-1;
// cout<<i<<" "<<p[i].pre<<" "<<p[i].nxt<<"--\n";
p[p[i].pre].nxt=p[i].nxt;
p[p[i].nxt].pre=p[i].pre;
remain--;
rkk++;
sum[i]=-1;
}
continue;
}
if(sum[i]==0)cout<<"0";
else{
if(sum[i]>=goal-50)color(color[0]);
slowsay("-"),slowsay(sum[i]);
}
color(0x07);
slowsay("\n");
}
cout<<"\n";
if(p[1].rnk==-1){
slowsay("You lose. You got rank ");
slowsay(n-rkk+1);
slowsay(".\n\nGood luck next time!\n");
return 0;
}
// cout<<remain<<"--\n";
if(remain==1){
Sleep(500);
slowsay("You win. Congratulations!\n");
break;
}
system("pause");
system("cls");
}
return 0;
}
}
void rules(){
system("cls");
slowsay("UNO is a multi-player card game.\n\n");
slowsay("There are 108 cards in total;\n");
slowsay("Every card has a color and a name.\n");
slowsay("At beginning, every player will get 7 cards, and the first to play all the cards is the winner.\n");
slowsay("You can play a card, only when the color OR the name is same as the last card.\n\n");
Sleep(500);
slowsay("There are four color, as red, blue, yellow and green.\n");
slowsay("First, there are 72 number card, from 0 ~ 9.\n");
slowsay("For 1 ~ 9, each color gets two of them; And for 0, there are only one.\n\n");
Sleep(500);
slowsay("There also have some special card : Draw 2 , Reverse , Skip;\n");
slowsay("2 of them for each color.\n");
slowsay("Draw 2 can make your next player draw two cards and skip him;\n");
slowsay("Skip can skip your next player;\n");
slowsay("Reverse can reverse the order of playing cards, from clockwise to anticlockwise or from anticlockwise to clockwise.\n\n");
Sleep(500);
slowsay("What's more, there are some powerful cards : wild\n");
slowsay("The doesn't have color, and they can be played at any time.\n");
slowsay("Card \"Wild\" can change color to what you want;\n");
slowsay("And \"Wild Draw 4\" can change color to what you want AND draw your next player 4 cards and skip him.\n\n");
Sleep(500);
slowsay("If you don't have a card to play or don't want to play a card, you should draw a card;\n");
slowsay("You can play the card you just drew, if it is suitable;\n");
slowsay("However, you shouldn't play another card after you drew a card.\n\n");
Sleep(500);
slowsay("Draw 2 and Wild Draw 4 can be added up.\n");
slowsay("e.g. if your previous player played a Draw 2, you can play another one, and your next player need to draw 4 cards;\n");
slowsay("You can use Wild Draw 4 to add up Draw 2, However, it is not allowed to do the opposite.\n\n");
Sleep(500);
slowsay("Mode \"Point Race\" : \n");
slowsay("In this mode, each cards have a point;\n");
slowsay("Number card is the number on it, Draw 2/Skip/Reverse is 20 Points each, and Wild is 50;\n");
slowsay("When a game is end, the winner will gain the sum of the remaining card points of others;\n");
slowsay("The first to reach the goal is the final winner.\n\n");
Sleep(500);
slowsay("Mode \"Knockout\" : \n");
slowsay("In this mode, each cards have a point, same as the \"Point Race\" mode;\n");
slowsay("However, when a game is end, everyone except will decrease the sum of the remaining card points of themselves;\n");
slowsay("When a player's point is less than Deadline, he is out;\n");
slowsay("Try to become the last standing man!\n\n");
Sleep(500);
slowsay("Mode \"Fight to the End\" : \n");
slowsay("In this mode, after one player wins, the rest will continue playing until the last one;\n");
slowsay("So don't be the last one!\n\n");
system("pause");
}
int main(){
int now=0;
while(1){
disappear();
system("cls");
printf("Welcome to the UNO.\n");
printf("You can use ↑/↓or w/s to move and Enter to choose.\n\n");
if(now==0)color(0x87);
printf("Rules\n");color(0x07);
if(now==1)color(0x87);
printf("Point Race\n");color(0x07);
if(now==2)color(0x87);
printf("Knockout\n");color(0x07);
if(now==3)color(0x87);
printf("Fight to the End\n");color(0x07);
if(now==4)color(0x87);
printf("Open/Close fast mode\n");color(0x07);
printf("\n");
if(now==0)printf("View the basic rules of UNO.\n");
if(now==1)printf("Get the score to achieve the goal as soon as possible!\n");
if(now==2)printf("Strive to survive and eliminate others!\n");
if(now==3)printf("Just run...Do your best!\n");
if(now==4)printf("Open/Close fast mode\n");
while(1){
if(kbhit()){
char c=_getch();
if(c=='w'||c==72){
if(now!=0)now--;
break;
}
if(c=='s'||c==80){
if(now!=4)now++;
break;
}
if(c=='\r'){
if(now==0)rules();
if(now==1)game2::main(),system("pause");
if(now==2)game3::main(),system("pause");
if(now==3)game1::main(),system("pause");
if(now==4){
flag^=1;
slowsay("Fast mode : ");
if(flag)slowsay("Off\n");
else slowsay("On\n");
Sleep(1000);
}
break;
}
}
}
}
return 0;
}
#endif
Linux 版本不是很全,因为我不知道咋读键盘输入
而且我也不是很会改颜色以及做 Sleep 之类的
最好也是放在 vscode 下运行
宿舍玩法(战至最后一个人)
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
#ifdef ONLINE_JUDGE
main(){while(1)puts("Output Limit Exceeded");}
#endif
#ifndef ONLINE_JUDGE
// By: luobotianle
// black base
// This version runs better with vscode
// For Linux
/* You can find Windows version at
https://www.luogu.com.cn/paste/58bfxt35
*/
int seed=time(0);
mt19937 rnd(seed);
int n,rk,rem;
int ttttt=15;
void Sleep(int x){usleep(x*1000);}
void slowsay(const string &s,int t=ttttt){
for(auto &i:s){
cout<<i;
fflush(stdout);
Sleep(t);
}
}
void slowsay(int x,int t=ttttt){
stack<char> s;
while(x){
s.push(x%10+'0');
x/=10;
}
while(s.size()){
cout<<s.top();
fflush(stdout);
s.pop();
Sleep(t);
}
}
int calc(string s){
int i=0;
int x=0,f=1;
while(!isdigit(s[i])){
if(s[i]=='-')f=-f;
i++;
}
while(i<s.size()){
if(isdigit(s[i]))x=(x<<3)+(x<<1)+(s[i]^48);
i++;
}
return x;
}
map<char,string> name;
int color[5]={0x0c,0x09,0x0e,0x0a,0x0d};
struct card{
char num;//0~9 r(reverse) s(skip) d(draw 2) w(wild) W(wild draw 4)
int color;//0~3 red blue yellow green
int id;
bool operator < (const card &a)const{
return id<a.id;
}
}c[109];
void print(card c,char ch='\n',int col=-1){
int cc=(col==-1?c.color:col);
if(col!=-1)cout<<"\033[35m";
if(cc==0)cout<<"\033[31m";
if(cc==1)cout<<"\033[34m";
if(cc==2)cout<<"\033[33m";
if(cc==3)cout<<"\033[32m";
slowsay(name[c.num]);
cout<<ch;
cout<<"\033[0m";
}
vector<card> used;
struct player{
int id,nxt,pre;
vector<card> c;
int maxn,maxcc=0,cnt[4];
int rnk;
}p[10];
int cnt=0;
void cset(char num){
if(num!='w'&&num!='W'){
for(int i=0;i<=3;i++){
cnt++;
c[cnt].num=num;
c[cnt].color=i;
}
}
else{
cnt++;
c[cnt].num=num;
c[cnt].color=4;
}
}
void setup(){
name['1']="1",name['2']="2",name['3']="3",name['4']="4",name['5']="5";
name['6']="6",name['7']="7",name['8']="8",name['9']="9",name['0']="0",
name['r']="reverse",name['s']="skip",name['d']="draw 2",name['w']="wild",name['W']="wild draw 4";
cnt=0;
for(char i='0';i<='9';i++){
for(int j=1;j<=2;j++){
cset(i);
}
}
for(int j=1;j<=2;j++){
cset('r');cset('s');cset('d');
cset('W');cset('w');
}
}
priority_queue<card> q;
void Random(){
srand(time(NULL));
for(int i=0;i<used.size();i++){
used[i].id=rnd();
q.push(used[i]);
}
used.clear();
}
bool cmp(card a,card b){
if(a.color==b.color)return a.num<b.num;
return a.color<b.color;
}
bool cmp2(card a,card b){
if(a.color==b.color)return a.num>b.num;
return a.color<b.color;
}
void yourcard(){
slowsay("Your card:\n");
int tt=0;
cout<<tt<<" "<<"Draw a card\n";
sort(p[1].c.begin(),p[1].c.end(),cmp);
for(auto &i:p[1].c){
slowsay(++tt);cout<<" ";
print(i);
}
cout<<"\n";
}
void drawcard(int pp){
// cout<<q.size()<<"\n";
card cc=q.top();q.pop();
p[pp].c.push_back(cc);
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
if(q.empty())Random();
}
void calmaxc(int pp){
memset(p[pp].cnt,0,sizeof(p[pp].cnt));
p[pp].maxcc=p[pp].maxn=0;
for(card cc:p[pp].c){
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
}
}
bool check(card a,card b,int cc){
if(a.color==4&&b.color==cc-1)return 1;
if(a.color==b.color)return 1;
if(a.num==b.num)return 1;
if(b.color==4)return 1;
return 0;
}
void start(int n){
rem=n;
for(int i=1;i<=n;i++){
p[i].id=i;
p[i].pre=i-1;
p[i].nxt=i+1;
for(int j=1;j<=7;j++){
drawcard(i);
}
}
p[1].pre=n;
p[n].nxt=1;
slowsay("You're the player 1.\n");
slowsay("Your previous player: ");
cout<<p[1].pre<<"\n";
slowsay("Your next player: ");
cout<<p[1].nxt<<"\n";
slowsay("Your card:\n");
sort(p[1].c.begin(),p[1].c.end(),cmp);
int tt=0;
for(auto &i:p[1].c){
cout<<++tt<<" ";
print(i);
}
Sleep(1000);
card now=q.top();
q.pop();
// now={'d',0,0};
while(now.num=='w'||now.num=='W'){
now.id=rnd();
q.push(now);
now=q.top();
q.pop();
}
Random();
if(now.num=='r')for(int i=1;i<=n;i++)swap(p[i].pre,p[i].nxt);
slowsay("\nThe first card is: ");
print(now);
Sleep(1000);
int nowp=1;
int cc=0;
int f=0;
if(now.num=='d'||now.num=='s')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
while(1){
system("cls");
for(int i=1;i<=n;i++){
if(p[i].rnk){
cout<<"\033[35m";
if(p[i].rnk==1)slowsay("1st ");
else if(p[i].rnk==2)slowsay("2nd ");
else if(p[i].rnk==3)slowsay("3rd ");
else{
cout<<p[i].rnk;
slowsay("th ");
}
cout<<"\033[0m";
slowsay("Player ",0);
cout<<i;
}
else{
slowsay("Player ",0);
cout<<i;
slowsay(" remains ",0);
cout<<p[i].c.size();
slowsay(" card(s).",0);
if(p[i].c.size()==1){
cout<<"\033[31m";
slowsay("UNO",0);
cout<<"\033[0m";
}
}
cout<<"\n";
}
cout<<"\n";
if(rem==2)puts("Only 2 people! Reverse equal to Skip! \n");
slowsay("Current card : ");
print(now,'\n',cc-1);
// cout<<now.num<<" "<<f<<"\n";
slowsay("\nNow:");
int ppp=1;
do{
slowsay(ppp);
slowsay(" -> ");
// cout<<ppp<<" -> ";
ppp=p[ppp].nxt;
}while(ppp!=1);
cout<<"1\n\n";
slowsay("Card remain : ");
slowsay(q.size());
cout<<"\n\n";
yourcard();
if(nowp!=1)sort(p[nowp].c.begin(),p[nowp].c.end(),cmp2);
calmaxc(nowp);
if(now.num=='s'&&f){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='r'&&f&&rem==2){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='d'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='d'||p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
Inv:
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
while(x<0||x>_t.size()){
slowsay("\nInvaild input.");
goto Inv;
}
if(x==0){
slowsay("Alright.\n");
goto draw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
cout<<"\033[35m";
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
cout<<"\033[0m";
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
exit(0);
}
goto no;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='d'||p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
if(p[nowp].c[i].num=='d')print(p[nowp].c[i],' ');
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto no;
}
}
}
draw:
while(f--)drawcard(nowp);
f=0;
no:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='W'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
if(x==0){
slowsay("Alright.\n");
goto draaw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
cout<<"\033[35m";
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
cout<<"\033[0m";
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
exit(0);
}
goto noo;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto noo;
}
}
}
draaw:
while(f--)drawcard(nowp);
f=0;
noo:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(nowp==1){
string xx;
int x=0;
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
while(x<0||x>p[1].c.size()){
tt:
system("cls");
slowsay("Invaild input.\n");
slowsay("Current card : ");print(now,'\n',cc-1);
yourcard();
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
}
if(x==0){
if(q.empty()){
system("cls");
slowsay("There is no more card!\n");
slowsay("Draw game.");
Sleep(2000);
exit(0);
}
card ccc=q.top();q.pop();
p[1].c.push_back(ccc);
slowsay("You draw the card ");
print(ccc);
Sleep(1000);
if(check(now,ccc,cc))
{
slowsay("You can play the card you just drew. 1/0 for yes or no > ");
int flag;
cin>>xx,flag=calc(xx);
if(flag){
now=ccc;
p[1].c.pop_back();
if(now.color==4){
inv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx;
cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto inv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
if(q.empty())Random();
}
else{
card tmp=p[1].c[x-1];
bool ff=check(now,tmp,cc);
if(!ff)goto tt;
now=tmp;
if(now.color==4){
invvvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvvv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
p[1].c.erase(p[1].c.begin()+x-1);
if(p[1].c.empty()){
system("cls");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
cout<<"\033[35m";
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
cout<<"\033[0m";
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
exit(0);
}
}
}
else{
slowsay("It's player ",10);
cout<<nowp;
slowsay("'s turn.\n",10);
bool ff=0;
for(int j=0;j<p[nowp].c.size();j++){
card i=p[nowp].c[j];
if(check(now,i,cc)){
now=i;
p[nowp].c.erase(p[nowp].c.begin()+j);
slowsay("Player ",10);
cout<<nowp;
slowsay(" played card ",10);
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
cout<<"\n";
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
ff=1;
break;
}
}
if(p[nowp].c.empty()){
Sleep(1500);
system("cls");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
if(!ff){
slowsay("Player ",10);
cout<<nowp;
slowsay(" draw a card.\n",10);
drawcard(nowp);
int siz=p[nowp].c.size();
if(check(now,p[nowp].c[siz-1],cc)){
now=p[nowp].c[siz-1];
p[nowp].c.pop_back();
slowsay("Player ",10);
cout<<nowp;
slowsay(" played the card which he just drew , ",10);
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
cout<<"\n";
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
}
Sleep(1500);
}
nowp=p[nowp].nxt;
}
}
int main(){
system("cls");
setup();
for(int i=1;i<=108;i++) used.push_back(c[i]);
Random();
slowsay("Welcome to the UNO.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
string ss;
cin>>ss,n=calc(ss);
while(n<2||n>8){
system("cls");
slowsay("Invaild input.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
cin>>ss,n=calc(ss);
}
ttttt=17-n;
slowsay("Seed : ",30);
slowsay(seed,30);
cout<<"\n";
Sleep(100);
slowsay("Game is starting...",100);
Sleep(200);
system("cls");
start(n);
return 0;
}
#endif
这是积分版本
#include<bits/stdc++.h>
#include<unistd.h>
#include<stdio.h>
#include<time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
using namespace std;
#ifdef ONLINE_JUDGE
main(){puts("Wrong Answer");}
#endif
#ifndef ONLINE_JUDGE
// By: luobotianle
// black base
// This version runs better with vscode
// For Windows
/* You can find Linux version at
https://www.luogu.com.cn/paste/q8ygzglm
*/
void change_color(int x){
if(x==0x0d)cout<<"\033[35m";
if(x==0x0c)cout<<"\033[31m";
if(x==0x09)cout<<"\033[34m";
if(x==0x0e)cout<<"\033[33m";
if(x==0x0a)cout<<"\033[32m";
if(x==0x07)cout<<"\033[0m";
}
#define color(x) change_color(x)
void Sleep(int x){usleep(x*1000);}
int seed=time(0);
mt19937 rnd(seed);
int n,rk,rem;
int ttttt=30;
void slowsay(const string &s,int t=ttttt){
for(auto &i:s){
cout<<i;
fflush(stdout);
Sleep(t);
}
}
void slowsay(int x,int t=ttttt){
stack<char> s;
while(x){
s.push(x%10+'0');
x/=10;
}
while(s.size()){
cout<<s.top();
fflush(stdout);
s.pop();
Sleep(t);
}
}
int calc(string s){
int i=0;
int x=0,f=1;
while(!isdigit(s[i])){
if(s[i]=='-')f=-f;
i++;
}
while(i<s.size()){
if(isdigit(s[i]))x=(x<<3)+(x<<1)+(s[i]^48);
i++;
}
return x;
}
map<char,string> name;
int color[5]={0x0c,0x09,0x0e,0x0a,0x0d};
struct card{
char num;//0~9 r(reverse) s(skip) d(draw 2) w(wild) W(wild draw 4)
int color;//0~3 red blue yellow green
int id;
bool operator < (const card &a)const{
return id<a.id;
}
}c[109];
void print(card c,char ch='\n',int col=-1){
if(col!=-1)color(color[col]);
else color(color[c.color]);
slowsay(name[c.num]);
cout<<ch;
color(0x07);
}
vector<card> used;
struct player{
int id,nxt,pre;
vector<card> c;
int maxn,maxcc=0,cnt[4];
int rnk;
}p[10];
int cnt=0;
void cset(char num){
if(num!='w'&&num!='W'){
for(int i=0;i<=3;i++){
cnt++;
c[cnt].num=num;
c[cnt].color=i;
}
}
else{
cnt++;
c[cnt].num=num;
c[cnt].color=4;
}
}
void setup(){
name['1']="1",name['2']="2",name['3']="3",name['4']="4",name['5']="5";
name['6']="6",name['7']="7",name['8']="8",name['9']="9",name['0']="0",
name['r']="reverse",name['s']="skip",name['d']="draw 2",name['w']="wild",name['W']="wild draw 4";
cnt=0;
for(char i='0';i<='9';i++){
for(int j=1;j<=2;j++){
cset(i);
}
}
for(int j=1;j<=2;j++){
cset('r');cset('s');cset('d');
cset('W');cset('w');
}
}
priority_queue<card> q;
void Random(){
for(int i=0;i<used.size();i++){
used[i].id=rnd();
q.push(used[i]);
}
used.clear();
}
bool cmp(card a,card b){
if(a.color==b.color)return a.num<b.num;
return a.color<b.color;
}
bool cmp2(card a,card b){
if(a.color==b.color)return a.num>b.num;
return a.color<b.color;
}
void yourcard(){
slowsay("Your card:\n");
int tt=0;
cout<<tt<<" "<<"Draw a card\n";
sort(p[1].c.begin(),p[1].c.end(),cmp);
for(auto &i:p[1].c){
slowsay(++tt);cout<<" ";
print(i);
}
cout<<"\n";
}
void drawcard(int pp){
// cout<<q.size()<<"\n";
card cc=q.top();q.pop();
p[pp].c.push_back(cc);
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
if(q.empty())Random();
}
void calmaxc(int pp){
memset(p[pp].cnt,0,sizeof(p[pp].cnt));
p[pp].maxcc=p[pp].maxn=0;
for(card cc:p[pp].c){
if(cc.color!=4)p[pp].cnt[cc.color]++;
if(p[pp].cnt[cc.color]>p[pp].maxn){
p[pp].maxcc=cc.color;
p[pp].maxn=p[pp].cnt[cc.color];
}
}
}
bool check(card a,card b,int cc){
if(a.color==4&&b.color==cc-1)return 1;
if(a.color==b.color)return 1;
if(a.num==b.num)return 1;
if(b.color==4)return 1;
return 0;
}
int nowp,f;
int start(int n){
rem=n;
for(int i=1;i<=n;i++){
p[i].id=i;
p[i].pre=i-1;
p[i].nxt=i+1;
for(int j=1;j<=7;j++){
drawcard(i);
}
}
p[1].pre=n;
p[n].nxt=1;
slowsay("You're the player 1.\n");
slowsay("Your previous player: ");
cout<<p[1].pre<<"\n";
slowsay("Your next player: ");
cout<<p[1].nxt<<"\n";
slowsay("Your card:\n");
sort(p[1].c.begin(),p[1].c.end(),cmp);
// p[1].c.clear();
// p[1].c.push_back({'W',4,0});
int tt=0;
for(auto &i:p[1].c){
cout<<++tt<<" ";
print(i);
}
Sleep(1000);
card now=q.top();
q.pop();
// now={'d',0,0};
while(now.num=='w'||now.num=='W'){
now.id=rnd();
q.push(now);
now=q.top();
q.pop();
}
Random();
if(now.num=='r')for(int i=1;i<=n;i++)swap(p[i].pre,p[i].nxt);
slowsay("\nThe first card is: ");
print(now);
Sleep(1000);
nowp=1;
int cc=0;
f=0;
if(now.num=='d'||now.num=='s')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
while(1){
system("clear");
for(int i=1;i<=n;i++){
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st ");
else if(p[i].rnk==2)slowsay("2nd ");
else if(p[i].rnk==3)slowsay("3rd ");
else{
cout<<p[i].rnk;
slowsay("th ");
}
color(0x07);
slowsay("Player ",0);
cout<<i;
}
else{
slowsay("Player ",0);
cout<<i;
slowsay(" remains ",0);
cout<<p[i].c.size();
slowsay(" card(s).",0);
if(p[i].c.size()==1){
color(color[0]);
slowsay("UNO",0);
color(0x07);
}
}
cout<<"\n";
}
cout<<"\n";
if(rem==2)puts("Only 2 people! Reverse equal to Skip! \n");
slowsay("Current card : ");
print(now,'\n',cc-1);
// cout<<now.num<<" "<<f<<"\n";
slowsay("\nNow:");
int ppp=1;
do{
slowsay(ppp);
slowsay(" -> ");
// cout<<ppp<<" -> ";
ppp=p[ppp].nxt;
}while(ppp!=1);
cout<<"1\n\n";
slowsay("Card remain : ");
slowsay(q.size());
cout<<"\n\n";
yourcard();
if(nowp!=1)sort(p[nowp].c.begin(),p[nowp].c.end(),cmp2);
calmaxc(nowp);
if(now.num=='s'&&f){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='r'&&f&&rem==2){
if(nowp==1)slowsay("You are skipped.\n");
else{
slowsay("Player ");
cout<<nowp;
slowsay(" is skipped.\n");
}
f=0;
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='d'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='d'||p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
Inv:
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
while(x<0||x>_t.size()){
slowsay("\nInvaild input.");
goto Inv;
}
if(x==0){
slowsay("Alright.\n");
goto draw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("clear");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
return 1;
}
goto no;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='d'||p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
if(p[nowp].c[i].num=='d')print(p[nowp].c[i],' ');
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("clear");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
Sleep(500);
if(rk==1)return nowp;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto no;
}
}
}
draw:
while(f--)drawcard(nowp);
f=0;
no:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(now.num=='W'&&f){
if(nowp==1){
slowsay("You need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
vector<pair<card,int> > _t;
for(int i=0;i<p[1].c.size();i++){
if(p[1].c[i].num=='W')_t.push_back({p[1].c[i],i});
}
if(_t.size()){
slowsay("...But wait! You can add it up!\n\n");
cout<<"0 Just Draw\n";
for(int j=0;j<_t.size();j++){
cout<<j+1<<" ";
print(_t[j].first);
}
slowsay("\nMake your choice > ");
string xx;cin>>xx;
int x=calc(xx);
if(x==0){
slowsay("Alright.\n");
goto draaw;
}
else{
if(_t[x-1].first.num=='d')f+=2;
else{
invvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvv;
}
f+=4;
}
slowsay("Now the next one should draw ");
cout<<f;
slowsay(" cards!\n");
now=_t[x-1].first;
p[1].c.erase(p[1].c.begin()+_t[x-1].second);
if(p[1].c.empty()){
system("clear");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
return 1;
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
exit(0);
}
goto noo;
}
}
}
else{
slowsay("Player ");
cout<<nowp;
slowsay(" need to draw ");cout<<f;slowsay(" cards and be skipped.\n");
for(int i=0;i<p[nowp].c.size();i++){
if(p[nowp].c[i].num=='W'){
slowsay("...But wait! He added it up with card ");
now=p[nowp].c[i];
if(p[nowp].c[i].num=='d')f+=2;
else{
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
}
f+=4;
}
cout<<"!\n";
p[nowp].c.erase(p[nowp].c.begin()+i);
if(p[nowp].c.empty()){
Sleep(1500);
system("clear");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
Sleep(500);
if(rk==1)return nowp;
p[nowp].rnk=rk;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
goto noo;
}
}
}
draaw:
while(f--)drawcard(nowp);
f=0;
noo:
nowp=p[nowp].nxt;
Sleep(1000);
continue;
}
if(nowp==1){
string xx;
int x=0;
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
while(x<0||x>p[1].c.size()){
tt:
system("clear");
slowsay("Invaild input.\n");
slowsay("Current card : ");print(now,'\n',cc-1);
yourcard();
slowsay("It's your turn. Please play a card > ");
cin>>xx,x=calc(xx);
}
if(x==0){
if(q.empty()){
system("clear");
slowsay("There is no more card!\n");
slowsay("Draw game.");
Sleep(2000);
return 0;
}
card ccc=q.top();q.pop();
p[1].c.push_back(ccc);
slowsay("You draw the card ");
print(ccc);
Sleep(1000);
if(check(now,ccc,cc))
{
slowsay("You can play the card you just drew. 1/0 for yes or no > ");
int flag;
cin>>xx,flag=calc(xx);
if(flag){
now=ccc;
p[1].c.pop_back();
if(now.color==4){
inv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx;
cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto inv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
if(q.empty())Random();
}
else{
card tmp=p[1].c[x-1];
bool ff=check(now,tmp,cc);
if(!ff)goto tt;
now=tmp;
if(now.color==4){
invvvv:
slowsay("Input the color you want to change to(1 ~ 4 for Red/Blue/Yellow/Green) > ");
cin>>xx,cc=calc(xx);
if(cc<1||cc>4){
slowsay("\nInvaild input.\n");
goto invvvv;
}
}
else cc=0;
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
p[1].c.erase(p[1].c.begin()+x-1);
if(p[1].c.empty()){
system("clear");
if(rk==0)slowsay("You win. Congratulations!\n");
else{
slowsay("Good job.You got the rank ");
cout<<++rk<<".\n";
}
Sleep(500);
return 1;
for(int i=2;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(p[i].rnk){
color(color[4]);
if(p[i].rnk==1)slowsay("1st \n");
else if(p[i].rnk==2)slowsay("2nd \n");
else if(p[i].rnk==3)slowsay("3rd \n");
else{
cout<<p[i].rnk;
slowsay("th \n");
}
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
for(auto &ca:p[i].c){
print(ca,' ');
}
cout<<"\n";
}
}
Sleep(2000);
exit(0);
}
}
}
else{
slowsay("It's player ",10);
cout<<nowp;
slowsay("'s turn.\n",10);
// Random_shuffle(p[nowp].c.begin(),p[nowp].c.end());
bool ff=0;
for(int j=0;j<p[nowp].c.size();j++){
card i=p[nowp].c[j];
if(check(now,i,cc)){
now=i;
p[nowp].c.erase(p[nowp].c.begin()+j);
slowsay("Player ",10);
cout<<nowp;
slowsay(" played card ",10);
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
cout<<"\n";
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
ff=1;
break;
}
}
if(p[nowp].c.empty()){
Sleep(1500);
system("clear");
slowsay("Player ");
cout<<nowp;
slowsay(" is the rank ");
cout<<++rk<<".\n";
p[nowp].rnk=rk;
Sleep(500);
if(rk==1)return nowp;
rem--;
if(rem==1){
slowsay("So YOU are the last one!\n");
slowsay("Umm...Do you think there will be any other game more fit you ?");
Sleep(2000);
exit(0);
}
if(rem==2){
Sleep(500);
slowsay("Only 2 people! Reverse equal to Skip! \n",50);
}
Sleep(1250);
p[p[nowp].pre].nxt=p[nowp].nxt;
p[p[nowp].nxt].pre=p[nowp].pre;
}
if(!ff){
slowsay("Player ",10);
cout<<nowp;
slowsay(" draw a card.\n",10);
drawcard(nowp);
int siz=p[nowp].c.size();
if(check(now,p[nowp].c[siz-1],cc)){
now=p[nowp].c[siz-1];
p[nowp].c.pop_back();
slowsay("Player ",10);
cout<<nowp;
slowsay(" played the card which he just drew , ",10);
if(now.color==4){
cc=p[nowp].maxcc+1;
if(cc<1||cc>4)cc=rnd()%4+1;
print(now,' ',cc-1);
slowsay(",changed color to ",10);
if(cc==1)slowsay("Red");
else if(cc==2)slowsay("Blue");
else if(cc==3)slowsay("Yellow");
else if(cc==4)slowsay("Green");
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
cout<<"\n";
}
else{
p[nowp].cnt[now.color]--;
p[nowp].maxn=0;
for(int i=0;i<3;i++){
if(p[nowp].cnt[i]>p[nowp].maxn){
p[nowp].maxn=p[nowp].cnt[i];
p[nowp].maxcc=i;
}
}
cc=0;
print(now);
if(now.num=='s'||now.num=='d')f=2;
if(now.num=='W')f=4;
if(now.num=='r'&&rem==2)f=1;
if(now.num=='r'&&rem!=2){
for(int i=1;i<=n;i++){
swap(p[i].pre,p[i].nxt);
}
}
used.push_back(now);
}
}
}
Sleep(1500);
}
nowp=p[nowp].nxt;
}
}
int sum[20];
void clear(){
cnt=rk=rem=0;
setup();
used.clear();
for(int i=1;i<=108;i++) used.push_back(c[i]);
while(!q.empty())q.pop();
Random();
for(int i=1;i<=n;i++)p[i].c.clear();
for(int i=1;i<=n;i++)p[i].id=p[i].maxcc=p[i].maxn=p[i].nxt=p[i].nxt=p[i].rnk=0;
for(int i=1;i<=n;i++)memset(p[i].cnt,0,sizeof(p[i].cnt));
}
int main(){
system("clear");
setup();
for(int i=1;i<=108;i++) used.push_back(c[i]);
Random();
slowsay("Welcome to the UNO.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
string ss;
cin>>ss,n=calc(ss);
while(n<2||n>8){
system("clear");
slowsay("Invaild input.\n");
slowsay("Please input the number of players(between 2 and 8) > ");
cin>>ss,n=calc(ss);
}
ttttt=10;
int goal=n*100;
slowsay("Seed : ",30);
slowsay(seed,30);
cout<<"\n";
Sleep(100);
slowsay("Game is starting...",100);
Sleep(200);
system("clear");
while(1){
clear();
int win=start(n);
if(f>=2){
while(f--)drawcard(p[win].nxt);
}
Sleep(500);
system("clear");
slowsay("Card remain : \n");
int total=0;
for(int i=1;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(i==win){
color(color[4]);
slowsay("Winner ");
color(0x07);
}
else{
sort(p[i].c.begin(),p[i].c.end(),cmp);
int now=0;
for(auto &j:p[i].c){
print(j,' ');
if(isdigit(j.num))now+=j.num-'0';
else if(j.color==4)now+=50;
else now+=20;
}
slowsay("\nPoints : ");
slowsay(now);
total+=now;
}
cout<<"\n\n";
}
slowsay("Total : ");
slowsay(total);
sum[win]+=total;
cout<<"\n\n";
slowsay("Now Points : \n");
int wp=0;
for(int i=1;i<=n;i++){
slowsay("Player ");
slowsay(i);
slowsay(" : ");
if(sum[i]>=goal-50){
color(color[0]);
}
if(sum[i]==0)cout<<"0";
else slowsay(sum[i]);
color(0x07);
slowsay("\n");
if(sum[i]>=goal)wp=i;
}
cout<<"\n";
if(wp){
Sleep(500);
slowsay("The winner is Player ");
slowsay(wp);
slowsay(".\n");
break;
}
slowsay("Goal : ");
slowsay(goal);
cout<<"\n\n";
Sleep(1000);
slowsay("Moving to next round");
slowsay(" ......",600);
system("clear");
}
return 0;
}
#endif