/*
纯属原创,如有雷同,他抄我的;
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;
char card_color[] = {'\a','\3','\4','\5','\6'};
int card_total[] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413 };
string card_name[] = {"0","A","2","3","4","5","6","7","8","9","10","J","Q","K"};
string player_name[] = {"player0","玩家1","玩家2","玩家3","玩家4","玩家5","玩家6","玩家7","玩家8"};
struct player
{
string name;//玩家名字
char card_co[6];//牌颜色
string card_na[6];//牌名
int card_value[6];//牌值
int niu_x;//牛几
bool zhuang;//庄家
int yazhu;
}players[9];
// 随机打乱一个数组
void random(int a[], int n)
{
int index, tmp, i;
srand(time(NULL));
for (i = 0; i <n; i++)
{
index = rand() % (n - i) + i;
if (index != i)
{
tmp = a[i];
a[i] = a[index];
a[index] = tmp;
}
}
}
int wuhua(player players)
{
int fl = 1;
for(int i = 1; i <= 5; i++)
{
if(players.card_value[i]!=10)
fl =0;
}
return fl;
}
void prin_card(player players)
{
cout<<players.name<<": ";
for(int i = 1; i <= 5; i++)
cout<<players.card_co[i]<<players.card_na[i]<<" ";
cout<<endl;
if(wuhua(players))
cout<<"\t\t\t\t==五花=="<<endl;
else
if(players.niu_x>0)
cout<<"\t\t\t\t==牛"<<players.niu_x<<"=="<<endl;
else
if(players.niu_x==0)
cout<<"\t\t\t\t==牛牛=="<<endl;
else
cout<<"\t\t\t\t==无牛=="<<endl;
}
void prin_card(int a)
{
cout<<card_color[a/100]<<card_name[a%100]<<" ";
}
int card_num(player players)
{
int sum = 0;
for(int i = 1; i <= 5; i++)
{
sum += players.card_value[i];
}
for(int i = 1; i <= 5; i++)
{
if(i+1<=5)
for(int j = i+1; j <=5; j++)
{
if(j+1<=5)
for(int k = j+1; k <= 5; k++)
{
int ans = players.card_value[i]+players.card_value[j]+players.card_value[k];
//cout<<players.card_value[i]<<" "<<players.card_value[j]<<" "<<players.card_value[k]<<endl;
if(ans%10 == 0)
{
//cout<<"ans: "<<ans<<endl;
return (sum-ans)%10;
}
}
}
}
return -1;
}
int main()
{
//printf("a\1b\2c\3d\4e\5f\6g\7h\8i\9j\n");
int i;
cout<<"原牌排列:"<<endl;
for (i = 0; i < 52; i++)
{
if(i%13==0)
printf("\n\n");
prin_card(card_total[i]);
}
random(card_total, 52);
cout<<"\n洗牌后排列:"<<endl;
for (i = 0; i < 52; i++)
{
if(i%13==0)
printf("\n\n");
prin_card(card_total[i]);
}
int p = 0;
int n,z;
cout<<"\n输入玩家个数(不要超过8):"<<endl;
cin>>n;
cout<<"输入庄家序号(不要超过总玩家人数):"<<endl;
cin>>z;
for(int i = 0; i <= n; i++)
{
players[i].name = player_name[i];
players[i].zhuang = false;
}
players[z].zhuang = true;
cout<<"发牌结束:"<<endl;
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= n; j++,p++)
{
players[j].card_co[i] = card_color[card_total[p]/100];
players[j].card_na[i] = card_name[card_total[p]%100];
if(card_total[p]%100>=10)
players[j].card_value[i] = 10;
else
players[j].card_value[i] = card_total[p]%100;
}
}
for(int i = 1; i <= n; i++)
players[i].niu_x = card_num(players[i]);
cout<<"\t\t\t(庄家)";
prin_card(players[z]);
cout<<"玩家:\n";
for(int i = 1; i <= n; i++)
{
if(i!=z)
prin_card(players[i]);
}
printf("\n");
system("pause");
return 0;
}