#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<string>
using namespace std;
int a[3][3];
int randpoker[27];
int result[3];
string cardname[54]=
{
"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K",
"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K",
"方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K",
"梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K",
"大王","小王"
};
void pokergame()
{
int i,j;
//....................................................
//选出不同的27个随机数
for(i=0;i<27;i++)
{ j=0;
randpoker[i]=rand()%54;
while(i!=0&&(randpoker[i]!=randpoker[j])&&(j<i))
{
j++;
}
if (i!=0&&j!=i) --i;
}
}
void main(){
time_t t;
srand(time(&t));
int i,j,line[2];char b;
cout<<"暗记某张纸牌,而后告诉我所暗记的那张纸牌处于哪一行中/n/n"<<"我猜出你暗记的纸牌/n/n/n";
L: pokergame();
for(i=0;i<3;i++)
{
cout<<"LINE"<<i+1<<":/t";
for(int j=0;j<9;j++)
{
cout<<cardname[randpoker[i*9+j]]<<"/t";
}
cout<<endl;
}
cout<<"Remember a card, and tell me what line it reside in(1/2/3):";
cin>>line[0];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=randpoker[(line[0]-1)*9+i*3+j];
}
}
switch(line[0])
{
case 1:{
for(i=0;i<3;i++)
{
randpoker[3+i]=randpoker[12+i];
randpoker[12+i]=a[1][i];
randpoker[6+i]=randpoker[24+i];
randpoker[24+i]=a[2][i];
}
}break;
case 2:{
for(i=0;i<3;i++)
{
randpoker[9+i]=randpoker[i];
randpoker[i]=a[0][i];
randpoker[15+i]=randpoker[24+i];
randpoker[24+i]=a[2][i];
}
}break;
case 3:{
for(i=0;i<3;i++)
{
randpoker[18+i]=randpoker[i];
randpoker[i]=a[0][i];
randpoker[21+i]=randpoker[12+i];
randpoker[12+i]=a[1][i];
}
}break;
default:{cout<<endl<<"输入出错,游戏重开!!!"<<endl<<endl<<endl;goto L;}
}
//显示重新排列后的牌
cout<<endl;
for(i=0;i<3;i++)
{
cout<<"LINE"<<i+1<<":/t";
for(int j=0;j<9;j++)
{
cout<<cardname[randpoker[i*9+j]]<<"/t";
}
cout<<endl;
}
cout<<"What line the card you remembered reside in now (1/2/3) :";
cin>>line[1];
for(i=0;i<3;i++){result[i]=a[line[1]-1][i];}
//第二次判断
switch(line[1]){
case 1:{
randpoker[1]=randpoker[10];
randpoker[10]=result[1];
randpoker[2]=randpoker[20];
randpoker[20]=result[2];
}break;
case 2:{
randpoker[12]=randpoker[3];
randpoker[3]=result[0];
randpoker[14]=randpoker[23];
randpoker[23]=result[2];
}break;
case 3:{
randpoker[24]=randpoker[6];
randpoker[6]=result[0];
randpoker[25]=randpoker[16];
randpoker[16]=result[1];
}break;
default:{cout<<endl<<"输入出错,游戏重开!!!"<<endl<<endl;goto L;}
}
cout<<endl;
for(i=0;i<3;i++)
{
cout<<"LINE"<<i+1<<":/t";
for(int j=0;j<9;j++)
{
cout<<cardname[randpoker[i*9+j]]<<"/t";
}
cout<<endl;
}
cout<<"What line the card you remembered reside in now (1/2/3) : ";
cin>>i;
cout<<"你要的是:"<<cardname[result[i-1]]<<endl<<endl<<"是否继续玩牌(Y/N):";
cin>>b;
if(b='Y') {cout<<endl<<endl;goto L;};
}